Skip to content

Instantly share code, notes, and snippets.

@komplexb
Last active December 29, 2016 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komplexb/2f5765f78111f07e4d84ce064893431c to your computer and use it in GitHub Desktop.
Save komplexb/2f5765f78111f07e4d84ce064893431c to your computer and use it in GitHub Desktop.
// http://electron.atom.io/docs/api/ipc-main
ipc.on('reschedule-notes', (event, arg) => {
rescheduleRandomNote(arg)
})
app.on('ready', () => {
// for reliability refresh scheduled task when computer wakes
// http://electron.atom.io/docs/api/power-monitor/#powermonitor
electron.powerMonitor.on('resume', () => {
log.info('computer awake: refresh schedule')
rescheduleRandomNote()
})
})
function rescheduleRandomNote (scheduleVal = storeSettings.getItemSync('schedule')) {
log.info(`reschedule-notes-to: ${scheduleVal}`)
scheduleInstance = scheduleRandomNote(scheduleVal)
}
2016-12-28 | 18:28:54:0181 reschedule-notes-to: 9 // i set schedule to morning (9) then put computer to sleep
2016-12-28 | 18:29:03:0720 computer awake: refresh schedule
2016-12-28 | 18:29:03:0720 canceled: Thu Dec 29 2016 09:00:00 GMT-0500 (EST) // app cancels old schedule of 9
2016-12-28 | 18:29:03:0720 canceled-settings-value: 9 // app cancels old schedule of 9
2016-12-28 | 18:29:03:0720 reschedule-notes-to: */5 * * * * // app should read value from file set in line 1 instead it uses old value from app load
handleSave () {
storeSettings.setItemSync('schedule', this.settings.schedule) // this.settings.schedule = 9
// http://electron.atom.io/docs/api/ipc-renderer
ipc.send('reschedule-notes', this.settings.schedule) // this.settings.schedule = 9
}
{"key":"schedule","value":"*/5 * * * *"} // initial setting on load
@komplexb
Copy link
Author

komplexb commented Dec 29, 2016

Event Emitters in Electron: ipcMain.on vs electron.powerMonitor.on

screenshot 2016-12-27 11 16 10

I'm using a method to set a schedule with a value, sometimes this value comes from a settings file, other times it comes from a user selection.

Calling from render.js works, it uses the newly provided value, but calling from electron.js uses the value it obtained when the app loaded, when what I really want it to do is retrieve a new value from storeSettings.getItemSync('schedule').

Why does reschedule-notes behave different from resume? Is it because rescheduleRandomNote(arg) inside reschedule-notes is provided a new argument?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment