-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExtensions.js
54 lines (47 loc) · 1.67 KB
/
Extensions.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
const arrConstructor = ([]).constructor;
const methods = {
callDestroyEvents(notify) {
if (notify.destroyed) {
return;
}
if (!notify.destroyEvents) {
return;
}
if (notify.destroyEvents.constructor != arrConstructor) {
return;
}
for (let i = 0; i < notify.destroyEvents.length; i++) {
const event = notify.destroyEvents[i];
if (typeof event == 'function') {
try { event(); }
catch (e) {
console.error('Execute onDestroy error:\n' + e);
}
}
}
notify.destroyed = true;
notify.destroyEvents.length = 0;
},
destroyNotify(notify, manager) {
try { methods.callDestroyEvents(notify); } catch (e) { console.error(e); }
if (manager.activeNotifications && manager.activeNotifications.constructor == arrConstructor) {
const index = manager.activeNotifications.indexOf(notify);
if (index > -1) {
manager.activeNotifications.splice(index, 1);
}
setTimeout(() => {
if (manager.activeNotifications.length == 0) {
manager.win.hide();
manager.win.webContents.session.clearCache();
}
}, 1000);
}
if (manager.onclickEvents && manager.onclickEvents.constructor == arrConstructor) {
const index = manager.onclickEvents.findIndex(x => x.id == notify.id);
if (index > -1) {
manager.onclickEvents.splice(index, 1);
}
}
}
};
module.exports = methods;