Skip to content

Commit

Permalink
Fix auto-launch not working on installed program
Browse files Browse the repository at this point in the history
  • Loading branch information
Heejin Lee committed Sep 3, 2016
1 parent c984ea0 commit 7695331
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
10 changes: 4 additions & 6 deletions app/main/server/app/app-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ const ShortcutService = require('./shortcut-service');
const iconProtocol = require('./icon-protocol');
const logger = require('../../shared/logger');

const AutoLaunch = require('auto-launch');
const autoLauncher = new AutoLaunch({
const AutoLauncher = require('./auto-launcher');
const autoLauncher = new AutoLauncher({
name: 'Hain',
isHidden: true
path: `"${process.execPath}" --silent`
});
// Workaround for keeping registry key name
autoLauncher.opts.appName = 'Hain';

module.exports = class AppService {
constructor(prefManager, workerClient, workerProxy) {
Expand All @@ -44,7 +42,7 @@ module.exports = class AppService {
autoLauncher.enable();

const isRestarted = (lo_includes(process.argv, '--restarted'));
const silentLaunch = (lo_includes(process.argv, '--hidden') || lo_includes(process.argv, '--silent'));
const silentLaunch = (lo_includes(process.argv, '--silent'));
const shouldQuit = electronApp.makeSingleInstance((cmdLine, workingDir) => {
if (self._isRestarting)
return;
Expand Down
39 changes: 39 additions & 0 deletions app/main/server/app/auto-launcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

const Registry = require('winreg');

module.exports = class AutoLauncher {
constructor(opts) {
this.appName = opts.name;
this.appPath = opts.path;
this.reg = new Registry({
hive: Registry.HKCU,
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'
});
}
enable() {
return new Promise((resolve, reject) => {
this.reg.set(this.appName, Registry.REG_SZ, this.appPath, (err) => {
if (err)
return reject(err);
resolve();
});
});
}
disable() {
return new Promise((resolve, reject) => {
this.reg.remove(this.appName, (err) => {
if (err)
return reject(err);
resolve();
});
});
}
isEnabled() {
return new Promise((resolve, reject) => {
this.reg.get(this.appName, (err, item) => {
resolve(item != null);
});
});
}
};
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"dependencies": {
"application-config-path": "^0.1.0",
"auto-launch": "4.0.0",
"co": "^4.6.0",
"electron-squirrel-startup": "^1.0.0",
"fs-extra": "^0.26.5",
Expand Down Expand Up @@ -57,6 +56,7 @@
"tunnel": "0.0.4",
"twitter-text": "^1.13.4",
"uuid": "2.0.2",
"winreg": "1.2.2",
"winston": "^2.2.0"
}
}

0 comments on commit 7695331

Please sign in to comment.