-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
125 lines (95 loc) · 2.84 KB
/
main.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
118
119
120
121
122
123
124
125
const { app, BrowserWindow, ipcMain, dialog, clipboard, TouchBar, nativeImage } = require('electron')
const windowStateKeeper = require('electron-window-state')
const appMenu = require('./menu')
let mainWindow, settingsWindow
let deeplinkingUrl
// Create a new BrowserWindow when `app` is ready
function createWindow() {
let state = windowStateKeeper({
defaultWidth: 950,
defaultHeight: 650
})
mainWindow = new BrowserWindow({
x: state.x,
y: state.y,
width: state.width,
height: state.height,
minWidth: 950,
minHeight: 650,
titleBarStyle: 'hidden',
backgroundColor: '#1B1C21',
webPreferences: {
// --- !! IMPORTANT !! ---
// Disable 'contextIsolation' to allow 'nodeIntegration'
// 'contextIsolation' defaults to "true" as from Electron v12
contextIsolation: false,
nodeIntegration: true,
enableRemoteModule: false
}
})
mainWindow.loadURL(`file://${__dirname}/dist/index.html`)
state.manage(mainWindow)
//appMenu()
// Listen for window being closed
mainWindow.on('closed', () => {
mainWindow = null
})
mainWindow.on('close', e => {
app.quit()
})
settingsWindow = new BrowserWindow({
modal : true,
show : false,
parent : mainWindow,
resizable : false,
webPreferences: {
// --- !! IMPORTANT !! ---
// Disable 'contextIsolation' to allow 'nodeIntegration'
// 'contextIsolation' defaults to "true" as from Electron v12
contextIsolation: false,
nodeIntegration: true,
enableRemoteModule: false
}
})
settingsWindow.loadURL(`file://${__dirname}/dist/index.html#/settings`)
// settingsWindow.on("blur", e => {
// settingsWindow.hide()
// })
}
app.setAsDefaultProtocolClient('happy');
app.on('open-url', function (event, url) {
event.preventDefault()
deeplinkingUrl = url
console.log(deeplinkingUrl)
settingsWindow.webContents.send('on-login', deeplinkingUrl)
});
ipcMain.on("open-settings", (e, args) => {
settingsWindow.show()
})
ipcMain.on("close-settings", (e, args) => {
settingsWindow.hide()
})
// Electron `app` is ready
app.on('ready', createWindow)
// Quit when all windows are closed - (Not macOS - Darwin)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
// When app icon is clicked and app is running, (macOS) recreate the BrowserWindow
app.on('activate', () => {
if (mainWindow === null) createWindow()
})
app.on('before-quit', e => {
mainWindow.webContents.send("application_will_quit")
})
// Open a file picker and return image result in base 64
ipcMain.on("open-file-picker", (e, options) => {
dialog.showOpenDialog(options).then(result => {
if (!result.canceled) {
e.sender.send("open-file-picker-result", result.filePaths)
}
})
})
ipcMain.on("add-clipboard", (e, args) => {
clipboard.writeText(args)
})