/
finder-window.js
93 lines (79 loc) · 2 KB
/
finder-window.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
const electron = require('electron')
const { app } = electron
const BrowserWindow = electron.BrowserWindow
const Menu = electron.Menu
const MenuItem = electron.MenuItem
const Tray = electron.Tray
const path = require('path')
var config = {
width: 840,
height: 540,
show: false,
frame: false,
resizable: false,
zoomFactor: 1.0,
webPreferences: {
blinkFeatures: 'OverlayScrollbars'
},
skipTaskbar: true,
standardWindow: false
}
if (process.platform === 'darwin') {
config['always-on-top'] = true
}
var finderWindow = new BrowserWindow(config)
var url = path.resolve(__dirname, './finder.html')
finderWindow.loadURL('file://' + url)
finderWindow.setSkipTaskbar(true)
if (process.platform === 'darwin') {
finderWindow.setVisibleOnAllWorkspaces(true)
}
finderWindow.on('blur', function () {
hideFinder()
})
finderWindow.on('close', function (e) {
e.preventDefault()
finderWindow.hide()
})
var appIcon = new Tray(path.join(__dirname, '../resources/tray-icon.png'))
appIcon.setToolTip('Boostnote')
var trayMenu = new Menu()
trayMenu.append(new MenuItem({
label: 'Open Main window',
click: function () {
finderWindow.webContents.send('open-main-from-tray')
}
}))
if (process.env.platform !== 'linux' || process.env.DESKTOP_SESSION === 'cinnamon') {
trayMenu.append(new MenuItem({
label: 'Open Finder window',
click: function () {
finderWindow.webContents.send('open-finder-from-tray')
}
}))
}
trayMenu.append(new MenuItem({
label: 'Quit',
click: function () {
finderWindow.webContents.send('quit-from-tray')
}
}))
appIcon.setContextMenu(trayMenu)
appIcon.on('click', function (e) {
e.preventDefault()
appIcon.popUpContextMenu(trayMenu)
})
function hideFinder () {
if (process.platform === 'win32') {
finderWindow.minimize()
return
}
if (process.platform === 'darwin') {
Menu.sendActionToFirstResponder('hide:')
}
finderWindow.hide()
}
app.on('before-quit', function (e) {
finderWindow.removeAllListeners()
})
module.exports = finderWindow