-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.js
64 lines (52 loc) · 1.9 KB
/
main.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
"use strict";
const path = require('path');
const url = require('url');
const MainWindowBuilder = require('./src/main/main_window_builder');
const appEvents = require('./src/main/app_events');
const utils = require('./src/common/utils');
const {
app
} = require('electron');
require('@electron/remote/main').initialize();
// Global reference to window
let win = null;
function initApp() {
function createWindow() {
if (win === null) {
const iconPath = path.join(__dirname, 'resources', 'icon.png');
const htmlUrl = url.format({
pathname: path.join(__dirname, 'public', 'index.html'),
protocol: 'file:'
});
win = new MainWindowBuilder()
.setIcon(iconPath)
.setIndex(htmlUrl)
.initWindow(utils.isDevEnv());
}
}
appEvents(createWindow);
}
app.disableHardwareAcceleration(); // fixes drag images freezes
app.commandLine.appendSwitch('force-color-profile', 'srgb'); // Fixes messed up color rendering
app.allowRendererProcessReuse = true; // Default from electron 9, explicitly set to remove warning
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
console.warn("An instance of Gaucho is already running");
app.quit();
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
// If command line is being executed while gaucho is running, this callback will be called
// commandLine Array of commands [ './gaucho', 'caca' ]
// in development
// Command [
// '/home/angrykoala/Git/gaucho/node_modules/electron/dist/electron',
// '.'
// ]
// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
}
});
initApp();
}