This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,116 additions
and
410 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,80 @@ | ||
import { BrowserWindow, dialog } from 'electron'; | ||
import { autoUpdater } from 'electron-updater'; | ||
|
||
let showUpdateNotAvailable = false; | ||
let window: BrowserWindow; | ||
const registry: Map<BrowserWindow, { showUpdateNotAvailable: boolean }> = new Map(); | ||
const windows: Set<BrowserWindow> = new Set(); | ||
|
||
export function checkForUpdates(win: BrowserWindow, startedByUser?: boolean): void { | ||
export async function checkForUpdates(win: BrowserWindow, startedByUser?: boolean): Promise<void> { | ||
autoUpdater.autoDownload = false; | ||
showUpdateNotAvailable = startedByUser || false; | ||
window = win; | ||
autoUpdater.checkForUpdatesAndNotify().catch(() => { | ||
dialog.showErrorBox('Check for Updates', 'Error while checking for updates.'); | ||
|
||
windows.add(win); | ||
|
||
registry.set(win, { | ||
showUpdateNotAvailable: startedByUser || false | ||
}); | ||
|
||
try { | ||
await autoUpdater.checkForUpdatesAndNotify(); | ||
} catch { | ||
dialog.showErrorBox('Check for Updates', 'Error while checking for updates.'); | ||
} | ||
} | ||
|
||
autoUpdater.on('update-available', info => { | ||
dialog.showMessageBox( | ||
{ | ||
type: 'info', | ||
message: `There is a new version available: ${ | ||
info.version | ||
} \nShould Alva download the update?`, | ||
buttons: ['yes', 'no'] | ||
}, | ||
buttonIndex => { | ||
if (buttonIndex === 0) { | ||
autoUpdater.downloadUpdate().catch(() => { | ||
dialog.showErrorBox( | ||
'Check for Updates', | ||
'An error occured while updating. Please try again manually.' | ||
); | ||
}); | ||
export function startUpdater(): void { | ||
autoUpdater.on('update-available', info => { | ||
dialog.showMessageBox( | ||
{ | ||
type: 'info', | ||
message: `There is a new version available: ${ | ||
info.version | ||
} \nShould Alva download the update?`, | ||
buttons: ['yes', 'no'] | ||
}, | ||
buttonIndex => { | ||
if (buttonIndex === 0) { | ||
autoUpdater.downloadUpdate().catch(() => { | ||
dialog.showErrorBox( | ||
'Check for Updates', | ||
'An error occured while updating. Please try again manually.' | ||
); | ||
}); | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
); | ||
}); | ||
|
||
autoUpdater.on('update-not-available', info => { | ||
if (showUpdateNotAvailable) { | ||
dialog.showMessageBox({ message: 'Alva is up-to-date.' }); | ||
} | ||
}); | ||
autoUpdater.on('update-not-available', info => { | ||
windows.forEach(window => { | ||
const context = registry.get(window); | ||
if (context && context.showUpdateNotAvailable) { | ||
dialog.showMessageBox({ message: 'Alva is up-to-date.' }); | ||
} | ||
}); | ||
}); | ||
|
||
autoUpdater.on('error', () => { | ||
dialog.showErrorBox( | ||
'Check for Updates', | ||
'An error occured while updating. Please try again manually.' | ||
); | ||
}); | ||
|
||
autoUpdater.on('error', () => { | ||
dialog.showErrorBox( | ||
'Check for Updates', | ||
'An error occured while updating. Please try again manually.' | ||
); | ||
}); | ||
autoUpdater.on('download-progress', progressObj => { | ||
windows.forEach(window => { | ||
window.setProgressBar(progressObj.percent / 100); | ||
}); | ||
}); | ||
|
||
autoUpdater.on('download-progress', progressObj => { | ||
window.setProgressBar(progressObj.percent / 100); | ||
}); | ||
autoUpdater.on('update-downloaded', info => { | ||
dialog.showMessageBox({ message: 'Update downloaded. Will be installed on next restart.' }); | ||
|
||
autoUpdater.on('update-downloaded', info => { | ||
dialog.showMessageBox({ message: 'Update downloaded. Will be installed on next restart.' }); | ||
// remove progress bar | ||
windows.forEach(window => { | ||
window.setProgressBar(-1); | ||
}); | ||
}); | ||
} | ||
|
||
// remove progress bar | ||
window.setProgressBar(-1); | ||
}); | ||
export function stopUpdater(): void { | ||
autoUpdater.removeAllListeners(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.