-
Notifications
You must be signed in to change notification settings - Fork 1
/
noggles.js
69 lines (62 loc) · 1.47 KB
/
noggles.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
const { app, Menu, Tray } = require('electron');
const path = require('path');
const { BrowserWindow } = require('electron');
const { menubar } = require('menubar');
const { clipboard, nativeTheme } = require('electron');
const nogglesList = [
'⌐◨-◨',
'⌐◧-◧',
'⌐🄶-🄼',
'⌐❘❙❚-❘❙❚',
'⌐♥-♥',
'⌐⁞⁚⁞-⁞⁚⁞',
'⌐□-□',
'⌐🆇-🆇',
'⌐ⓝ°ⓒ',
'separator',
'⌐×-×'
];
app.on('ready', () => {
const getTrayIcon = (isDark = nativeTheme.shouldUseDarkColors) => {
return path.join(EXTRA_RESOURCES_PATH, `icon${isDark ? '-dark' : ''}.png`);
};
const EXTRA_RESOURCES_PATH = app.isPackaged
? path.join(process.resourcesPath, 'assets')
: path.join(__dirname, 'assets');
const quitApp = () => {
app.quit();
};
const copyNoggles = (text) => {
clipboard.writeText(text);
};
const menuItems = nogglesList.map((nog, i, { length }) =>
length - 2 === i
? {
type: 'separator',
}
: length - 1 === i
? {
label: '⌐×-×',
click: function () {
quitApp();
},
}
: {
label: nog,
click: function () {
copyNoggles(nog);
},
}
);
const tray = new Tray(getTrayIcon());
const contextMenu = Menu.buildFromTemplate(menuItems);
tray.setContextMenu(contextMenu);
const mb = menubar({
tray,
});
mb.on('ready', () => {
// Don't open browser window
tray.removeAllListeners();
nativeTheme.on('updated', () => mb.tray.setImage(getTrayIcon()));
});
});