22//
33// SPDX-License-Identifier: GPL-3.0-or-later
44
5+ import GLib from 'gi://GLib' ;
56import GObject from 'gi://GObject' ;
67import 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' ) ;
0 commit comments