-
Notifications
You must be signed in to change notification settings - Fork 1
/
notifications.js
60 lines (51 loc) · 1.8 KB
/
notifications.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
/*
* Zilence extension for Gnome Shell.
* Copyright 2021-2024 Andrzej Pańkowski
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import Gio from "gi://Gio"
export const Notifications = class {
constructor() {
this.settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.notifications' })
this.settingChangedSignal = null
}
areEnabled() {
return this.settings.get_boolean('show-banners')
}
enable() {
this.settings.set_boolean('show-banners', true)
}
disable() {
this.settings.set_boolean('show-banners', false)
}
enableChangeTracking(callback) {
this.disableChangeTracking()
this.settingChangedSignal = this.settings.connect('changed::show-banners', () => callback())
// GSettings require reading the setting to receive its corresponding 'changed' signal
this.areEnabled()
}
disableChangeTracking() {
if (this.settingChangedSignal) {
this.settings.disconnect(this.settingChangedSignal)
this.settingChangedSignal = null
}
}
dispose() {
this.disableChangeTracking()
this.settings = null
}
}