|
const {app, BrowserWindow, Menu, protocol, ipcMain} = require('electron'); |
|
const log = require('electron-log'); |
|
const {autoUpdater} = require("electron-updater"); |
|
|
|
//------------------------------------------------------------------- |
|
// Logging |
|
// |
|
// THIS SECTION IS NOT REQUIRED |
|
// |
|
// This logging setup is not required for auto-updates to work, |
|
// but it sure makes debugging easier :) |
|
//------------------------------------------------------------------- |
|
autoUpdater.logger = log; |
|
autoUpdater.logger.transports.file.level = 'info'; |
|
log.info('App starting...'); |
|
|
|
//------------------------------------------------------------------- |
|
// Define the menu |
|
// |
|
// THIS SECTION IS NOT REQUIRED |
|
//------------------------------------------------------------------- |
|
let template = [] |
|
if (process.platform === 'darwin') { |
|
// OS X |
|
const name = app.getName(); |
|
template.unshift({ |
|
label: name, |
|
submenu: [ |
|
{ |
|
label: 'About ' + name, |
|
role: 'about' |
|
}, |
|
{ |
|
label: 'Quit', |
|
accelerator: 'Command+Q', |
|
click() { app.quit(); } |
|
}, |
|
] |
|
}) |
|
} |
|
|
|
|
|
//------------------------------------------------------------------- |
|
// Open a window that displays the version |
|
// |
|
// THIS SECTION IS NOT REQUIRED |
|
// |
|
// This isn't required for auto-updates to work, but it's easier |
|
// for the app to show a window than to have to click "About" to see |
|
// that updates are working. |
|
//------------------------------------------------------------------- |
|
let win; |
|
|
|
function sendStatusToWindow(text) { |
|
log.info(text); |
|
win.webContents.send('message', text); |
|
} |
|
function createDefaultWindow() { |
|
win = new BrowserWindow(); |
|
win.webContents.openDevTools(); |
|
win.on('closed', () => { |
|
win = null; |
|
}); |
|
win.loadURL(`file://${__dirname}/version.html#v${app.getVersion()}`); |
|
return win; |
|
} |
|
autoUpdater.on('checking-for-update', () => { |
|
sendStatusToWindow('Checking for update...'); |
|
}) |
|
autoUpdater.on('update-available', (ev, info) => { |
|
sendStatusToWindow('Update available.'); |
|
}) |
|
autoUpdater.on('update-not-available', (ev, info) => { |
|
sendStatusToWindow('Update not available.'); |
|
}) |
|
autoUpdater.on('error', (ev, err) => { |
|
sendStatusToWindow('Error in auto-updater.'); |
|
}) |
|
autoUpdater.on('download-progress', (ev, progressObj) => { |
|
sendStatusToWindow('Download progress...'); |
|
}) |
|
autoUpdater.on('update-downloaded', (ev, info) => { |
|
sendStatusToWindow('Update downloaded; will install in 5 seconds'); |
|
}); |
|
app.on('ready', function() { |
|
// Create the Menu |
|
const menu = Menu.buildFromTemplate(template); |
|
Menu.setApplicationMenu(menu); |
|
|
|
createDefaultWindow(); |
|
}); |
|
app.on('window-all-closed', () => { |
|
app.quit(); |
|
}); |
|
|
|
//------------------------------------------------------------------- |
|
// Auto updates |
|
// |
|
// For details about these events, see the Wiki: |
|
// https://github.com/electron-userland/electron-builder/wiki/Auto-Update#events |
|
// |
|
// The app doesn't need to listen to any events except `update-downloaded` |
|
// |
|
// Uncomment any of the below events to listen for them. Also, |
|
// look in the previous section to see them being used. |
|
//------------------------------------------------------------------- |
|
// autoUpdater.on('checking-for-update', () => { |
|
// }) |
|
// autoUpdater.on('update-available', (ev, info) => { |
|
// }) |
|
// autoUpdater.on('update-not-available', (ev, info) => { |
|
// }) |
|
// autoUpdater.on('error', (ev, err) => { |
|
// }) |
|
// autoUpdater.on('download-progress', (ev, progressObj) => { |
|
// }) |
|
autoUpdater.on('update-downloaded', (ev, info) => { |
|
// Wait 5 seconds, then quit and install |
|
// In your application, you don't need to wait 5 seconds. |
|
// You could call autoUpdater.quitAndInstall(); immediately |
|
setTimeout(function() { |
|
autoUpdater.quitAndInstall(); |
|
}, 5000) |
|
}) |
|
|
|
app.on('ready', function() { |
|
autoUpdater.checkForUpdates(); |
|
}); |
Skip app dependencies rebuild because platform is different Error: Cannot check wine version: Error: Exit code: ENOENT. spawn wine ENOENT at /Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/src/packager.ts:399:13 at Generator.throw (<anonymous>) From previous event: at checkWineVersion (/Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/out/packager.js:57:22) at /Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/src/packager.ts:207:17 From previous event: at Packager.doBuild (/Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/out/packager.js:335:11) at /Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/src/packager.ts:151:38 at Generator.next (<anonymous>) at processImmediate (internal/timers.js:456:21) From previous event: at Packager.build (/Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/out/packager.js:261:11) at /Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/src/builder.ts:214:40 at Generator.next (<anonymous>) From previous event: at build (/Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/out/builder.js:63:21) at Object.<anonymous> (/Users/elliotyan/Documents/me/updater-test/node_modules/electron-builder/out/cli/build-cli.js:68:41) at Module._compile (internal/modules/cjs/loader.js:1158:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10) at Module.load (internal/modules/cjs/loader.js:1002:32) at Function.Module._load (internal/modules/cjs/loader.js:901:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) at internal/main/run_main_module.js:18:47