import { Injectable } from '@angular/core' ; import { remote } from 'electron' ; import * as Store from 'electron-store' ; import * as os from 'os' ; import { Constants } from '../core/constants' ; @ Injectable ( { providedIn : 'root' , } ) export class Settings { private settings : Store = new Store ( ) ; private globalEmitter : any = remote . getGlobal ( 'globalEmitter' ) ; constructor ( ) { this . initialize ( ) ; } public get defaultLanguage ( ) : string { return 'en' ; } public get language ( ) : string { return this . settings . get ( 'language' ) ; } public set language ( v ) { this . settings . set ( 'language' , v ) ; } public get checkForUpdates ( ) : boolean { return this . settings . get ( 'checkForUpdates' ) ; } public set checkForUpdates ( v ) { this . settings . set ( 'checkForUpdates' , v ) ; } public get useCustomTitleBar ( ) : boolean { return this . settings . get ( 'useCustomTitleBar' ) ; } public set useCustomTitleBar ( v ) { this . settings . set ( 'useCustomTitleBar' , v ) ; } public get fontSize ( ) : number { return this . settings . get ( 'fontSize' ) ; } public set fontSize ( v ) { this . settings . set ( 'fontSize' , v ) ; } public get colorScheme ( ) : string { return this . settings . get ( 'colorScheme' ) ; } public set colorScheme ( v ) { this . settings . set ( 'colorScheme' , v ) ; } public get closeNotesWithEscape ( ) : boolean { return this . settings . get ( 'closeNotesWithEscape' ) ; } public set closeNotesWithEscape ( v ) { this . settings . set ( 'closeNotesWithEscape' , v ) ; } public get fontSizeInNotes ( ) : number { return this . settings . get ( 'fontSizeInNotes' ) ; } public set fontSizeInNotes ( v ) { this . settings . set ( 'fontSizeInNotes' , v ) ; this . globalEmitter . emit ( Constants . noteFontSizeChangedEvent ) ; } public get showExactDatesInTheNotesList ( ) : boolean { return this . settings . get ( 'showExactDatesInTheNotesList' ) ; } public set showExactDatesInTheNotesList ( v ) { this . settings . set ( 'showExactDatesInTheNotesList' , v ) ; } public get storageDirectory ( ) : string { return this . settings . get ( 'storageDirectory' ) ; } public set storageDirectory ( v ) { this . settings . set ( 'storageDirectory' , v ) ; } public get activeCollection ( ) : string { return this . settings . get ( 'activeCollection' ) ; } public set activeCollection ( v ) { this . settings . set ( 'activeCollection' , v ) ; } public get notebooksPaneWidth ( ) : number { return this . settings . get ( 'notebooksPaneWidth' ) ; } public set notebooksPaneWidth ( v ) { this . settings . set ( 'notebooksPaneWidth' , v ) ; } public get moveDeletedNotesToTrash ( ) : boolean { return this . settings . get ( 'moveDeletedNotesToTrash' ) ; } public set moveDeletedNotesToTrash ( v ) { this . settings . set ( 'moveDeletedNotesToTrash' , v ) ; } public get useLightHeaderBar ( ) : boolean { return this . settings . get ( 'useLightHeaderBar' ) ; } public set useLightHeaderBar ( v ) { this . settings . set ( 'useLightHeaderBar' , v ) ; } private initialize ( ) { if ( ! this . settings . has ( 'language' ) ) { this . settings . set ( 'language' , 'en' ) ; } if ( ! this . settings . has ( 'checkForUpdates' ) ) { this . settings . set ( 'checkForUpdates' , true ) ; } if ( ! this . settings . has ( 'useCustomTitleBar' ) ) { if ( os . platform ( ) === 'win32' ) { this . settings . set ( 'useCustomTitleBar' , true ) ; } else { this . settings . set ( 'useCustomTitleBar' , false ) ; } } if ( ! this . settings . has ( 'fontSize' ) ) { this . settings . set ( 'fontSize' , 13 ) ; } if ( ! this . settings . has ( 'colorScheme' ) ) { this . settings . set ( 'colorScheme' , 'Knowte blue' ) ; } else { const settingsColorSchemeName = this . settings . get ( 'colorScheme' ) ; if ( ! Constants . colorSchemes . map ( ( x ) => x . name ) . includes ( settingsColorSchemeName ) ) { this . settings . set ( 'colorScheme' , 'Knowte blue' ) ; } } if ( ! this . settings . has ( 'closeNotesWithEscape' ) ) { this . settings . set ( 'closeNotesWithEscape' , true ) ; } if ( ! this . settings . has ( 'fontSizeInNotes' ) ) { this . settings . set ( 'fontSizeInNotes' , 13 ) ; } if ( ! this . settings . has ( 'showExactDatesInTheNotesList' ) ) { this . settings . set ( 'showExactDatesInTheNotesList' , false ) ; } if ( ! this . settings . has ( 'notebooksPaneWidth' ) ) { this . settings . set ( 'notebooksPaneWidth' , 300 ) ; } if ( ! this . settings . has ( 'moveDeletedNotesToTrash' ) ) { this . settings . set ( 'moveDeletedNotesToTrash' , true ) ; } if ( ! this . settings . has ( 'useLightHeaderBar' ) ) { this . settings . set ( 'useLightHeaderBar' , false ) ; } } }