-
Notifications
You must be signed in to change notification settings - Fork 7
/
utilnotify.js
150 lines (129 loc) · 4.49 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
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.
*/
/*
This file has been copied from EasyScreenCast/utilnotify.js [1], with minimal
edits, primary deletions. Edits include removal of settings.
[1]: https://github.com/EasyScreenCast/EasyScreenCast/blob/3922633/utilnotify.js
*/
'use strict';
import GObject from 'gi://GObject';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/messageTray.js
import * as MessageTray from 'resource:///org/gnome/shell/ui/messageTray.js';
import St from 'gi://St';
import * as Lib from './convenience.js';
import {gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
/**
* @type {NotifyManager}
*/
export const NotifyManager = GObject.registerClass({
GTypeName: 'ForceQuit_NotifyManager',
}, class NotifyManager extends GObject.Object {
/**
* Create a notify manager
*/
constructor() {
super();
Lib.TalkativeLog('-°-init notify manager');
this._alertWidget = null;
}
/**
* create notify
*
* @param {string} msg the title
* @param {Gio.FileIcon} icon the icon
* @param {boolean} sound whether to play a sound
* @returns {MessageTray.Notification}
*/
createNotify(msg, icon, sound) {
Lib.TalkativeLog(`-°-create notify :${msg}`);
var source = new MessageTray.Source({
title: _('ForceQuit'),
});
var notify = new MessageTray.Notification({
source,
title: msg,
body: null,
gicon: icon,
isTransient: false,
resident: true,
});
Main.messageTray.add(source);
source.addNotification(notify);
if (sound)
notify.playSound();
return notify;
}
/**
* update notify
*
* @param {MessageTray.Notification} notify the already existing notification to update
* @param {string} msg the title
* @param {Gio.FileIcon} icon the icon
* @param {boolean} sound whether to play a sound
*/
updateNotify(notify, msg, icon, sound) {
Lib.TalkativeLog('-°-update notify');
notify.set({
title: msg,
body: null,
gicon: icon,
});
if (sound)
notify.playSound();
}
/**
* create alert
*
* @param {string} msg the message
*/
createAlert(msg) {
Lib.TalkativeLog(`-°-show alert tweener : ${msg}`);
if (true) {
var monitor = Main.layoutManager.focusMonitor;
this.resetAlert();
this._alertWidget = new St.Label({
style_class: 'alert-msg',
opacity: 255,
text: msg,
});
Main.uiGroup.add_child(this._alertWidget);
this._alertWidget.set_position(
Math.floor(monitor.width / 2 - this._alertWidget.width / 2),
Math.floor(monitor.height / 2 - this._alertWidget.height / 2)
);
Lib.TalkativeLog(`-°-show alert tweener : opacity=${this._alertWidget.opacity}`);
// see org/gnome/shell/ui/environment.js#_easeActor
// TODO: for some reason, no transition is created, so the onComplete
// callback is called _immediately_
/*
import Clutter from 'gi://Clutter';
this._alertWidget.ease({
opacity: 0,
duration: 400,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
Lib.TalkativeLog(`-°-show alert tweener completed: opacity=${this._alertWidget.opacity}`);
Main.uiGroup.remove_child(this._alertWidget);
this._alertWidget = null;
},
});
*/
}
}
resetAlert() {
if (this._alertWidget !== null) {
this._alertWidget.hide();
Main.uiGroup.remove_child(this._alertWidget);
this._alertWidget = null;
}
}
});