forked from EasyScreenCast/EasyScreenCast
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutilnotify.js
119 lines (101 loc) · 3.06 KB
/
utilnotify.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
/*
Copyright (C) 2016 Borsato Ivano
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*/
const Lang = imports.lang;
const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;
const Clutter = imports.gi.Clutter;
const St = imports.gi.St;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Lib = Me.imports.convenience;
const Settings = Me.imports.settings;
/**
* @type {NotifyManager}
*/
var NotifyManager = new Lang.Class({
Name: "NotifyManager",
/**
* Create a notify manager
*/
_init: function () {
Lib.TalkativeLog("-°-init notify manager");
this.source = new MessageTray.SystemNotificationSource();
},
/**
* create notify
*
* @param msg
* @param icon
* @param sound
* @return {MessageTray.Notification}
*/
createNotify: function (msg, icon, sound) {
Lib.TalkativeLog("-°-create notify :" + msg);
var notify = new MessageTray.Notification(this.source, msg, null, {
gicon: icon,
});
notify.setTransient(false);
notify.setResident(true);
Main.messageTray.add(this.source);
this.source.showNotification(notify);
if (sound) {
notify.playSound();
}
return notify;
},
/**
* update notify
*
* @param notify
* @param msg
* @param icon
* @param sound
*/
updateNotify: function (notify, msg, icon, sound) {
Lib.TalkativeLog("-°-update notify");
notify.update(msg, null, {
gicon: icon,
});
if (sound) {
notify.playSound();
}
},
/**
* create alert
*
* @param msg
*/
createAlert: function (msg) {
Lib.TalkativeLog("-°-show alert tweener : " + msg);
if (Settings.getOption("b", Settings.SHOW_NOTIFY_ALERT_SETTING_KEY)) {
var monitor = Main.layoutManager.focusMonitor;
var text = new St.Label({
style_class: "alert-msg",
text: msg,
});
text.opacity = 255;
Main.uiGroup.add_actor(text);
text.set_position(
Math.floor(monitor.width / 2 - text.width / 2),
Math.floor(monitor.height / 2 - text.height / 2)
);
text.ease({
opacity: 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
duration: 4000,
onComplete: () => {
Main.uiGroup.remove_actor(text);
text = null;
},
});
}
},
});