-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindicator.js
87 lines (72 loc) · 2.5 KB
/
indicator.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
import Gio from "gi://Gio";
import GObject from "gi://GObject";
import * as DBus from "./dbus.js";
import { Pihole as SingleInstance } from "./pihole.js";
import { MPihole as MultiInstance } from "./mpihole.js";
export const PiholeIndicator = GObject.registerClass(
{
GTypeName: "PiholeIndicator",
},
class PiholeIndicator extends GObject.Object {
constructor(me, settings) {
super();
this._me = me;
this._settings = settings;
this._network_monitor = Gio.NetworkMonitor.get_default();
this._pihole = null;
this._configure();
this._setHandlers();
this._start().catch(console.error);
}
_configure() {
this._hideUi = this._settings.get_boolean("hideui");
this._check_network = this._settings.get_boolean("check-network");
this._network = this._settings.get_string("network");
this._multimode = this._settings.get_boolean("multimode");
}
_setHandlers() {
this._networkHandlerId = this._network_monitor.connect(
"network-changed",
() => {
this._start().catch(console.error);
}
);
this._settingsHandlerId = this._settings.connect("changed", () => {
this._configure();
this._start().catch(console.error);
});
}
async _start() {
const Pihole = this._multimode ? MultiInstance : SingleInstance;
this._pihole?.destroy();
this._pihole = null;
if (this._network_monitor.network_available) {
if (this._check_network && this._hideUi) {
const currentNetworkId = await DBus.getNetworkIdAsync();
this._pihole =
this._network === currentNetworkId
? new Pihole(this._me, this._settings, "start")
: null;
} else if (this._check_network) {
const currentNetworkId = await DBus.getNetworkIdAsync();
this._pihole =
this._network === currentNetworkId
? new Pihole(this._me, this._settings, "start")
: new Pihole(this._me, this._settings, "unknown_network");
} else {
this._pihole = new Pihole(this._me, this._settings, "start");
}
} else {
if (!this._hideUi)
this._pihole = new Pihole(this._me, this._settings, "no_network");
}
}
destroy() {
this._settings.disconnect(this._settingsHandlerId);
this._settings = null;
this._network_monitor.disconnect(this._networkHandlerId);
this._pihole?.destroy();
this._pihole = null;
}
}
);