mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 01:54:40 +08:00
[client-app] Restart sync when computer awakes from sleep
Summary: Use electron's `powerMonitor` module to detect when the computer resumes from sleep, and restart the sync loop when that happens in order to sync the inbox immediately, in case we received any new mail events while the computer was asleep Test Plan: manual Reviewers: evan, spang, halla Reviewed By: halla Differential Revision: https://phab.nylas.com/D4216
This commit is contained in:
parent
f157ddb867
commit
7fc1e043c1
2 changed files with 15 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
/* eslint global-require: "off" */
|
||||
|
||||
import {BrowserWindow, Menu, app, ipcMain, dialog} from 'electron';
|
||||
import {BrowserWindow, Menu, app, ipcMain, dialog, powerMonitor} from 'electron';
|
||||
|
||||
import fs from 'fs-plus';
|
||||
import url from 'url';
|
||||
|
@ -395,6 +395,10 @@ export default class Application extends EventEmitter {
|
|||
});
|
||||
}
|
||||
|
||||
powerMonitor.on('resume', () => {
|
||||
this.windowManager.sendToAllWindows('app-resumed-from-sleep', {})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
this.windowManager.quitWinLinuxIfNoWindows()
|
||||
});
|
||||
|
|
|
@ -20,13 +20,14 @@ class SyncProcessManager {
|
|||
Actions.wakeLocalSyncWorkerForAccount.listen((accountId) =>
|
||||
this.wakeWorkerForAccount(accountId, {interrupt: true})
|
||||
);
|
||||
ipcRenderer.on('app-resumed-from-sleep', () => {
|
||||
this._wakeAllWorkers({reason: 'Computer resumed from sleep', interrupt: true})
|
||||
})
|
||||
}
|
||||
|
||||
_onOnlineStatusChanged() {
|
||||
if (OnlineStatusStore.isOnline()) {
|
||||
Object.keys(this._workersByAccountId).forEach((id) => {
|
||||
this.wakeWorkerForAccount(id, {reason: 'Came back online'})
|
||||
})
|
||||
this._wakeAllWorkers({reason: 'Came back online', interrupt: true})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +44,12 @@ class SyncProcessManager {
|
|||
win.openDevTools()
|
||||
}
|
||||
|
||||
_wakeAllWorkers({reason, interrupt} = {}) {
|
||||
Object.keys(this._workersByAccountId).forEach((id) => {
|
||||
this.wakeWorkerForAccount(id, {reason, interrupt})
|
||||
})
|
||||
}
|
||||
|
||||
async _resetEmailCache() {
|
||||
if (this._resettingEmailCache) return;
|
||||
this._resettingEmailCache = true
|
||||
|
|
Loading…
Reference in a new issue