import { Component , OnInit } from 'angular-ts-decorators' ; import autobind from 'autobind-decorator' ; import { PlatformService } from '../../../shared/global-shared.interface' ; import { AllSettings } from '../../../shared/settings/settings.interface' ; import { SettingsService } from '../../../shared/settings/settings.service' ; import { SyncType } from '../../../shared/sync/sync.enum' ; import { UtilityService } from '../../../shared/utility/utility.service' ; import { WorkingService } from '../../../shared/working/working.service' ; import { AppHelperService } from '../../shared/app-helper/app-helper.service' ; @ autobind @ Component ( { controllerAs : 'vm' , selector : 'preferencesSettings' , styles : [ require ( './preferences-settings.component.scss' ) ] , template : require ( './preferences-settings.component.html' ) } ) export class PreferencesSettingsComponent implements OnInit { Strings = require ( '../../../../../res/strings/en.json' ) ; $timeout : ng . ITimeoutService ; appHelperSvc : AppHelperService ; platformSvc : PlatformService ; settingsSvc : SettingsService ; utilitySvc : UtilityService ; workingSvc : WorkingService ; displaySyncBookmarksToolbarConfirmation = false ; settings : AllSettings ; static $inject = [ '$timeout' , 'AppHelperService' , 'PlatformService' , 'SettingsService' , 'UtilityService' , 'WorkingService' ] ; constructor ( $timeout , AppHelperSvc , PlatformSvc , SettingsSvc , UtilitySvc , WorkingSvc ) { this . $timeout = $timeout ; this . appHelperSvc = AppHelperSvc ; this . platformSvc = PlatformSvc ; this . settingsSvc = SettingsSvc ; this . utilitySvc = UtilitySvc ; this . workingSvc = WorkingSvc ; } cancelSyncBookmarksToolbar ( ) { this . displaySyncBookmarksToolbarConfirmation = false ; this . settings . syncBookmarksToolbar = false ; } confirmSyncBookmarksToolbar ( ) { this . utilitySvc . isSyncEnabled ( ) . then ( ( syncEnabled ) => { if ( ! syncEnabled ) { return ; } this . displaySyncBookmarksToolbarConfirmation = false ; this . workingSvc . show ( ) ; return this . settingsSvc . syncBookmarksToolbar ( true ) . then ( ( ) => this . platformSvc . queueSync ( { type : SyncType . Local } ) ) ; } ) ; } ngOnInit ( ) { this . settingsSvc . all ( ) . then ( ( allSettings ) => { this . settings = allSettings ; } ) ; } toggleAlternateSearchBarPosition ( ) { this . settings . alternateSearchBarPosition = ! this . settings . alternateSearchBarPosition ; this . settingsSvc . alternateSearchBarPosition ( this . settings . alternateSearchBarPosition ) ; } toggleAutoFetchMetadata ( ) { this . settings . autoFetchMetadata = ! this . settings . autoFetchMetadata ; this . settingsSvc . autoFetchMetadata ( this . settings . autoFetchMetadata ) ; } toggleCheckForAppUpdates ( ) { this . settings . checkForAppUpdates = ! this . settings . checkForAppUpdates ; this . settingsSvc . checkForAppUpdates ( this . settings . checkForAppUpdates ) ; } toggleDefaultToFolderView ( ) { this . settings . defaultToFolderView = ! this . settings . defaultToFolderView ; this . settingsSvc . defaultToFolderView ( this . settings . defaultToFolderView ) ; } toggleEnableDarkMode ( ) { this . settings . darkModeEnabled = ! this . settings . darkModeEnabled ; this . settingsSvc . darkModeEnabled ( this . settings . darkModeEnabled ) ; } toggleSyncBookmarksToolbar ( ) { this . settingsSvc . syncBookmarksToolbar ( ) . then ( ( syncBookmarksToolbar ) => { this . settings . syncBookmarksToolbar = ! this . settings . syncBookmarksToolbar ; if ( this . displaySyncBookmarksToolbarConfirmation ) { this . displaySyncBookmarksToolbarConfirmation = false ; return ; } return this . utilitySvc . isSyncEnabled ( ) . then ( ( syncEnabled ) => { if ( ! syncEnabled || syncBookmarksToolbar ) { return this . settingsSvc . syncBookmarksToolbar ( this . settings . syncBookmarksToolbar ) ; } this . displaySyncBookmarksToolbarConfirmation = true ; this . appHelperSvc . focusOnElement ( '.btn-confirm-sync-toolbar' ) ; } ) ; } ) ; } }