forked from klaudiosinani/tusk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtray.js
145 lines (137 loc) Β· 2.87 KB
/
tray.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict';
const path = require('path');
const electron = require('electron');
const config = require('./config');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const shell = electron.shell;
let tray = null;
const settingsURL = 'https://www.evernote.com/Settings.action';
const issueURL = 'https://github.com/klauscfhq/tusk/issues/new';
function activate(command) {
const appWindow = BrowserWindow.getAllWindows()[0];
// Extra measure in order to be shown
appWindow.show();
appWindow.webContents.send(command);
}
exports.create = win => {
if (process.platform === 'darwin' || tray) {
return;
}
const iconPath = path.join(__dirname, 'static/IconTray.png');
const toggleWin = () => {
// Toggle/untoggle window
if (win.isVisible()) {
win.hide();
} else {
win.show();
}
};
const showWin = () => {
// Bring window on top if not visible
if (!win.isVisible()) {
win.show();
}
};
const contextMenu = electron.Menu.buildFromTemplate([{
label: 'Open Tusk',
click() {
toggleWin();
}
}, {
type: 'separator'
}, {
label: 'Search',
click() {
showWin();
activate('search');
}
}, {
type: 'separator'
}, {
label: 'Create',
submenu: [{
label: 'New Tag',
click() {
showWin();
activate('new-tag');
}
}, {
label: 'New Note',
click() {
showWin();
activate('new-note');
}
}, {
label: 'New Notebook',
click() {
showWin();
activate('new-notebook');
}
}]
}, {
type: 'separator'
}, {
label: 'Toggle Theme',
submenu: [{
label: 'Sepia Theme',
click() {
showWin();
activate('toggle-sepia-mode');
}
}, {
label: 'Dark Theme',
click() {
showWin();
activate('toggle-dark-mode');
}
}, {
label: 'Black Theme',
click() {
showWin();
activate('toggle-black-mode');
}
}]
}, {
label: 'Auto Night Mode',
type: 'checkbox',
checked: config.get('autoNightMode'),
click(item) {
showWin();
config.set('autoNightMode', item.checked);
activate('auto-night-mode');
}
}, {
type: 'separator'
}, {
label: 'Hide Tray Icon',
type: 'checkbox',
checked: config.get('hideTray'),
click(item) {
showWin();
config.set('hideTray', item.checked);
app.relaunch();
app.quit();
}
}, {
type: 'separator'
}, {
label: `Settings`,
click() {
shell.openExternal(settingsURL);
}
}, {
label: `Report Issue`,
click() {
shell.openExternal(issueURL);
}
}, {
type: 'separator'
}, {
role: 'quit'
}]);
tray = new electron.Tray(iconPath);
tray.setToolTip(`${app.getName()}`);
tray.setContextMenu(contextMenu);
tray.on('click', toggleWin);
};