mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-28 10:13:52 +00:00
feat: sync to google drive before closing app
This commit is contained in:
parent
b1ef7458c0
commit
3e4d4e9e0d
4 changed files with 60 additions and 19 deletions
|
|
@ -53,6 +53,7 @@
|
|||
.run(checkIfLatestVersion)
|
||||
.run(showWelcomeDialog)
|
||||
.run(initUnloadActions)
|
||||
.run(initElectronOnBeforeQuit)
|
||||
//.run(goToWorkViewIfTasks);
|
||||
|
||||
/* @ngInject */
|
||||
|
|
@ -378,6 +379,38 @@
|
|||
}
|
||||
}
|
||||
|
||||
function initElectronOnBeforeQuit(IS_ELECTRON, GoogleDriveSync, $mdDialog) {
|
||||
const ON_BEFORE_QUIT_EV = 'ON_BEFORE_QUIT';
|
||||
const SHUTDOWN_NOW_EV = 'SHUTDOWN_NOW';
|
||||
|
||||
const confirmQuitAnyWay = () => {
|
||||
const confirm = $mdDialog.confirm()
|
||||
.title(`Some error occurred while syncing`)
|
||||
.textContent(`
|
||||
Some error occurred while syncing to Google Drive (check the console). Do you want to quit anyway?`)
|
||||
.ok('Yes')
|
||||
.cancel('No!');
|
||||
$mdDialog.show(confirm)
|
||||
.then(() => {
|
||||
window.ipcRenderer.send(SHUTDOWN_NOW_EV, {});
|
||||
});
|
||||
};
|
||||
|
||||
if (IS_ELECTRON) {
|
||||
window.ipcRenderer.on(ON_BEFORE_QUIT_EV, () => {
|
||||
if (GoogleDriveSync.config.isAutoSyncToRemote) {
|
||||
GoogleDriveSync.saveForSyncIfEnabled()
|
||||
.then(() => {
|
||||
window.ipcRenderer.send(SHUTDOWN_NOW_EV, {});
|
||||
})
|
||||
.catch(confirmQuitAnyWay);
|
||||
} else {
|
||||
window.ipcRenderer.send(SHUTDOWN_NOW_EV, {});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function sendAppReadyToElectron(IS_ELECTRON) {
|
||||
const APP_READY = 'APP_READY';
|
||||
if (IS_ELECTRON) {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@
|
|||
|
||||
// save everything
|
||||
AppStorage.saveToLs();
|
||||
if (GoogleDriveSync.config && GoogleDriveSync.config.isAutoSyncToRemote) {
|
||||
|
||||
if (!IS_ELECTRON && GoogleDriveSync.config && GoogleDriveSync.config.isAutoSyncToRemote) {
|
||||
SimpleToast('CUSTOM', `Syncing Data to Google Drive.`, 'file_upload');
|
||||
GoogleDriveSync.saveTo();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,15 +230,7 @@
|
|||
|
||||
this.autoSyncInterval = this.$interval(() => {
|
||||
// only sync if not in the middle of something
|
||||
if (this._isCurrentPromisePending()) {
|
||||
this._log('SYNC OMITTED because of promise', this.currentPromise, this.currentPromise.$$state.status);
|
||||
} else {
|
||||
this._log('SYNC');
|
||||
this.saveTo()
|
||||
.then(() => {
|
||||
this.SimpleToast('SUCCESS', `Successfully synced Data to Google drive.`, 'file_upload');
|
||||
});
|
||||
}
|
||||
this.saveForSyncIfEnabled();
|
||||
}, interval);
|
||||
}
|
||||
|
||||
|
|
@ -279,6 +271,23 @@
|
|||
return defer.promise;
|
||||
}
|
||||
|
||||
saveForSyncIfEnabled() {
|
||||
if (!this.config.isAutoSyncToRemote) {
|
||||
return this.$q.resolve();
|
||||
}
|
||||
|
||||
if (this._isCurrentPromisePending()) {
|
||||
this._log('SYNC OMITTED because of promise', this.currentPromise, this.currentPromise.$$state.status);
|
||||
return this.$q.reject();
|
||||
} else {
|
||||
this._log('SYNC');
|
||||
return this.saveTo()
|
||||
.then(() => {
|
||||
this.SimpleToast('SUCCESS', `Successfully synced Data to Google drive.`, 'file_upload');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
saveTo() {
|
||||
// don't execute sync interactions at the same time
|
||||
if (this._isCurrentPromisePending()) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ let shouldQuitBecauseAppIsAnotherInstance = app.makeSingleInstance(() => {
|
|||
});
|
||||
|
||||
if (shouldQuitBecauseAppIsAnotherInstance) {
|
||||
quitApp();
|
||||
quitAppNow();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -109,6 +109,8 @@ app.on('before-quit', () => {
|
|||
|
||||
// FRONTEND EVENTS
|
||||
// ---------------
|
||||
electron.ipcMain.on('SHUTDOWN_NOW', quitAppNow);
|
||||
|
||||
electron.ipcMain.on('SHUTDOWN', quitApp);
|
||||
|
||||
electron.ipcMain.on('REGISTER_GLOBAL_SHORTCUT', (ev, shortcutPassed) => {
|
||||
|
|
@ -182,19 +184,15 @@ function registerShowAppShortCut(shortcutPassed) {
|
|||
}
|
||||
}
|
||||
|
||||
function showIdleDialog(idleTimeInMs) {
|
||||
// first show, then send again
|
||||
mainWin.webContents.send('WAS_IDLE', ({
|
||||
idleTimeInMs: idleTimeInMs,
|
||||
minIdleTimeInMs: CONFIG.MIN_IDLE_TIME
|
||||
}));
|
||||
}
|
||||
|
||||
function showApp() {
|
||||
showOrFocus(mainWin);
|
||||
}
|
||||
|
||||
function quitApp() {
|
||||
mainWin.webContents.send('ON_BEFORE_QUIT');
|
||||
}
|
||||
|
||||
function quitAppNow() {
|
||||
app.isQuiting = true;
|
||||
app.quit();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue