setup app update api
This commit is contained in:
parent
3df11180ec
commit
e33f28f38e
|
@ -9,3 +9,13 @@ export const showOnTray = (content: string) => {
|
|||
export const reloadWindow = () => {
|
||||
ipcRenderer.send('reload-window');
|
||||
};
|
||||
|
||||
export const registerUpdateEventListener = (showUpdateDialog: () => void) => {
|
||||
ipcRenderer.on('show-update-dialog', () => {
|
||||
showUpdateDialog();
|
||||
});
|
||||
};
|
||||
|
||||
export const updateAndRestart = () => {
|
||||
ipcRenderer.send('update-and-restart');
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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,34 @@ 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');
|
||||
|
||||
// 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();
|
||||
// }
|
||||
// });
|
||||
};
|
||||
|
|
|
@ -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.handle('update-and-restart', () => {
|
||||
appUpdater.updateAndRestart();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ export function buildContextMenu(
|
|||
paused,
|
||||
} = args;
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
...(isUpdateAvailable()
|
||||
...(!isUpdateAvailable()
|
||||
? [
|
||||
{
|
||||
label: 'Update available',
|
||||
click: () => showUpdateDialog(),
|
||||
click: () => showUpdateDialog(mainWindow),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
|
Loading…
Reference in a new issue