forked from wulkano/Kap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtray.js
78 lines (63 loc) · 1.78 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
'use strict';
const {Tray} = require('electron');
const path = require('path');
const {openCropperWindow} = require('./cropper');
const {cogMenu} = require('./menus');
const {track} = require('./common/analytics');
const openFiles = require('./utils/open-files');
let tray = null;
let trayAnimation = null;
const openContextMenu = () => {
tray.popUpContextMenu(cogMenu);
};
const initializeTray = () => {
tray = new Tray(path.join(__dirname, '..', 'static', 'menubarDefaultTemplate.png'));
tray.on('click', openCropperWindow);
tray.on('right-click', openContextMenu);
tray.on('drop-files', (_, files) => {
track('editor/opened/tray');
openFiles(...files);
});
return tray;
};
const disableTray = () => {
tray.removeListener('click', openCropperWindow);
tray.removeListener('right-click', openContextMenu);
};
const resetTray = () => {
if (trayAnimation) {
clearTimeout(trayAnimation);
}
tray.removeAllListeners('click');
tray.setImage(path.join(__dirname, '..', 'static', 'menubarDefaultTemplate.png'));
tray.on('click', openCropperWindow);
tray.on('right-click', openContextMenu);
};
const setRecordingTray = stopRecording => {
animateIcon();
tray.once('click', stopRecording);
};
const animateIcon = () => new Promise(resolve => {
const interval = 20;
let i = 0;
const next = () => {
trayAnimation = setTimeout(() => {
const number = String(i++).padStart(5, '0');
const filename = `loading_${number}Template.png`;
try {
tray.setImage(path.join(__dirname, '..', 'static', 'menubar-loading', filename));
next();
} catch (_) {
trayAnimation = null;
resolve();
}
}, interval);
};
next();
});
module.exports = {
initializeTray,
disableTray,
setRecordingTray,
resetTray
};