-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a function to return the platform type/version
- Loading branch information
Hemal Ruparelia
committed
Nov 9, 2017
1 parent
3aa7e6c
commit fe1759c
Showing
4 changed files
with
142 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,76 @@ | ||
"use strict"; | ||
const fs = require("fs"); | ||
const { app, dialog } = require("electron"); | ||
const { autoUpdater } = require("electron-updater"); | ||
const isDev = require("electron-is-dev"); | ||
const log = require("electron-log"); | ||
'use strict'; | ||
const fs = require('fs'); | ||
const { app, dialog } = require('electron'); | ||
const { autoUpdater } = require('electron-updater'); | ||
const isDev = require('electron-is-dev'); | ||
const log = require('electron-log'); | ||
|
||
function appUpdater(mainWindow) { | ||
// Don't initiate auto-updates in development and on Linux system | ||
// since autoUpdater doesn't work on Linux | ||
if (isDev || process.platform === "linux") { | ||
return; | ||
} | ||
// Don't initiate auto-updates in development and on Linux system | ||
// since autoUpdater doesn't work on Linux | ||
if (isDev || process.platform === 'linux') { | ||
return; | ||
} | ||
|
||
// Log whats happening | ||
autoUpdater.logger = log; | ||
autoUpdater.logger.transports.file.level = "info"; | ||
log.info("App starting..."); | ||
// Log whats happening | ||
autoUpdater.logger = log; | ||
autoUpdater.logger.transports.file.level = 'info'; | ||
log.info('App starting...'); | ||
|
||
autoUpdater.logger = log; | ||
autoUpdater.logger = log; | ||
|
||
function sendStatusToWindow(text) { | ||
log.info(text); | ||
mainWindow.send("Updater", text); | ||
} | ||
function sendStatusToWindow(text) { | ||
log.info(text); | ||
if (mainWindow) { | ||
mainWindow.send('Updater', text); | ||
} | ||
} | ||
|
||
autoUpdater.on("checking-for-update", () => { | ||
sendStatusToWindow("Checking for update..."); | ||
}); | ||
autoUpdater.on("update-available", info => { | ||
sendStatusToWindow("Update available."); | ||
}); | ||
autoUpdater.on("update-not-available", info => { | ||
sendStatusToWindow("Update not available."); | ||
}); | ||
autoUpdater.on("error", err => { | ||
log.info(err); | ||
sendStatusToWindow(`Error in auto-updater.`); | ||
}); | ||
autoUpdater.on("download-progress", progressObj => { | ||
let log_message = "Download speed: " + progressObj.bytesPerSecond; | ||
log_message = log_message + " - Downloaded " + progressObj.percent + "%"; | ||
log_message = | ||
log_message + | ||
" (" + | ||
progressObj.transferred + | ||
"/" + | ||
progressObj.total + | ||
")"; | ||
sendStatusToWindow(log_message); | ||
}); | ||
autoUpdater.on('checking-for-update', () => { | ||
sendStatusToWindow('Checking for update...'); | ||
}); | ||
autoUpdater.on('update-available', info => { | ||
sendStatusToWindow('Update available.'); | ||
}); | ||
autoUpdater.on('update-not-available', info => { | ||
sendStatusToWindow('Update not available.'); | ||
}); | ||
autoUpdater.on('error', err => { | ||
log.info(err); | ||
sendStatusToWindow(`Error in auto-updater.`); | ||
}); | ||
autoUpdater.on('download-progress', progressObj => { | ||
let log_message = 'Download speed: ' + progressObj.bytesPerSecond; | ||
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'; | ||
log_message = log_message + ' (' + progressObj.transferred + '/' + progressObj.total + ')'; | ||
sendStatusToWindow(log_message); | ||
}); | ||
|
||
// Ask the user to restart if an update is available | ||
autoUpdater.on("update-downloaded", event => { | ||
dialog.showMessageBox( | ||
{ | ||
type: "question", | ||
buttons: ["Install and Relaunch", "Install Later"], | ||
defaultId: 0, | ||
message: `A new update ${event.version} has been downloaded`, | ||
detail: "It will be installed the next time you restart the application" | ||
}, | ||
response => { | ||
if (response === 0) { | ||
setTimeout(() => { | ||
autoUpdater.quitAndInstall(); | ||
// force app to quit. This is just a workaround, ideally autoUpdater.quitAndInstall() should relaunch the app. | ||
app.quit(); | ||
}, 1000); | ||
} | ||
} | ||
); | ||
}); | ||
// Init for updates | ||
autoUpdater.checkForUpdates(); | ||
// Ask the user to restart if an update is available | ||
autoUpdater.on('update-downloaded', event => { | ||
dialog.showMessageBox( | ||
{ | ||
type: 'question', | ||
buttons: ['Install and Relaunch', 'Install Later'], | ||
defaultId: 0, | ||
message: `A new update ${event.version} has been downloaded`, | ||
detail: 'It will be installed the next time you restart the application', | ||
}, | ||
response => { | ||
if (response === 0) { | ||
setTimeout(() => { | ||
autoUpdater.quitAndInstall(); | ||
// force app to quit. This is just a workaround, ideally autoUpdater.quitAndInstall() should relaunch the app. | ||
app.quit(); | ||
}, 1000); | ||
} | ||
} | ||
); | ||
}); | ||
// Init for updates | ||
autoUpdater.checkForUpdates(); | ||
} | ||
|
||
module.exports = { | ||
appUpdater | ||
appUpdater, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Check platform. Code from:https://github.com/adam-lynch/developing-an-electron-edge/ | ||
|
||
const os = require('os'); | ||
|
||
var platform = { | ||
isLinux: false, | ||
isMac: false, | ||
isWindows: false, | ||
isWindows8: false, | ||
version: os.release(), | ||
}; | ||
|
||
/** | ||
* Checks if the current platform version is greater than or equal to the desired minimum version given | ||
* | ||
* @param minimumVersion {string} E.g. 10.0.0. | ||
* See [the Darwin operating system Wikipedia entry](http://en.wikipedia.org/wiki/Darwin_%28operating_system%29#Release_history) for Mac - Darwin versions. | ||
* Also, Windows 8 >= 6.2.9200 | ||
* | ||
* @returns {boolean} | ||
*/ | ||
var isOfMinimumVersion = minimumVersion => { | ||
var actualVersionPieces = platform.version.split('.'), | ||
pieces = minimumVersion.split('.'), | ||
numberOfPieces = pieces.length; | ||
|
||
for (var i = 0; i < numberOfPieces; i++) { | ||
var piece = parseInt(pieces[i], 10), | ||
actualPiece = parseInt(actualVersionPieces[i], 10); | ||
|
||
if (typeof actualPiece === 'undefined') { | ||
break; // e.g. 13.1 passed and actual is 13.1.0 | ||
} else if (actualPiece > piece) { | ||
break; // doesn't matter what the next bits are, the major version (or whatever) is larger | ||
} else if (actualPiece === piece) { | ||
continue; // to check next version piece | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
return true; // all was ok | ||
}; | ||
|
||
var name = os.platform(); | ||
|
||
if (name === 'darwin') { | ||
platform.name = 'mac'; | ||
platform.isMac = true; | ||
} else if (name === 'linux') { | ||
platform.name = 'linux'; | ||
platform.isLinux = true; | ||
} else { | ||
platform.name = 'windows'; | ||
platform.isWindows = true; | ||
platform.isWindows8 = isOfMinimumVersion('6.2.9200'); | ||
} | ||
|
||
platform.is64Bit = os.arch() === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'); | ||
|
||
module.exports = platform; |