20 lines
752 B
TypeScript
20 lines
752 B
TypeScript
import type Store from 'electron-store'
|
|
import type { ComposeSettings } from '@shared/types/compose'
|
|
|
|
export class ComposeSettingsError extends Error {}
|
|
|
|
export class ComposeSettingsService {
|
|
constructor(private readonly store: Pick<Store<ComposeSettings>, 'get' | 'set'>) {}
|
|
|
|
get(): ComposeSettings {
|
|
return { signature: this.store.get('signature') ?? '' }
|
|
}
|
|
|
|
save(settings: ComposeSettings): ComposeSettings {
|
|
if (!settings || typeof settings.signature !== 'string' || settings.signature.length > 10_000) {
|
|
throw new ComposeSettingsError('Подпись должна быть текстом длиной до 10 000 символов')
|
|
}
|
|
this.store.set('signature', settings.signature.trim())
|
|
return this.get()
|
|
}
|
|
}
|