diff --git a/PMD_Extension b/PMD_Extension new file mode 160000 index 0000000..0802f63 --- /dev/null +++ b/PMD_Extension @@ -0,0 +1 @@ +Subproject commit 0802f6392be71a46d0ad7826343fc7f276a11af5 diff --git a/installer_assets/AutoUpdater.xml b/installer_assets/AutoUpdater.xml new file mode 100644 index 0000000..d3dfb1a --- /dev/null +++ b/installer_assets/AutoUpdater.xml @@ -0,0 +1,8 @@ + + PreMiD + PreMiD + Timeraa + 2.0 + 1 + asInvoker + \ No newline at end of file diff --git a/installer_assets/appIcon.png b/installer_assets/appIcon.png new file mode 100644 index 0000000..845bf5b Binary files /dev/null and b/installer_assets/appIcon.png differ diff --git a/installer_assets/reset.js b/installer_assets/reset.js new file mode 100644 index 0000000..e69de29 diff --git a/installer_assets/update.ini b/installer_assets/update.ini new file mode 100644 index 0000000..aa41d27 --- /dev/null +++ b/installer_assets/update.ini @@ -0,0 +1,6 @@ +[Update] + +url = https://api.premid.app/app/update +version_id = 0200 +check_for_updates = 1 +update_download_location = ${installer_directory}/updating \ No newline at end of file diff --git a/installer_assets/updater.exe b/installer_assets/updater.exe new file mode 100644 index 0000000..abcd6b9 Binary files /dev/null and b/installer_assets/updater.exe differ diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..8b555fd --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,3 @@ +update.ini +updater.exe +updater.app \ No newline at end of file diff --git a/src/package-lock.json b/src/package-lock.json index 8f5db8c..9351f23 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1983,6 +1983,11 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true }, + "sudo-prompt": { + "version": "8.2.5", + "resolved": "https://registry.npmjs.org/sudo-prompt/-/sudo-prompt-8.2.5.tgz", + "integrity": "sha512-rlBo3HU/1zAJUrkY6jNxDOC9eVYliG6nS4JA8u8KAshITd07tafMc/Br7xQwCSseXwJ2iCcHCE8SNWX3q8Z+kw==" + }, "sumchecker": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-2.0.2.tgz", diff --git a/src/package.json b/src/package.json index 4bc639e..696fb2f 100644 --- a/src/package.json +++ b/src/package.json @@ -27,7 +27,8 @@ "express": "4.16.4", "request": "2.88.0", "request-promise-native": "1.0.7", - "socket.io": "2.2.0" + "socket.io": "2.2.0", + "sudo-prompt": "^8.2.5" }, "devDependencies": { "chalk": "2.4.2", diff --git a/src/util/updateChecker.js b/src/util/updateChecker.js index 57ba108..92dd6e2 100644 --- a/src/util/updateChecker.js +++ b/src/util/updateChecker.js @@ -1,157 +1,56 @@ -var { app, dialog, BrowserWindow } = require('electron'), +var { dialog } = require('electron'), os = require('os'), - request = require('request-promise-native'), - { existsSync, mkdirSync, createWriteStream } = require('fs'), debug = require('./debug'), - { exec } = require('child_process'); + { execFile } = require('child_process'), + path = require('path'); async function checkForUpdate(sendNotification = false, sendNoUpdateInfo = false) { debug.info('Checking for update...'); - request( - { - url: 'https://api.premid.app/version', - json: true - }, - function(error, response, body) { - if (error) { - debug.error('Checking for update... - Error\n' + error.message); - dialog.showMessageBox({ - type: 'error', - title: 'PreMiD', - message: `Error while checking for update!`, - detail: `${error}` - }); - return; - } - //* Remove v from version - var gitVersion = body.app; - //* Compare version - if (gitVersion > VERSION) { - global.UPDATEAVAIABLE = gitVersion; - - debug.info(`New version avaiable: V${VERSION} > V${gitVersion}`); + var osSuffix = os.platform(); + if (osSuffix == 'win32') osSuffix = '.exe'; + if (osSuffix == 'darwin') osSuffix = '.app'; + const { execFile } = require('child_process'); + const ls = execFile('./updater' + osSuffix, [ '--mode', 'unattended' ]); + ls.on('close', (code) => { + if (code == 0) { + debug.info('Update available!'); + if (sendNotification) dialog.showMessageBox( { type: 'question', buttons: [ 'Nah, not now', 'Yes!' ], title: 'Update available!', - message: `PreMiD V${gitVersion} is available for download!\nDo you want to update?` + message: `A new version of PreMiD is available for download!\nDo you want to update now?` }, function(response) { - if (response == 1) { - if (os.platform() == 'darwin') { - debug.info('Downloading latest release...'); - if (!existsSync(app.getPath('temp') + 'PreMiD/')) - mkdirSync(app.getPath('temp') + 'PreMiD'); - var oldPercentage; - app.dock.show(); - var win = new BrowserWindow({ show: false }); - - downloadFile({ - remoteFile: `https://github.com/PreMiD/PreMiD/releases/download/v1.2/PreMiD-Mac.dmg`, - localFile: app.getPath('temp') + 'PreMiD/update.dmg', - onProgress: function(received, total) { - var percentage = received * 100 / total; - if (Math.floor(percentage) != oldPercentage) { - win.setProgressBar(Math.floor(percentage) / 100); - oldPercentage = Math.floor(percentage); - debug.info(`Update download: ${Math.floor(percentage)}%`); - } - } - }).then(function() { - win.setProgressBar(-1); - win.close(); - win = null; - - dialog.showMessageBox(null, { - type: 'info', - message: - 'Update downloaded successfully, please drag the new version into your applications folder and open it.' - }); - - exec( - `hdiutil attach ${app.getPath('temp')}PreMiD/update.dmg`, - (err, stdout, stderr) => { - if (!err) { - process.exit(0); - } else debug.error('oof... something bad happened\n' + err); - } - ); - debug.info('Update download: successful'); - }); - } else if (os.platform() != 'win32') { - debug.info('Unrecognizable system detected... Follow instructions on release.'); - require('electron').shell.openExternal( - `https://github.com/PreMiD/PreMiD/releases/latest` - ); + if (response == 0) return; + var sudo = require('sudo-prompt'); + sudo.exec( + `"${path.resolve( + './updater' + osSuffix + )}" --mode unattended --unattendedmodebehavior download`, + { + name: 'PreMiD Updater' + }, + function(error, stdout, stderr) { + process.exit(0); } - //TODO Handle Windows - //process.exit(0); - } + ); } ); - } else { - if (os.platform() == 'darwin' && existsSync(app.getPath('temp') + 'PreMiD')) - require('del')([ app.getPath('temp') + 'PreMiD' ], { force: true }); - global.UPDATEAVAIABLE = false; - debug.success(`Checking for update... - Up to date`); - if (sendNoUpdateInfo) { - dialog.showMessageBox({ - type: 'info', - title: 'PreMiD', - message: `You are up to date! (v${VERSION})` - }); - } - } + } else { + if (sendNoUpdateInfo) + dialog.showMessageBox({ + type: 'info', + title: 'Up to date!', + message: 'PreMiD is up to date!' + }); } - ); + }); return UPDATEAVAIABLE; } -/** - * Promise based download file method - */ -function downloadFile(configuration) { - return new Promise(function(resolve, reject) { - // Save variable to know progress - var received_bytes = 0; - var total_bytes = 0; - - var req = request({ - method: 'GET', - uri: configuration.remoteFile - }); - - var out = createWriteStream(configuration.localFile); - req.pipe(out); - - req.on('response', function(data) { - // Change the total bytes value to get progress later. - total_bytes = parseInt(data.headers['content-length']); - }); - - // Get progress if callback exists - if (configuration.hasOwnProperty('onProgress')) { - req.on('data', function(chunk) { - // Update the received bytes - received_bytes += chunk.length; - - configuration.onProgress(received_bytes, total_bytes); - }); - } else { - req.on('data', function(chunk) { - // Update the received bytes - received_bytes += chunk.length; - }); - } - - req.on('end', function() { - resolve(); - }); - }); -} - module.exports.checkForUpdate = checkForUpdate;