-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When I'm updating the Electron app in the background the main window pops up for a second. #446
Comments
Here is in short what I have at the moment in my function executeSquirrelCommand(args, done) {
const updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');
fs.stat(updateDotExe, function(err, stats) {
if (err) {
return false;
}
var child = cp.spawn(updateDotExe, args, {detached: true});
child.on('close', function(code) {
done();
});
});
}
function updateSelfWin() {
executeSquirrelCommand(['--update', config.RELEASES], function() {
// On done :)
});
}
function handleSquirrelEvent() {
if (process.platform !== 'win32') {
return false;
}
function install(done) {
var target = path.basename(process.execPath);
executeSquirrelCommand(['--createShortcut', target], done);
}
function uninstall(done) {
var target = path.basename(process.execPath);
executeSquirrelCommand(['--removeShortcut', target], done);
}
var squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case '--squirrel-install':
install(app.quit);
return true;
case '--squirrel-updated':
install(app.quit);
return true;
case '--squirrel-obsolete':
app.quit();
return true;
case '--squirrel-uninstall':
uninstall(app.quit);
return true;
}
updateSelfWin();
return false;
};
handleSquirrelEvent(); |
The problem is you can't start the app until handleSquirrelEvent returns, yours concurrently runs the app |
Here's what Slack does: // Private: When our app is installed, Squirrel (our app install/update framework)
// invokes our executable with specific parameters, usually of the form
// '--squirrel-$EVENT $VERSION' (i.e. '--squirrel-install 0.1.0'). This is our
// chance to do custom install / uninstall actions. Once these events are handled,
// we **must** exit imediately
//
// appStart - A callback to be invoked to start the application if there are no
// Squirrel events to handle.
//
// Returns a {Promise} whose value is a Boolean - if 'true', start the app. If
// 'false', quit immediately.
async function handleSquirrelEvents() {
let options = process.argv.slice(1);
if (!(options && options.length >= 1)) return true;
let m = options[0].match(/--squirrel-([a-z]+)/);
if (!(m && m[1])) return true;
if (m[1] === 'firstrun') return true;
let defaultLocations = 'Desktop,StartMenu,Startup';
// NB: Babel currently hates switch + await, /shrug
if (m[1] === 'install') {
await createShortcuts(defaultLocations);
}
if (m[1] === 'updated') {
await updateShortcuts(defaultLocations);
}
if (m[1] === 'uninstall') {
await removeShortcuts(defaultLocations);
let taskKill = p`${'SYSTEMROOT'}/system32/taskkill.exe`;
let args = ['/F', '/IM', 'slack.exe', '/T'];
await spawn(taskKill, args);
}
return false;
}
// Go go go go go go go
handleSquirrelEvents()
.then((shouldRun) => {
if (!shouldRun) {
app.quit();
process.exit(0);
}
start();
})
.catch((e) => {
console.log(`Inevitable Demise! ${e.message}`);
console.log(e.stack);
app.quit();
process.exit(0);
}); |
@lipis can you tell me what your "config.RELEASES" is? |
@Schrims It's the URL of where the packages and the RELEASES file are stored..
|
I think we can close that one.. :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using Electron and the this Grunt task to make releases. Everything works perfectly fine and the updates are happening in the background, but during that update a second application's window pops up for a brief moment and then closes. Is there any way to avoid that somehow?
The text was updated successfully, but these errors were encountered: