forked from GetScatter/ScatterDesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron.js
More file actions
124 lines (103 loc) · 3.51 KB
/
electron.js
File metadata and controls
124 lines (103 loc) · 3.51 KB
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
const {app, BrowserWindow, Tray, Menu, MenuItem} = require('electron');
const path = require("path");
const url = require("url");
const Transport = require('@ledgerhq/hw-transport-node-hid');
global.appShared = { Transport, ApiWatcher:null };
let tray, win;
const setupMenu = () => {
const menu = new Menu();
win.setMenu(menu);
const template = [{
label: "Application",
submenu: [
{ label: "About Application", selector: "orderFrontStandardAboutPanel:" },
{ type: "separator" },
{ label: "Quit", accelerator: "Command+Q", click: () => { 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));
};
const createScatterInstance = () => {
app.setAsDefaultProtocolClient('scatter');
// Initialize the window to our specified dimensions
win = new BrowserWindow({
width: 1280,
height: 800,
frame: false,
radii: [5,5,5,5],
icon:'static/icons/icon.png',
resizable: true,
minWidth: 620,
minHeight:580
});
// 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);
win.on('close', () => app.quit());
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();
};
const activateInstance = e => {
if(e) e.preventDefault();
if(!win) return;
win.restore();
};
app.on('ready', createScatterInstance);
app.on('activate', activateInstance);
app.on('window-all-closed', () => app.quit())
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
const isLocal = url.startsWith('https://127.0.0.1');
if (isLocal) {
event.preventDefault()
callback(true)
} else {
callback(false)
}
})
const callDeepLink = url => {
if(global.appShared.ApiWatcher !== null)
global.appShared.ApiWatcher(url);
}
const shouldQuit = app.makeSingleInstance(argv => {
if (process.platform === 'win32') callDeepLink(argv.slice(1))
if (win) activateInstance();
})
if (shouldQuit) app.quit();
app.on('will-finish-launching', () => {
app.on('open-url', (e, url) => {
e.preventDefault();
callDeepLink(url)
})
});