Merge pull request #90 from ente-io/update-dialog

App Update Dialog
This commit is contained in:
Abhinav Kumar 2022-10-31 15:23:40 +05:30 committed by GitHub
commit e3b9332544
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 19 deletions

View file

@ -9,3 +9,14 @@ export const showOnTray = (content: string) => {
export const reloadWindow = () => {
ipcRenderer.send('reload-window');
};
export const registerUpdateEventListener = (showUpdateDialog: () => void) => {
ipcRenderer.removeAllListeners('show-update-dialog');
ipcRenderer.on('show-update-dialog', () => {
showUpdateDialog();
});
};
export const updateAndRestart = () => {
ipcRenderer.send('update-and-restart');
};

View file

@ -1,4 +1,10 @@
import { reloadWindow, sendNotification, showOnTray } from './api/system';
import {
registerUpdateEventListener,
reloadWindow,
sendNotification,
showOnTray,
updateAndRestart,
} from './api/system';
import {
showUploadDirsDialog,
showUploadFilesDialog,
@ -82,4 +88,6 @@ windowObject['ElectronAPIs'] = {
logToDisk,
convertHEIC,
openLogDirectory,
registerUpdateEventListener,
updateAndRestart,
};

View file

@ -1,4 +1,4 @@
import { BrowserWindow, dialog, Tray } from 'electron';
import { BrowserWindow, Tray } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import { setIsAppQuitting, setIsUpdateAvailable } from '../main';
@ -12,27 +12,20 @@ class AppUpdater {
async checkForUpdate(tray: Tray, mainWindow: BrowserWindow) {
await autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on('update-downloaded', () => {
showUpdateDialog();
showUpdateDialog(mainWindow);
setIsUpdateAvailable(true);
tray.setContextMenu(buildContextMenu(mainWindow));
});
}
updateAndRestart = () => {
setIsAppQuitting(true);
autoUpdater.quitAndInstall();
};
}
export default new AppUpdater();
export const showUpdateDialog = (): void => {
dialog
.showMessageBox({
type: 'info',
title: 'Install update',
message: 'Restart to update to the latest version of ente',
buttons: ['Later', 'Restart now'],
})
.then((buttonIndex) => {
if (buttonIndex.response === 1) {
setIsAppQuitting(true);
autoUpdater.quitAndInstall();
}
});
export const showUpdateDialog = (mainWindow: BrowserWindow): void => {
mainWindow.webContents.send('show-update-dialog');
};

View file

@ -15,6 +15,7 @@ import chokidar from 'chokidar';
import path from 'path';
import { getDirFilePaths } from '../services/fs';
import { convertHEIC } from '../services/heicConvertor';
import appUpdater from '../services/appUpdater';
export default function setupIpcComs(
tray: Tray,
@ -106,4 +107,8 @@ export default function setupIpcComs(
ipcMain.handle('open-log-dir', () => {
shell.openPath(app.getPath('logs'));
});
ipcMain.on('update-and-restart', () => {
appUpdater.updateAndRestart();
});
}

View file

@ -29,7 +29,7 @@ export function buildContextMenu(
? [
{
label: 'Update available',
click: () => showUpdateDialog(),
click: () => showUpdateDialog(mainWindow),
},
]
: []),

2
ui

@ -1 +1 @@
Subproject commit 6e4e040d548fe83dd62111727e7686690fa8e630
Subproject commit 15f1d5da3f673b91edf9d27328c642fd71c8bfc2