-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (27 loc) · 849 Bytes
/
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
const { app, BrowserWindow, Tray } = require('electron');
const path = require('path');
const fs = require('fs');
const electronPositioner = require('electron-positioner')
module.exports = async (config, icon, mode, showIcon) => {
await app.whenReady()
if(!icon) icon = path.join(__dirname, 'icon.png')
if(!config) config = {}
if(!config.frame && mode != 'detach') config.frame = false
const window = new BrowserWindow(config)
const tray = new Tray(fs.realpathSync(icon))
const positioner = new electronPositioner(window)
if(!showIcon){
window.hide()
window.setSkipTaskbar(true)
app.dock.hide()
}
tray.on('click', () => {
window.isVisible() ? window.hide() : window.show()
})
if(mode != 'detach') {
positioner.move(process.platform == 'darwin' ? 'topCenter' : 'trayBottomCenter', tray.getBounds())
}
return {
window, tray, app, positioner
}
}