mirror of
https://github.com/PreMiD/PreMiD.git
synced 2026-04-06 04:41:58 +02:00
Auto Updating - Windows
This commit is contained in:
1
PMD_Extension
Submodule
1
PMD_Extension
Submodule
Submodule PMD_Extension added at 0802f6392b
8
installer_assets/AutoUpdater.xml
Normal file
8
installer_assets/AutoUpdater.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<autoUpdateProject>
|
||||
<fullName>PreMiD</fullName>
|
||||
<shortName>PreMiD</shortName>
|
||||
<vendor>Timeraa</vendor>
|
||||
<version>2.0</version>
|
||||
<singleInstanceCheck>1</singleInstanceCheck>
|
||||
<requestedExecutionLevel>asInvoker</requestedExecutionLevel>
|
||||
</autoUpdateProject>
|
||||
BIN
installer_assets/appIcon.png
Normal file
BIN
installer_assets/appIcon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
0
installer_assets/reset.js
Normal file
0
installer_assets/reset.js
Normal file
6
installer_assets/update.ini
Normal file
6
installer_assets/update.ini
Normal file
@@ -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
|
||||
BIN
installer_assets/updater.exe
Normal file
BIN
installer_assets/updater.exe
Normal file
Binary file not shown.
3
src/.gitignore
vendored
Normal file
3
src/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
update.ini
|
||||
updater.exe
|
||||
updater.app
|
||||
5
src/package-lock.json
generated
5
src/package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user