forked from BoostIO/BoostNote-Legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
247 lines (222 loc) · 5.33 KB
/
Copy pathmain.js
File metadata and controls
247 lines (222 loc) · 5.33 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
var app = require('app') // Module to control application life.
var BrowserWindow = require('browser-window') // Module to create native browser window.
// Report crashes to our server.
require('crash-reporter').start()
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null
// app.on('window-all-closed', function () {
// if (process.platform !== 'darwin') app.quit()
// })
var clipboard = require('clipboard')
var Tray = require('tray')
var notifier = require('node-notifier')
var appIcon = null
app.on('ready', function () {
appIcon = new Tray(__dirname + '/tray-icon.png')
appIcon.setToolTip('This is my application.')
appIcon.on('clicked', function () {
if (mainWindow == null) {
makeNewMainWindow()
}
mainWindow.show()
})
makeNewMainWindow()
var globalShortcut = require('global-shortcut')
var popUpWindow = new BrowserWindow({
width: 600,
height: 400,
show: false,
frame: false,
'web-preferences': {
'overlay-scrollbars': true,
'skip-taskbar': true
}
})
popUpWindow.loadUrl('file://' + __dirname + '/browser/popup/index.html')
app.on('activate-with-no-open-windows', function () {
if (mainWindow == null) {
makeNewMainWindow()
}
mainWindow.show()
})
popUpWindow.on('blur', function () {
popUpWindow.hide()
})
popUpWindow.setVisibleOnAllWorkspaces(true)
var hidePopUp = function () {
if (fromMain) {
} else {
mainWindow ? mainWindow.hide() : null
Menu.sendActionToFirstResponder('hide:')
}
popUpWindow.hide()
}
var ipc = require('ipc')
ipc.on('hidePopUp', function () {
hidePopUp()
})
ipc.on('writeCode', function (e, code) {
clipboard.writeText(code)
notifier.notify({
title: 'Write on clipboard!',
message: 'Ready to paste',
wait: false
}, function (err, res) {
})
hidePopUp()
})
var fromMain
// Register a 'ctrl+x' shortcut listener.
globalShortcut.register('ctrl+tab+shift', function () {
if (popUpWindow.isVisible()) {
hidePopUp()
return
}
fromMain = mainWindow ? mainWindow.isFocused() : false
popUpWindow.show()
})
// MENU
var Menu = require('menu')
var template = [
{
label: 'Electron',
submenu: [
{
label: 'About Electron',
selector: 'orderFrontStandardAboutPanel:'
},
{
type: 'separator'
},
{
label: 'Services',
submenu: []
},
{
type: 'separator'
},
{
label: 'Hide Electron',
accelerator: 'Command+H',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
},
{
label: 'Show All',
selector: 'unhideAllApplications:'
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
click: function () { app.quit() }
}
]
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'Command+Z',
selector: 'undo:'
},
{
label: 'Redo',
accelerator: 'Shift+Command+Z',
selector: 'redo:'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'Command+X',
selector: 'cut:'
},
{
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
},
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}
]
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function () { BrowserWindow.getFocusedWindow().reloadIgnoringCache() }
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function () { BrowserWindow.getFocusedWindow().toggleDevTools() }
}
]
},
{
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
},
{
label: 'Close',
accelerator: 'Command+W',
selector: 'performClose:'
},
{
type: 'separator'
},
{
label: 'Bring All to Front',
selector: 'arrangeInFront:'
}
]
},
{
label: 'Help',
submenu: []
}
]
var menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
function makeNewMainWindow () {
console.log('new Window!')
mainWindow = new BrowserWindow({
width: 920,
height: 640,
'web-preferences': {
'overlay-scrollbars': true
}
})
mainWindow.loadUrl('file://' + __dirname + '/browser/main/index.html')
mainWindow.on('closed', function () {
console.log('main closed')
mainWindow = null
app.dock.hide()
})
app.dock.show()
}
})