Skip to content

Commit f2e6de0

Browse files
committed
Autolaunch on startup & window size fix on windows
1 parent 7601723 commit f2e6de0

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ npm start
6868

6969
On Windows, you can make a `.bat` file with `start cmd /k nmp start` that then you can double click to launch the program.
7070

71+
The launch-on-startup functionality is only available on bundled releases. See the **Deployment** section.
72+
7173
## Testing
7274

7375
To make sure the code is ok and run some sanity checks on it:

app/routes/settings.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
const os = require('os');
12
const Account = require('../core/account');
23
const router = require("express").Router();
34
const gbs = require('../../config/globals');
45
const core = require('../core');
56
const ipc = require('electron').ipcMain;
67

8+
const baseSize = os.platform() === "win32" ? 330 : 270;
9+
710
router.get('/settings', async (req, res) => {
811
let accounts = await core.accounts();
912

1013
res.render('settings', {accounts});
1114

1215
/* Hack to set frontend to proper height */
13-
gbs.win.setSize(600, 270+80*Math.max(accounts.length,0.5));
16+
gbs.win.setSize(650, baseSize+80*Math.max(accounts.length,0.5));
1417
});
1518

1619
router.get('/connect', (req, res) => {

config/globals.js

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Globals extends EventEmitter {
1212
this.port = process.env.port || 16409;
1313
this.connected = true;
1414
this.syncing = false;
15+
this.autorun = false;
1516
}
1617

1718
updateConnectivity(isConnected) {
@@ -33,6 +34,15 @@ class Globals extends EventEmitter {
3334
this.syncing = syncing;
3435
this.emit("syncing", syncing);
3536
}
37+
38+
set autorun(val) {
39+
this._autorun = val;
40+
this.emit('updateAutorun');
41+
}
42+
43+
get autorun() {
44+
return this._autorun;
45+
}
3646
}
3747

3848
module.exports = new Globals();

main.js

+36-4
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@ const path = require("path");
55

66
const gbs = require('./config/globals');
77
const core = require('./app/core');
8+
const AutoLaunch = require('auto-launch');
9+
const os = require('os');
810

911
//Actual backend
1012
const backend = require('./app/backend');
1113

14+
const autolauncher = new AutoLaunch({name: "ODrive"});
15+
16+
autolauncher.isEnabled().then(
17+
val => gbs.autorun = val,
18+
err => console.error("Error when checking auto launch", err)
19+
)
20+
1221
const logo = path.join(__dirname, 'public', 'images', 'logo.png');
1322
const logoGrey = path.join(__dirname, 'public', 'images', 'logo-grey.png');
1423
const logoSync = path.join(__dirname, 'public', 'images', 'logo-sync.png');
1524

1625
function createWindow () {
1726
// Create the browser window.
1827
gbs.win = new BrowserWindow({
19-
width: 600,
20-
height: 250,
28+
width: 650,
29+
height: os.platform() === "win32" ? 260 : 250,
2130
icon: logo,
2231
webPreferences: {
2332
},
@@ -41,8 +50,10 @@ function createWindow () {
4150
});
4251
}
4352

44-
function generateTray() {
45-
gbs.tray = new Tray(logo);
53+
function generateTrayMenu() {
54+
if (!gbs.tray) {
55+
return;
56+
}
4657

4758
gbs.trayMenu = Menu.buildFromTemplate([
4859
{
@@ -53,6 +64,18 @@ function generateTray() {
5364
}
5465
}
5566
},
67+
{
68+
label: 'Launch on startup',
69+
click() {
70+
if (gbs.autorun) {
71+
autolauncher.disable().then(gbs.autorun = false).catch(err => console.error("Error when disabling auto launch", err));
72+
} else {
73+
autolauncher.enable().then(gbs.autorun = true).catch(err => console.error("Error when enabling auto launch", err));
74+
}
75+
},
76+
type: 'checkbox',
77+
checked: gbs.autorun
78+
},
5679
{type: 'separator'},
5780
{
5881
label: 'Quit ODrive',
@@ -62,8 +85,17 @@ function generateTray() {
6285
gbs.tray.setContextMenu(gbs.trayMenu);
6386
}
6487

88+
function generateTray() {
89+
gbs.tray = new Tray(logo);
90+
91+
generateTrayMenu();
92+
}
93+
6594
async function launch() {
6695
generateTray();
96+
97+
gbs.on("updateAutorun", generateTrayMenu);
98+
6799
await backend.launch();
68100

69101
/* Only display settings on launch if no account already set up */

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "odrive",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"description": "Simple google drive client",
55
"main": "main.js",
6-
"repository": "git@github.com:liberodark/ODrive.git",
6+
"repository": "https://github.com/liberodark/ODrive.git",
77
"author": "coyotte508 <[email protected]>",
88
"license": "GPL-3.0",
99
"dependencies": {
1010
"array-unique": "^0.3.2",
11+
"auto-launch": "^5.0.5",
1112
"body-parser": "^1.18.2",
1213
"bootstrap": "4.0.0-beta",
1314
"chokidar": "^1.7.0",
@@ -47,7 +48,7 @@
4748
"scripts": {
4849
"lint": "eslint app main.js",
4950
"test": "npm run lint",
50-
"start": "electron main",
51+
"start": "electron main",
5152
"webpack": "webpack",
5253
"postinstall": "npm run webpack && electron-builder install-app-deps",
5354
"pack": "electron-builder --dir",

0 commit comments

Comments
 (0)