Skip to content

Commit

Permalink
Ability to auto-launch app on login
Browse files Browse the repository at this point in the history
  • Loading branch information
mariosinani authored and klaudiosinani committed Oct 28, 2017
1 parent 1bceb4f commit ea674f1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
15 changes: 15 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@ function exportAsPDF() {

ipc.on('export', exportAsPDF);

function toggleAutoLaunch() {
// Decide whether or not the app should launch on login
const startup = require('./startup');

if (config.get('autoLaunch')) {
// Activate app lauching
startup.activate();
} else {
// Deactivate app lauching
startup.deactivate();
}
}

ipc.on('auto-launch', toggleAutoLaunch);

ipc.on('next-note', goToNextNote);

ipc.on('previous-note', goToPreviewsNote);
Expand Down
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = new Config({
},
menuBarVisible: false,
autoNightMode: false,
autoLaunch: false,
hideTray: false,
darkMode: false,
blackMode: false,
Expand Down
16 changes: 16 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ const darwinTpl = [{
click() {
activate('settings');
}
}, {
label: 'Launch on Start',
type: 'checkbox',
checked: config.get('autoLaunch'),
click(item) {
config.set('autoLaunch', item.checked);
activate('auto-launch');
}
}, {
label: 'Edit Shortcut Keys',
accelerator: 'CmdorCtrl+.',
Expand Down Expand Up @@ -691,6 +699,14 @@ const otherTpl = [{
click() {
activate('settings');
}
}, {
label: 'Launch on Start',
type: 'checkbox',
checked: config.get('autoLaunch'),
click(item) {
config.set('autoLaunch', item.checked);
activate('auto-launch');
}
}, {
label: 'Edit Shortcut Keys',
accelerator: 'CmdorCtrl+.',
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
"pack:windows": "electron-packager . --no-prune --overwrite --asar --out=dist --platform=win32 --arch=ia32 --icon=static/Icon.ico --version-string.ProductName=$npm_package_productName && cd dist/Tusk-win32-ia32 && zip -ryq9 ../Tusk-windows-v${npm_package_version}.zip *"
},
"dependencies": {
"ms": "^2.0.0",
"fs-extra": "^4.0.2",
"simple-get": "^2.7.0",
"time-stamp": "^2.0.0",
"auto-launch": "^5.0.1",
"electron-config": "^1.0.0",
"electron-context-menu": "^0.9.0",
"electron-debug": "^1.3.0",
"electron-dl": "^1.9.0",
"electron-is-dev": "^0.1.2",
"electron-debug": "^1.3.0",
"electron-config": "^1.0.0",
"electron-context-menu": "^0.9.0"
"fs-extra": "^4.0.2",
"ms": "^2.0.0",
"simple-get": "^2.7.0",
"time-stamp": "^2.0.0"
},
"devDependencies": {
"electron": "^1.7.8",
Expand Down
35 changes: 35 additions & 0 deletions startup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
const electron = require('electron');
const AutoLaunch = require('auto-launch');

const app = electron.app;

const launchTusk = new AutoLaunch({
name: 'Tusk',
path: (process.platform === 'darwin') ? app.getPath('exe').replace(/\.app\/Content.*/, '.app') : undefined,
isHidden: true
});

function activate() {
// Activate app launch on login
return launchTusk
.isEnabled()
.then(enabled => {
if (!enabled) {
return launchTusk.enable();
}
});
}

function deactivate() {
// Deaactivate app launch on login
return launchTusk
.isEnabled()
.then(enabled => {
if (enabled) {
return launchTusk.disable();
}
});
}

module.exports = {activate, deactivate};

0 comments on commit ea674f1

Please sign in to comment.