mirror of https://github.com/keeweb/keeweb.git
installing updates on macos
This commit is contained in:
parent
21b8e9ae8f
commit
1d572d1fa9
|
@ -251,7 +251,8 @@ module.exports = function (grunt) {
|
|||
desktop: ['desktop/**/*.js', '!desktop/node_modules/**'],
|
||||
build: ['Gruntfile.js', 'grunt.*.js', 'build/**/*.js', 'webpack.config.js'],
|
||||
plugins: ['plugins/**/*.js'],
|
||||
util: ['util/**/*.js']
|
||||
util: ['util/**/*.js'],
|
||||
installer: ['package/osx/installer.js']
|
||||
},
|
||||
inline: {
|
||||
app: {
|
||||
|
|
|
@ -116,7 +116,7 @@ main.on('ready', () => {
|
|||
})
|
||||
.catch((e) => {
|
||||
electron.dialog.showErrorBox('KeeWeb', 'Error loading app: ' + e);
|
||||
process.exit(2);
|
||||
main.exit(2);
|
||||
});
|
||||
});
|
||||
main.on('open-file', (e, path) => {
|
||||
|
@ -949,7 +949,8 @@ function httpRequest(config, log, onLoad) {
|
|||
|
||||
function exitAndStartUpdate() {
|
||||
if (pendingUpdateFilePath) {
|
||||
// TODO: install the update
|
||||
const { installUpdate } = require('./updater');
|
||||
installUpdate(pendingUpdateFilePath);
|
||||
main.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { spawn, spawnSync } = require('child_process');
|
||||
const electron = require('electron');
|
||||
|
||||
function installUpdate(updateFilePath) {
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
installDarwinUpdate(updateFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
function installDarwinUpdate(updateFilePath) {
|
||||
const appPath = process.execPath.replace(/\.app\/.*?$/, '.app');
|
||||
const installerAppPath = path.join(appPath, 'Contents', 'Installer', 'KeeWeb Installer.app');
|
||||
const tempPath = path.join(electron.app.getPath('temp'), 'KeeWeb');
|
||||
const tempInstallerPath = path.join(tempPath, 'KeeWeb Installer.app');
|
||||
|
||||
if (!fs.existsSync(tempPath)) {
|
||||
fs.mkdirSync(tempPath, { recursive: true });
|
||||
}
|
||||
|
||||
spawnSync('rm', ['-rf', tempInstallerPath]);
|
||||
const res = spawnSync('cp', ['-pRf', installerAppPath, tempInstallerPath]);
|
||||
if (res.status) {
|
||||
const copyErr = res.stderr.toString('utf8');
|
||||
throw new Error(`Error installing update: ${copyErr}`);
|
||||
}
|
||||
|
||||
const installerExecutable = path.join(tempInstallerPath, 'Contents', 'MacOS', 'applet');
|
||||
spawn(
|
||||
installerExecutable,
|
||||
['--update', `--wait-pid=${process.pid}`, `--dmg=${updateFilePath}`, `--app=${appPath}`],
|
||||
{
|
||||
detached: true
|
||||
}
|
||||
).unref();
|
||||
}
|
||||
|
||||
module.exports.installUpdate = installUpdate;
|
|
@ -14,7 +14,7 @@ if (args.update) {
|
|||
}
|
||||
|
||||
const dmg = checkFilePath(args.dmg, 'dmg');
|
||||
const target = checkFilePath(args.target, 'app');
|
||||
const target = checkFilePath(args.app, 'app');
|
||||
|
||||
const targetOwner = app.doShellScript(`stat -f '%Su' ${target}`);
|
||||
const setAdminRights = targetOwner === 'root';
|
||||
|
@ -37,6 +37,7 @@ rm -rf ${tmpDir}
|
|||
scriptOptions.administratorPrivileges = true;
|
||||
}
|
||||
app.doShellScript(script, scriptOptions);
|
||||
Application(args.app).activate();
|
||||
} else if (args.install) {
|
||||
app.doShellScript('chown -R 0 /Applications/KeeWeb.app', { administratorPrivileges: true });
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue