Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
terkelg
GitHub Repository: terkelg/ramme
Path: blob/master/app/src/main/tray.js
106 views
1
const path = require('path')
2
const {
3
app,
4
dialog,
5
shell,
6
Tray,
7
Menu
8
} = require('electron')
9
10
const isPlatform = require('./../common/is-platform')
11
12
let tray = null
13
14
/**
15
* Create a tray for Windows and Linux users
16
* @param win { BrowserWindow } - window instance
17
* @returns tray
18
*/
19
exports.createTray = win => {
20
if (isPlatform('macOS') || tray) {
21
return
22
}
23
24
let iconName = null
25
// Set tray icon
26
if (isPlatform('windows')) {
27
iconName = 'icon.ico'
28
} else {
29
iconName = 'icon-18x18.png'
30
}
31
32
const iconPath = path.join(__dirname, '../assets/' + iconName)
33
const toggleWin = () => {
34
if (isPlatform('windows')) {
35
win.isMinimized() ? win.restore() : win.isVisible() ? win.hide() : win.show()
36
} else {
37
win.isVisible() ? win.hide() : win.show()
38
}
39
}
40
41
// Create tray
42
tray = new Tray(iconPath)
43
44
const contextMenu = [{
45
label: 'Toggle',
46
click () {
47
toggleWin()
48
}
49
},
50
{
51
label: 'Clear cache',
52
click () {
53
win.webContents.session.clearCache(() => {
54
dialog.showMessageBox({
55
message: 'Cache cleared correctly!'
56
})
57
})
58
}
59
},
60
{
61
label: 'Logout',
62
click () {
63
win.webContents.session.clearStorageData(() => {
64
win.webContents.loadURL('https://www.instagram.com/')
65
dialog.showMessageBox({
66
message: 'Logged out successfully!'
67
})
68
})
69
}
70
},
71
{
72
type: 'separator'
73
},
74
{
75
label: 'GitHub',
76
click () {
77
shell.openExternal('https://github.com/terkelg/ramme')
78
}
79
},
80
{
81
label: 'Issue',
82
click () {
83
shell.openExternal('https://github.com/terkelg/ramme/issues')
84
}
85
},
86
{
87
type: 'separator'
88
},
89
{
90
label: 'Quit',
91
click () {
92
app.quit()
93
}
94
}
95
]
96
97
tray.setToolTip(`${app.getName()}`)
98
tray.setContextMenu(Menu.buildFromTemplate(contextMenu))
99
tray.on('click', () => {
100
toggleWin()
101
})
102
103
// return tray
104
}
105
106