mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
21 lines
701 B
TypeScript
21 lines
701 B
TypeScript
import { inject, Injectable } from '@angular/core'
|
|
import { Clipboard } from '@angular/cdk/clipboard'
|
|
import { TuiNotificationService } from '@taiga-ui/core'
|
|
|
|
import { i18nPipe } from '../i18n/i18n.pipe'
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class CopyService {
|
|
private readonly clipboard = inject(Clipboard)
|
|
private readonly i18n = inject(i18nPipe)
|
|
private readonly alerts = inject(TuiNotificationService)
|
|
|
|
async copy(text: string) {
|
|
const success = this.clipboard.copy(text)
|
|
const message = success ? 'Copied to clipboard' : 'Failed'
|
|
const appearance = success ? 'positive' : 'negative'
|
|
|
|
this.alerts.open(this.i18n.transform(message), { appearance }).subscribe()
|
|
}
|
|
}
|