dbusServices: Port to ESM

We want to replace gjs' custom (and now legacy) imports system
with standard EcmaScript modules: JS developers are already
familiar with them, they have better tooling support and using
standard features over non-standard ones is generally the right
thing to do.

Our D-Bus services are separate from the main process, and thus
can be ported separately (except for the few imports that are
shared with the main process' code base).

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2786>
This commit is contained in:
Florian Müllner
2023-05-25 20:31:22 +02:00
parent eacabbf443
commit 612e04165e
13 changed files with 70 additions and 70 deletions

View File

@ -1,14 +1,13 @@
/* exported DBusService, ServiceImplementation */
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
const { Gio, GLib } = imports.gi;
import {programArgs} from 'system';
const Signals = imports.signals;
const IDLE_SHUTDOWN_TIME = 2; // s
const { programArgs } = imports.system;
var ServiceImplementation = class {
export class ServiceImplementation {
constructor(info, objectPath) {
this._objectPath = objectPath;
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(info, this);
@ -150,10 +149,10 @@ var ServiceImplementation = class {
that._queueShutdownCheck();
};
}
};
}
Signals.addSignalMethods(ServiceImplementation.prototype);
var DBusService = class {
export class DBusService {
constructor(name, service) {
this._name = name;
this._service = service;
@ -162,7 +161,7 @@ var DBusService = class {
this._service.connect('shutdown', () => this._loop.quit());
}
run() {
async runAsync() {
// Bail out when not running under gnome-shell
Gio.DBus.watch_name(Gio.BusType.SESSION,
'org.gnome.Shell',
@ -183,6 +182,6 @@ var DBusService = class {
null,
() => this._loop.quit());
this._loop.run();
await this._loop.runAsync();
}
};
}