This repository has been archived by the owner on May 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
94 lines (75 loc) · 2.24 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const electron = require('electron');
const config = require('./config.json');
const appMenu = require('./includes/menu');
const path = require('path');
const url = require('url');
const windowStateKeeper = require('electron-window-state');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const Tray = electron.Tray;
const iconPath = path.join(__dirname, config.icon);
let mainWindow;
let appIcon;
function createWindow() {
/* Set default window dimensions */
let mainWindowState = windowStateKeeper({
defaultWidth: config.width,
defaultHeight: config.height
});
/* Create main window */
mainWindow = new BrowserWindow({
width: mainWindowState.width,
height: mainWindowState.height,
x: mainWindowState.x,
y: mainWindowState.y,
icon: iconPath
});
/* Set globals to use on Modules */
global.ModuleElectron = electron;
global.ModuleWindow = mainWindow;
global.ModuleIconPath = iconPath;
/* Load URL */
//mainWindow.loadURL(config.url); // DISABLED FOR NOW ...
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
/* Show menubar */
mainWindow.setMenu(appMenu.getMenuBar());
/* Show tray icon */
appIcon = new Tray(iconPath);
appIcon.setToolTip('CodeAnywhere Desktop');
appIcon.setContextMenu(appMenu.getTrayMenu());
/* Remember window state */
mainWindowState.manage(mainWindow);
// Open the DevTools.
// mainWindow.webContents.openDevTools()
mainWindow.on('closed', function () {
mainWindow = null
});
/* Minimize to tray */
mainWindow.on('minimize', function (event) {
event.preventDefault();
mainWindow.hide();
});
/* Close to tray */
mainWindow.on('close', function (event) {
if (!app.isQuiting) {
event.preventDefault();
mainWindow.hide();
}
return false;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
});