Skip to content

Commit cecaacd

Browse files
committed
extension/service: use AppLaunchContext again
1 parent d008ce2 commit cecaacd

File tree

3 files changed

+44
-40
lines changed

3 files changed

+44
-40
lines changed

ddterm/shell/extension.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ class EnabledExtension {
237237
)
238238
));
239239

240+
const app_info = install(this.extension, rollback);
241+
240242
this.notifications = new Notifications({
241243
icon: this.symbolic_icon,
242244
gettext_domain: this.extension,
@@ -249,7 +251,7 @@ class EnabledExtension {
249251
this.service = new Service({
250252
bus: Gio.DBus.session,
251253
bus_name: APP_ID,
252-
executable: this.extension.launcher_path,
254+
app_info,
253255
subprocess: this.extension.app_process,
254256
});
255257

@@ -405,8 +407,6 @@ class EnabledExtension {
405407
this.extension,
406408
rollback
407409
);
408-
409-
install(this.extension, rollback);
410410
}
411411

412412
#set_skip_taskbar() {

ddterm/shell/service.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

5+
import GLib from 'gi://GLib';
56
import GObject from 'gi://GObject';
67
import Gio from 'gi://Gio';
78

@@ -24,12 +25,12 @@ export const Service = GObject.registerClass({
2425
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
2526
null
2627
),
27-
'executable': GObject.ParamSpec.string(
28-
'executable',
28+
'app-info': GObject.ParamSpec.object(
29+
'app-info',
2930
null,
3031
null,
3132
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
32-
null
33+
Gio.AppInfo
3334
),
3435
'wayland': GObject.ParamSpec.boolean(
3536
'wayland',
@@ -118,8 +119,8 @@ export const Service = GObject.registerClass({
118119
this.bus,
119120
this.bus_name,
120121
Gio.BusNameWatcherFlags.NONE,
121-
(connection, name, owner) => this.#update_bus_name_owner(owner),
122-
() => this.#update_bus_name_owner(null)
122+
(connection, name, owner) => this.#update_bus_name_owner(name, owner),
123+
(connection, name) => this.#update_bus_name_owner(name, null)
123124
);
124125
}
125126

@@ -169,23 +170,39 @@ export const Service = GObject.registerClass({
169170
}
170171

171172
#create_subprocess() {
172-
const argv = [
173-
this.executable,
173+
const [, argv] = GLib.shell_parse_argv(this.app_info.get_commandline());
174+
175+
argv.push(
174176
'--gapplication-service',
175177
this.wayland ? '--allowed-gdk-backends=wayland' : '--allowed-gdk-backends=x11',
176-
...this.extra_argv,
177-
];
178+
...this.extra_argv
179+
);
180+
181+
const launch_context = global.create_app_launch_context(0, -1);
182+
183+
for (const extra_env of this.extra_env) {
184+
const split_pos = extra_env.indexOf('=');
185+
const name = extra_env.slice(0, split_pos);
186+
const value = extra_env.slice(split_pos + 1);
187+
188+
launch_context.setenv(name, value);
189+
}
178190

179191
const params = {
180192
journal_identifier: this.bus_name,
181193
argv,
182-
environ: this.extra_env,
194+
environ: launch_context.get_environment(),
183195
};
184196

185-
if (this.wayland)
186-
return new WaylandSubprocess(params);
187-
else
188-
return new Subprocess(params);
197+
launch_context.emit('launch-started', this.app_info, null);
198+
199+
const proc = this.wayland ? new WaylandSubprocess(params) : new Subprocess(params);
200+
201+
const platform_data = GLib.VariantDict.new(null);
202+
platform_data.insert_value('pid', GLib.Variant.new_int32(proc.get_pid()));
203+
launch_context.emit('launched', this.app_info, platform_data.end());
204+
205+
return proc;
189206
}
190207

191208
async #wait_subprocess(cancellable) {
@@ -202,13 +219,13 @@ export const Service = GObject.registerClass({
202219
}
203220
}
204221

205-
#update_bus_name_owner(owner) {
222+
#update_bus_name_owner(name, owner) {
206223
if (this.#bus_name_owner === owner)
207224
return;
208225

209226
const prev_registered = this.is_registered;
210227

211-
log(`${this.bus_name}: name owner changed to ${JSON.stringify(owner)}`);
228+
log(`${name}: name owner changed to ${JSON.stringify(owner)}`);
212229

213230
this.#bus_name_owner = owner;
214231
this.notify('bus-name-owner');

ddterm/shell/subprocess.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import GLib from 'gi://GLib';
66
import GObject from 'gi://GObject';
77
import Gio from 'gi://Gio';
8-
import GnomeDesktop from 'gi://GnomeDesktop';
98
import Meta from 'gi://Meta';
109

1110
import Gi from 'gi';
@@ -201,15 +200,9 @@ export const Subprocess = GObject.registerClass({
201200
? make_subprocess_launcher_journald(this.journal_identifier)
202201
: make_subprocess_launcher_fallback();
203202

204-
for (const extra_env of this.environ) {
205-
const split_pos = extra_env.indexOf('=');
206-
const name = extra_env.slice(0, split_pos);
207-
const value = extra_env.slice(split_pos + 1);
208-
209-
subprocess_launcher.setenv(name, value, true);
210-
}
211-
212203
try {
204+
subprocess_launcher.set_environ(this.environ);
205+
213206
this._subprocess = this._spawn(subprocess_launcher);
214207
} finally {
215208
subprocess_launcher.close();
@@ -220,18 +213,6 @@ export const Subprocess = GObject.registerClass({
220213
this._get_logs = logging_to_journald
221214
? collect_journald_logs.bind(globalThis, journalctl, start_date, pid)
222215
: collect_stdio_logs(this._subprocess.get_stdout_pipe()).catch(logError);
223-
224-
if (!pid)
225-
return;
226-
227-
GnomeDesktop.start_systemd_scope(
228-
this.journal_identifier,
229-
parseInt(pid, 10),
230-
null,
231-
null,
232-
null,
233-
null
234-
);
235216
}
236217

237218
get g_subprocess() {
@@ -265,6 +246,12 @@ export const Subprocess = GObject.registerClass({
265246
this.g_subprocess.send_signal(SIGTERM);
266247
}
267248

249+
get_pid() {
250+
const pid = this.g_subprocess.get_identifier();
251+
252+
return pid ? parseInt(pid, 10) : null;
253+
}
254+
268255
get_logs() {
269256
if (this._get_logs instanceof Function)
270257
return this._get_logs();

0 commit comments

Comments
 (0)