forked from GetScatter/ScatterDesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron.js
104 lines (85 loc) · 2.7 KB
/
electron.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
const {app, BrowserWindow, Tray, Menu, MenuItem} = require('electron')
const path = require("path");
const url = require("url");
let tray = null;
let win = null;
const setupMenu = () => {
const menu = new Menu();
menu.append(new MenuItem({
label: 'Print',
accelerator: 'CmdOrCtrl+Shift+D',
click: () => { win.toggleDevTools(); }
}));
// Menu.setApplicationMenu(menu)
win.setMenu(menu);
const template = [{
label: "Application",
submenu: [
{ label: "About Application", selector: "orderFrontStandardAboutPanel:" },
{ type: "separator" },
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }}
]}, {
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:" }
]}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
};
app.on('ready', function () {
// Initialize the window to our specified dimensions
win = new BrowserWindow({
width: 1280,
height: 800,
// width: 800,
// height: 600,
frame: false,
radii: [5,5,5,5],
icon:'assets/icon.png'
});
// win.openDevTools();
let mainUrl = '';
let trayIcon = '';
if(process.mainModule.filename.indexOf('app.asar') === -1){
mainUrl = 'http://localhost:8080/';
trayIcon = 'static/icons/icon-tray.png';
} else {
mainUrl = url.format({
pathname: path.join(__dirname, "dist", "index.html"),
protocol: "file:",
slashes: true
});
trayIcon = __dirname + '/static/icons/icon-tray.png';
}
win.loadURL(mainUrl);
win.on('closed', () => {
win = null;
});
tray = new Tray(trayIcon);
const contextMenu = Menu.buildFromTemplate([
{label: 'Open', type: 'normal', click:() => {
win.show();
if(win.isMinimized()) win.restore();
}},
{label: 'Exit', type: 'normal', click:() => app.quit()}
]);
tray.setToolTip('Scatter Desktop Companion');
tray.setContextMenu(contextMenu);
setupMenu();
});
// app.on('activate', () => {
// if (win === null) {
// createWindow()
// }
// });
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});