This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
117 lines (96 loc) · 2.14 KB
/
index.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
const {app, BrowserWindow} = require('electron')
const windowStateKeeper = require('electron-window-state');
const gotTheLock = app.requestSingleInstanceLock();
let win;
function createWindow()
{
let mainWindowState = windowStateKeeper({
defaultWidth: 1280,
defaultHeight: 800
});
// Create the window using the state information
win = new BrowserWindow({
'x': mainWindowState.x,
'y': mainWindowState.y,
'width': mainWindowState.width,
'height': mainWindowState.height,
frame: false,
webPreferences: {
spellcheck: true,
nodeIntegration: true,
enableRemoteModule: true
}
});
const {
Menu,
MenuItem
} = require('electron')
win.webContents.on('context-menu', (event, params) => {
const menu = new Menu();
if (!event.target.closest('textarea, input, [contenteditable="true"]')) return;
// Add each spelling suggestion
//console.log(params);
for (const suggestion of params.dictionarySuggestions)
{
menu.append(new MenuItem({
label: suggestion,
click: () => mainWindow.webContents.replaceMisspelling(suggestion)
}))
}
// Allow users to add the misspelled word to the dictionary
if (params.misspelledWord)
{
menu.append(
new MenuItem({
type: 'separator'
})
)
menu.append(
new MenuItem({
label: 'Add to dictionary',
click: () => win.webContents.session.addWordToSpellCheckerDictionary(params.misspelledWord)
})
)
}
menu.popup()
})
mainWindowState.manage(win);
win.loadURL(`file://${__dirname}/index.html#openModal`)
// Open the DevTools.
//win.webContents.openDevTools()
win.on('closed', () => {
win = null
})
}
if (!gotTheLock) {
app.quit()
}
else
{
app.on('second-instance', (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (myWindow)
{
if (myWindow.isMinimized())
{
myWindow.restore()
}
myWindow.focus()
}
})
// Create myWindow, load the rest of the app, etc...
app.whenReady().then(() => {
createWindow();
})
}
app.on('window-all-closed', () =>
{
app.quit()
});
app.on('activate', () =>
{
if (win === null)
{
createWindow();
}
});