forked from LN-Zap/zap-desktop
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for auto updates using electron-updater. Fix LN-Zap#607
- Loading branch information
Showing
5 changed files
with
155 additions
and
31 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { dialog } from 'electron' | ||
import { autoUpdater } from 'electron-updater' | ||
import { updaterLog } from './utils/log' | ||
|
||
autoUpdater.logger = updaterLog | ||
|
||
/** | ||
* @class ZapController | ||
* | ||
* The ZapController class coordinates actions between the the main nand renderer processes. | ||
*/ | ||
class ZapUpdater { | ||
/** | ||
* Create a new ZapUpdater instance. | ||
* @param {BrowserWindow} mainWindow BrowserWindow instance to interact with | ||
*/ | ||
constructor(mainWindow) { | ||
this.mainWindow = mainWindow | ||
} | ||
|
||
init() { | ||
autoUpdater.on('update-downloaded', () => { | ||
const opt = { | ||
type: 'question', | ||
buttons: ['Install', 'Later'], | ||
title: 'Update available', | ||
message: 'An update is available. Restart the app and install?' | ||
} | ||
dialog.showMessageBox(this.mainWindow, opt, choice => { | ||
if (choice !== 0) { | ||
return | ||
} | ||
setTimeout(() => { | ||
autoUpdater.quitAndInstall() | ||
}, 100) | ||
}) | ||
}) | ||
|
||
this.initAutoUpdate() | ||
} | ||
|
||
initAutoUpdate() { | ||
autoUpdater.checkForUpdates() | ||
const oneHour = 60 * 60 * 1000 | ||
setInterval(() => autoUpdater.checkForUpdates(), oneHour) | ||
} | ||
} | ||
|
||
export default ZapUpdater |
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
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