import Store from "electron-store" ; import { Settings , NotificationType } from "../../types/settings" ; import { setAutoLauch } from "./auto-launch" ; import { initBreaks } from "./breaks" ; const defaultSettings = { autoLaunch : true , breaksEnabled : true , notificationType : NotificationType . Popup , breakFrequency : new Date ( 0 , 0 , 0 , 0 , 28 ) , breakLength : new Date ( 0 , 0 , 0 , 0 , 2 ) , postponeLength : new Date ( 0 , 0 , 0 , 0 , 3 ) , postponeLimit : 0 , workingHoursEnabled : true , workingHoursFrom : new Date ( 0 , 0 , 0 , 9 ) , workingHoursTo : new Date ( 0 , 0 , 0 , 18 ) , workingHoursMonday : true , workingHoursTuesday : true , workingHoursWednesday : true , workingHoursThursday : true , workingHoursFriday : true , workingHoursSaturday : false , workingHoursSunday : false , idleResetEnabled : true , idleResetLength : new Date ( 0 , 0 , 0 , 0 , 5 ) , idleResetNotification : false , gongEnabled : true , breakTitle : "Time for a break!" , breakMessage : "Rest your eyes. Stretch your legs. Breathe. Relax." , backgroundColor : "#16a085" , backdropColor : "#001914" , textColor : "#ffffff" , showBackdrop : false , backdropOpacity : 0.7 , endBreakEnabled : true , skipBreakEnabled : false , postponeBreakEnabled : true , } ; const store = new Store < { settings : Settings ; appInitialized : boolean ; } > ( { defaults : { settings : defaultSettings , appInitialized : false , } , } ) ; export function getSettings ( ) { return Object . assign ( defaultSettings , store . get ( "settings" ) ) as Settings ; } export function setSettings ( settings , resetBreaks = true ) { const currentSettings = getSettings ( ) ; if ( currentSettings . autoLaunch !== settings . autoLaunch ) { setAutoLauch ( settings . autoLaunch ) ; } store . set ( { settings } ) ; if ( resetBreaks ) { initBreaks ( ) ; } } export function getAppInitialized ( ) { return store . get ( "appInitialized" ) as boolean ; } export function setAppInitialized ( ) { store . set ( { appInitialized : true } ) ; } export function setBreaksEnabled ( breaksEnabled ) { const settings = getSettings ( ) ; setSettings ( { ... settings , breaksEnabled } , false ) ; }