2020-12-04 19:40:13 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2023-05-25 18:31:22 +00:00
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import GLib from 'gi://GLib';
|
2020-12-04 19:40:13 +00:00
|
|
|
|
2023-05-25 18:31:22 +00:00
|
|
|
import {ServiceImplementation} from './dbusService.js';
|
2020-12-04 19:40:13 +00:00
|
|
|
|
2023-05-25 18:31:22 +00:00
|
|
|
const {loadInterfaceXML} = imports.misc.dbusUtils;
|
2020-12-04 19:40:13 +00:00
|
|
|
|
|
|
|
const ScreenSaverIface = loadInterfaceXML('org.gnome.ScreenSaver');
|
|
|
|
const ScreenSaverProxy = Gio.DBusProxy.makeProxyWrapper(ScreenSaverIface);
|
|
|
|
|
2023-05-25 18:31:22 +00:00
|
|
|
export const ScreenSaverService = class extends ServiceImplementation {
|
2020-12-04 19:40:13 +00:00
|
|
|
constructor() {
|
|
|
|
super(ScreenSaverIface, '/org/gnome/ScreenSaver');
|
|
|
|
|
2021-04-27 19:07:05 +00:00
|
|
|
this._autoShutdown = false;
|
|
|
|
|
2020-12-04 19:40:13 +00:00
|
|
|
this._proxy = new ScreenSaverProxy(Gio.DBus.session,
|
|
|
|
'org.gnome.Shell.ScreenShield',
|
|
|
|
'/org/gnome/ScreenSaver',
|
|
|
|
(proxy, error) => {
|
|
|
|
if (error)
|
|
|
|
log(error.message);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._proxy.connectSignal('ActiveChanged',
|
|
|
|
(proxy, sender, params) => {
|
|
|
|
this._dbusImpl.emit_signal('ActiveChanged',
|
|
|
|
new GLib.Variant('(b)', params));
|
|
|
|
});
|
|
|
|
this._proxy.connectSignal('WakeUpScreen',
|
|
|
|
() => this._dbusImpl.emit_signal('WakeUpScreen', null));
|
|
|
|
}
|
|
|
|
|
2022-06-23 12:53:29 +00:00
|
|
|
async LockAsync(params, invocation) {
|
|
|
|
try {
|
|
|
|
await this._proxy.LockAsync(...params);
|
2020-12-04 19:40:13 +00:00
|
|
|
invocation.return_value(null);
|
2022-06-23 12:53:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
this._handleError(invocation, error);
|
|
|
|
}
|
2020-12-04 19:40:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 12:53:29 +00:00
|
|
|
async GetActiveAsync(params, invocation) {
|
|
|
|
try {
|
|
|
|
const res = await this._proxy.GetActiveAsync(...params);
|
2020-12-04 19:40:13 +00:00
|
|
|
invocation.return_value(new GLib.Variant('(b)', res));
|
2022-06-23 12:53:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
this._handleError(invocation, error);
|
|
|
|
}
|
2020-12-04 19:40:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 12:53:29 +00:00
|
|
|
async SetActiveAsync(params, invocation) {
|
|
|
|
try {
|
|
|
|
await this._proxy.SetActiveAsync(...params);
|
2020-12-04 19:40:13 +00:00
|
|
|
invocation.return_value(null);
|
2022-06-23 12:53:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
this._handleError(invocation, error);
|
|
|
|
}
|
2020-12-04 19:40:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 12:53:29 +00:00
|
|
|
async GetActiveTimeAsync(params, invocation) {
|
|
|
|
try {
|
|
|
|
const res = await this._proxy.GetActiveTimeAsync(...params);
|
2020-12-04 19:40:13 +00:00
|
|
|
invocation.return_value(new GLib.Variant('(u)', res));
|
2022-06-23 12:53:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
this._handleError(invocation, error);
|
|
|
|
}
|
2020-12-04 19:40:13 +00:00
|
|
|
}
|
|
|
|
};
|