Skip to content

Commit

Permalink
Fix undefined window state bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jalenng committed May 31, 2021
1 parent 2b4c9f4 commit 8ddd6a9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twenty",
"productName": "Twenty",
"description": "A customizable timer that reminds you to take breaks in preventing eye strain",
"version": "0.1.2",
"version": "0.1.3",
"repository": "https://github.com/jalenng/twenty",
"url": "https://github.com/jalenng/twenty#readme",
"author": {
Expand Down
1 change: 0 additions & 1 deletion public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ app.setLoginItemSettings({
let appTray = null

app.whenReady().then(() => {

/* Create main window */
global.mainWindow = createWindow('main')

Expand Down
5 changes: 4 additions & 1 deletion public/systems/EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class EventEmitter {
* @param {(callback) => any} fireCallbacks
*/
emit (eventName, fireCallbacks = callback => callback()) {
this._events[eventName].forEach(fireCallbacks)
const callbacks = this._events[eventName]
if (callbacks) {
callbacks.forEach(fireCallbacks)
}
}
}

Expand Down
16 changes: 9 additions & 7 deletions public/systems/systemsInitializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ global.notificationSystem = new NotificationSystem()
global.appSnapshotSystem = new AppSnapshotSystem()
global.blockerSystem = new BlockerSystem()

/* ------------------------------------------------------------------------- */
/* Start timer automatically based on user preferences */

if (global.store.get('preferences.startup.startTimerOnAppStartup')) { global.timerSystem.start() }

global.appSnapshotSystem.updateState()

/* ------------------------------------------------------------------------- */
/* If timer has stopped and the notification interval updates, update the timer with the new value. */

Expand Down Expand Up @@ -94,3 +87,12 @@ powerMonitor.on('on-ac', () => {
global.blockerSystem.remove('other', 'batteryPower')
}
})

/* ------------------------------------------------------------------------- */
/* Start timer automatically based on user preferences */

if (global.store.get('preferences.startup.startTimerOnAppStartup')) {
global.timerSystem.start()
}

global.appSnapshotSystem.updateState()
14 changes: 12 additions & 2 deletions public/systems/timerSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,19 @@ class TimerSystem extends EventEmitter {
*/
getState () {
if (this.isStopped) {
if (this.isBlocked) { return states.BLOCKED_AND_STOPPED } else { return states.STOPPED }
if (this.isBlocked) {
return states.BLOCKED_AND_STOPPED
} else {
return states.STOPPED
}
} else {
if (this.isBlocked) { return states.BLOCKED } else if (this.isIdle) { return states.IDLE } else { return states.RUNNING }
if (this.isBlocked) {
return states.BLOCKED
} else if (this.isIdle) {
return states.IDLE
} else {
return states.RUNNING
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion public/windowCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function createWindow (type, destination = '', display = null, isPopup = false)
mainWindowState = windowStateKeeper({})

// Update and remember the position of the main window
window.setPosition(mainWindowState.x, mainWindowState.y)
if (mainWindowState.x && mainWindowState.y) {
window.setPosition(mainWindowState.x, mainWindowState.y)
}
mainWindowState.manage(window)

// Make the main window always on top if its corresponding preference is enabled
Expand Down

0 comments on commit 8ddd6a9

Please sign in to comment.