Add toast to autoUpdater
This commit is contained in:
parent
ff31625544
commit
31ccdb73a1
|
|
@ -4,6 +4,7 @@ import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
import { autoUpdater } from 'electron-updater'
|
import { autoUpdater } from 'electron-updater'
|
||||||
import Store from './lib/Store'
|
import Store from './lib/Store'
|
||||||
|
import { registerToastTarget, showErrorToast, showSuccessToast, showToast } from './lib/Toast'
|
||||||
|
|
||||||
autoUpdater.autoDownload = false;
|
autoUpdater.autoDownload = false;
|
||||||
autoUpdater.autoInstallOnAppQuit = true;
|
autoUpdater.autoInstallOnAppQuit = true;
|
||||||
|
|
@ -80,6 +81,7 @@ function finishSetup(): void {
|
||||||
store.set('showSetupWindow', false);
|
store.set('showSetupWindow', false);
|
||||||
createMainWindow();
|
createMainWindow();
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.on('ready-to-show', () => {
|
||||||
|
registerToastTarget(mainWindow);
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
setupWindow.close();
|
setupWindow.close();
|
||||||
})
|
})
|
||||||
|
|
@ -98,6 +100,8 @@ function createWindow(): void {
|
||||||
} else {
|
} else {
|
||||||
createMainWindow();
|
createMainWindow();
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.on('ready-to-show', () => {
|
||||||
|
registerToastTarget(mainWindow);
|
||||||
|
checkForUpdates();
|
||||||
splashWindow.close();
|
splashWindow.close();
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
})
|
})
|
||||||
|
|
@ -132,8 +136,6 @@ app.whenReady().then(() => {
|
||||||
// dock icon is clicked and there are no other windows open.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||||
})
|
})
|
||||||
|
|
||||||
checkForUpdates();
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS. There, it's common
|
// Quit when all windows are closed, except on macOS. There, it's common
|
||||||
|
|
@ -156,30 +158,36 @@ function showNotification(value: any) {
|
||||||
function checkForUpdates() {
|
function checkForUpdates() {
|
||||||
autoUpdater.checkForUpdates();
|
autoUpdater.checkForUpdates();
|
||||||
console.log(`Checking for updates. Current version ${app.getVersion()}`);
|
console.log(`Checking for updates. Current version ${app.getVersion()}`);
|
||||||
|
showToast(`Checking for updates. Current version ${app.getVersion()}`);
|
||||||
showNotification(`Checking for updates. Current version ${app.getVersion()}`);
|
showNotification(`Checking for updates. Current version ${app.getVersion()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*New Update Available*/
|
/*New Update Available*/
|
||||||
autoUpdater.on("update-available", () => {
|
autoUpdater.on("update-available", () => {
|
||||||
console.log(`Update available. Current version ${app.getVersion()}`);
|
console.log(`Update available. Current version ${app.getVersion()}`);
|
||||||
|
showToast(`Update available. Current version ${app.getVersion()}`);
|
||||||
showNotification(`Update available. Current version ${app.getVersion()}`);
|
showNotification(`Update available. Current version ${app.getVersion()}`);
|
||||||
let pth = autoUpdater.downloadUpdate();
|
let pth = autoUpdater.downloadUpdate();
|
||||||
console.log(pth);
|
console.log(pth);
|
||||||
|
showToast(`Download update path : ${pth}`);
|
||||||
showNotification(`Download update path : ${pth}`);
|
showNotification(`Download update path : ${pth}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
autoUpdater.on("update-not-available", () => {
|
autoUpdater.on("update-not-available", () => {
|
||||||
console.log(`No update available. Current version ${app.getVersion()}`);
|
console.log(`No update available. Current version ${app.getVersion()}`);
|
||||||
|
showToast(`No update available. Current version ${app.getVersion()}`);
|
||||||
showNotification(`No update available. Current version ${app.getVersion()}`);
|
showNotification(`No update available. Current version ${app.getVersion()}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*Download Completion Message*/
|
/*Download Completion Message*/
|
||||||
autoUpdater.on("update-downloaded", () => {
|
autoUpdater.on("update-downloaded", () => {
|
||||||
console.log(`Update downloaded. Current version ${app.getVersion()}`);
|
console.log(`Update downloaded. Current version ${app.getVersion()}`);
|
||||||
|
showSuccessToast(`Update downloaded. Current version ${app.getVersion()}`);
|
||||||
showNotification(`Update downloaded. Current version ${app.getVersion()}`);
|
showNotification(`Update downloaded. Current version ${app.getVersion()}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
autoUpdater.on("error", (info) => {
|
autoUpdater.on("error", (info) => {
|
||||||
console.log(info);
|
console.log(info);
|
||||||
|
showErrorToast(`Error: ${info}`);
|
||||||
showNotification(`Error: ${info}`);
|
showNotification(`Error: ${info}`);
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue