This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathelectron.js
100 lines (86 loc) · 2.37 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
// Dependencies
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const Menu = electron.Menu;
const path = require('path');
const isDev = require('electron-is-dev');
var mainWindow;
// Create the Main window that loads the web app.
function createWindow() {
var menu;
mainWindow = new BrowserWindow({width: 1280, height: 768, minWidth: 1024, minHeight: 768, frame: true});
mainWindow.loadURL(isDev
? 'http://localhost:8082'
: `file://${path.join(__dirname, '/index.html')}`);
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows in an array if
// your app supports multi windows, this is the time when you should delete the
// corresponding element.
mainWindow = null;
// Quit the app when main window is closed
app.quit();
});
// Show window when it first loads.
mainWindow
.webContents
.once('did-finish-load', () => {
mainWindow.show();
// Open developer tools.
if (isDev) {
mainWindow
.webContents
.openDevTools();
}
});
// This is implmented to fix the copy paste issue in electron app for mac
// reference: https://pracucci.com/atom-electron-enable-copy-and-paste.html
menu = Menu.buildFromTemplate([
{
label: 'Application',
submenu: [
{
label: 'Quit',
accelerator: 'Command+Q',
click: function () {
app.quit();
}
}
]
}, {
label: 'Edit',
submenu: [
{
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);
}
// This method will be called when Electron has finished initialization and is
// ready to create browser windows. Some APIs can only be used after this event
// occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => {
app.quit();
});
app.on('activate', () => {
// TODO: Recreate or show?
if (mainWindow === null) {
createWindow();
} else {
mainWindow.show();
}
});