-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
77 lines (65 loc) · 1.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
const path = require('path');
const yargs = require('yargs');
const app = require('electron').app;
const App = require('./app');
/**
* Describe command-line options.
*
* @returns {Object} options
*/
function getOptions() {
const options = yargs(process.argv.slice(1))
.usage('Usage: $0 <command> [options]')
.option('dev', {
alias : 'd',
boolean : true,
describe : 'Run in development mode (show dev tools on start)',
})
.option('tray', {
alias : 't',
boolean : true,
describe : 'Hide to tray on start',
})
.option('config-dir', {
alias : 'configDir',
describe : 'Override the path to the Laverna configuration directory',
example : '--config-dir /home/user/.config/laverna-notes',
})
.help()
.version(app.getVersion());
return options.argv;
}
/**
* Override the path to the Laverna configuration directory.
*
* @param {Object} options
*/
function setupConfigDir(options) {
const dir = options.dev ? 'laverna-dev' : 'laverna';
let configDir = path.join(app.getPath('appData'), dir);
if (options.configDir) {
configDir = options.configDir;
}
app.setPath('userData', path.normalize(configDir));
}
/**
* Start the application.
*/
function start() {
const options = getOptions();
setupConfigDir(options);
// Allow only one instance of the app
if (!options.dev) {
const shouldQuit = app.makeSingleInstance(() => global.application.focus());
if (shouldQuit) {
app.quit();
}
}
app.on('ready', () => {
global.application = new App(options);
global.application.start();
});
}
start();
module.exports = {getOptions, setupConfigDir, start};