Repository navigation
Expand file tree
/
Copy pathelectron.js
More file actions
133 lines (107 loc) · 3.54 KB
/
Copy pathelectron.js
File metadata and controls
133 lines (107 loc) · 3.54 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
123
124
125
126
127
128
129
130
131
132
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 = null;
let win = null;
const logToConsoles = (s) => {
console.log(s)
if (win && win.webContents) {
win.webContents.executeJavaScript(`console.log("${s}")`)
}
}
const setupMenu = () => {
const menu = new Menu();
// 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));
};
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:'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();
};
const activateInstance = e => {
if(e) e.preventDefault();
if(!win) return;
win.restore();
};
app.on('ready', createScatterInstance);
app.on('activate', activateInstance);
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 shouldQuit = app.makeSingleInstance(argv => {
if (process.platform === 'win32')
if(global.appShared.ApiWatcher !== null)
global.appShared.ApiWatcher(argv.slice(1));
if (win) activateInstance();
})
if (shouldQuit) app.quit();
app.on('will-finish-launching', () => {
app.on('open-url', function (event, url) {
event.preventDefault()
if(global.appShared.ApiWatcher !== null)
global.appShared.ApiWatcher(argv.slice(1));
})
});