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
|
// SPDX-FileCopyrightText: 2023 Deminder <tremminder@gmail.com>
// SPDX-License-Identifier: GPL-3.0-or-later
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import { loadInterfaceXML, logDebug } from '../modules/util.js';
import { Timer } from './timer.js';
export const ShutdownTimerName = 'org.gnome.Shell.Extensions.ShutdownTimer';
export const ShutdownTimerObjectPath =
'/org/gnome/Shell/Extensions/ShutdownTimer';
export const ShutdownTimerIface = await loadInterfaceXML(ShutdownTimerName);
export class ShutdownTimerDBus {
constructor({ settings }) {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(
ShutdownTimerIface,
this
);
this._dbusImpl.export(Gio.DBus.session, ShutdownTimerObjectPath);
this._timer = new Timer({ settings });
this._timer.connect('message', (_, msg) => {
logDebug('[shutdown-timer-dbus] msg', msg);
this._dbusImpl.emit_signal('OnMessage', new GLib.Variant('(s)', [msg]));
});
this._timer.connect('change', () => {
logDebug('[shutdown-timer-dbus] state', this._timer.state);
this._dbusImpl.emit_signal(
'OnStateChange',
new GLib.Variant('(s)', [this._timer.state])
);
});
this._timer.connect('change-external', () => {
this._dbusImpl.emit_signal('OnExternalChange', null);
});
}
async ScheduleShutdownAsync(parameters, invocation) {
const [shutdown, action] = parameters;
logDebug(
'[sdt-dbus] [ScheduleShutdownAsync] shutdown',
shutdown,
'action',
action
);
await this._timer.toggleShutdown(shutdown, action);
invocation.return_value(null);
}
async ScheduleWakeAsync(parameters, invocation) {
const [wake] = parameters;
logDebug('[sdt-dbus] [ScheduleWakeAsync] wake', wake);
await this._timer.toggleWake(wake);
invocation.return_value(null);
}
GetStateAsync(_, invocation) {
logDebug('[sdt-dbus] [GetStateAsync]');
invocation.return_value(new GLib.Variant('(s)', [this._timer.state]));
return Promise.resolve();
}
destroy() {
logDebug('[sdt-dbus] destroy');
this._dbusImpl.unexport();
this._dbusImpl = null;
this._timer.destroy();
this._timer = null;
}
}
|