-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.js
165 lines (165 loc) · 5.25 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Libraries used in the app
var app = require('electron').app;
var BrowserWindow = require('electron').BrowserWindow;
var appMenu = require('electron').Menu;
var appTray = require('electron').Tray;
var path = require('path');
const {
crashReporter
} = require('electron');
app.commandLine.appendSwitch('ignore-certificate-errors', 'true');
// Crash Reporter (Optional)
crashReporter.start({
productName: 'APEX Plugins',
companyName: 'Daniel Hochleitner',
submitURL: 'https://github.com/Dani3lSun/apex-app-desktop/issues',
autoSubmit: false
});
// Init mainWindow and Tray
var mainWindow = null;
var appIcon = null;
// Kill the app when all windows are closed
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
// App is loaded
app.on('ready', function() {
// Tray icon
// template
var trayTemplate = [{
label: "About Application",
selector: "orderFrontStandardAboutPanel:"
}, {
label: "Quit",
click: function() {
app.quit();
}
}];
// set tray icon with context menu
appIcon = new appTray(path.join(__dirname, 'img/tray.png'));
appIcon.setContextMenu(appMenu.buildFromTemplate(trayTemplate));
// Create the main window for the app
mainWindow = new BrowserWindow({
"width": 1280, // init width
"height": 800, // init height
"minWidth": 1024,
"minHeight": 800,
"resizable": true,
"useContentSize": true,
//"transparent": true, // better look in OSX
"titleBarStyle": "hidden-inset", // better look in OSX
"icon": path.join(__dirname, 'img/tray.png') // app icon (for linux build)
});
// Load in content with webview to APEX app
mainWindow.loadURL('file://' + __dirname + '/index.html');
// Ensure that garbage collection occurs when the window is closed
mainWindow.on('closed', function(e) {
mainWindow = null;
});
// Create the Application main menu (required for Copy&Paste Support)
// Application menu
var menuTemplate = [{
label: "Application",
submenu: [{
label: "About Application",
selector: "orderFrontStandardAboutPanel:"
}, {
type: "separator"
}, {
label: "Quit",
accelerator: "Command+Q",
click: function() {
app.quit();
}
}]
// Edit menu
}, {
label: "Edit",
submenu: [{
label: "Undo",
accelerator: "CmdOrCtrl+Z",
selector: "undo:"
}, {
label: "Redo",
accelerator: "Shift+CmdOrCtrl+Z",
selector: "redo:"
}, {
type: "separator"
}, {
label: "Cut",
accelerator: "CmdOrCtrl+X",
selector: "cut:"
}, {
label: "Copy",
accelerator: "CmdOrCtrl+C",
selector: "copy:"
}, {
label: "Paste",
accelerator: "CmdOrCtrl+V",
selector: "paste:"
}, {
label: "Select All",
accelerator: "CmdOrCtrl+A",
selector: "selectAll:"
}]
}, {
// View menu
label: 'View',
submenu: [{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click: function(item, focusedWindow) {
if (focusedWindow)
focusedWindow.reload();
}
}, {
label: 'Toggle Full Screen',
accelerator: (function() {
if (process.platform == 'darwin')
return 'Ctrl+Command+F';
else
return 'F11';
})(),
click: function(item, focusedWindow) {
if (focusedWindow)
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
}
}, {
label: 'Toggle Developer Tools',
accelerator: (function() {
if (process.platform == 'darwin')
return 'Alt+Command+I';
else
return 'Ctrl+Shift+I';
})(),
click: function(item, focusedWindow) {
if (focusedWindow)
focusedWindow.toggleDevTools();
}
}]
}];
// set menu with options from above
appMenu.setApplicationMenu(appMenu.buildFromTemplate(menuTemplate));
});
// Create the main window for the app when App is reopened from OSX Dock
app.on('activate', function(e, hasVisibleWindows) {
if (mainWindow === null) {
mainWindow = new BrowserWindow({
"width": 1280, //init width
"height": 800, // init height
"minWidth": 1024,
"minHeight": 800,
"resizable": true,
"useContentSize": true,
"transparent": true, // better look in OSX
"titleBarStyle": "hidden-inset", // better look in OSX
"icon": path.join(__dirname, 'img/tray.png') // app icon (for linux build)
});
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.on('closed', function() {
mainWindow = null;
});
}
});