forked from EasyScreenCast/EasyScreenCast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilnotify.js
103 lines (85 loc) · 2.84 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
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
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 St = imports.gi.St;
const Tweener = imports.ui.tweener;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Lib = Me.imports.convenience;
const Settings = Me.imports.settings;
const NotifyManager = new Lang.Class({
Name: "NotifyManager",
/*
* Create a notify manager
*/
_init: function() {
Lib.TalkativeLog('-°-init notify manager');
this.source = new MessageTray.SystemNotificationSource();
},
/*
* create notify
*/
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.notify(notify);
if (sound) {
notify.playSound();
}
return notify;
},
/*
* update notify
*/
updateNotify: function(notify, msg, icon, sound) {
Lib.TalkativeLog('-°-update notify');
notify.update(msg, null, {
gicon: icon
});
if (sound) {
notify.playSound();
}
},
/*
* create alert
*/
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));
Tweener.addTween(text, {
opacity: 0,
time: 4,
transition: 'easeOutQuad',
onComplete: Lang.bind(this, function() {
Main.uiGroup.remove_actor(text);
text = null;
})
});
}
}
});