@@ -15,7 +15,7 @@ import type { ShellWindow } from 'window'
1515import type { JsonIPC } from 'launcher_service'
1616
1717const { DefaultPointerPosition } = config
18- const { Clutter, GLib, Meta, Shell } = imports . gi
18+ const { Clutter, Gio , GLib, Meta, Shell } = imports . gi
1919
2020interface SearchOption {
2121 result : JsonIPC . SearchResult
@@ -192,7 +192,6 @@ export class Launcher extends search.Search {
192192
193193 if ( app ) {
194194 if ( app . state === Shell . AppState . RUNNING ) {
195- global . log ( `activating window` )
196195 app . activate ( )
197196 const window = app . get_windows ( ) [ 0 ]
198197 if ( window ) shell_window . activate ( true , DefaultPointerPosition . TopLeft , window )
@@ -202,6 +201,15 @@ export class Launcher extends search.Search {
202201 app . launch ( 0 , - 1 , gpuPref )
203202
204203 GLib . timeout_add ( GLib . PRIORITY_DEFAULT , 100 , ( ) => {
204+ if ( app . state === Shell . AppState . STOPPED ) {
205+ const info = app . get_app_info ( )
206+ if ( info ) {
207+ this . locate_by_app_info ( info ) ?. activate ( false )
208+ }
209+
210+ return false ;
211+ }
212+
205213 const window = app . get_windows ( ) [ 0 ]
206214 if ( window ) {
207215 shell_window . activate ( true , DefaultPointerPosition . TopLeft , window )
@@ -223,6 +231,30 @@ export class Launcher extends search.Search {
223231 log . warn ( "pop-shell: deprecated function called (dialog_launcher::load_desktop_files)" )
224232 }
225233
234+ locate_by_app_info ( info : any ) : null | ShellWindow {
235+ const exec_info : null | string = info . get_string ( "Exec" )
236+ const exec = exec_info ?. split ( ' ' ) . shift ( ) ?. split ( '/' ) . pop ( )
237+ if ( exec ) {
238+ for ( const window of this . ext . tab_list ( Meta . TabList . NORMAL , null ) ) {
239+ const pid = window . meta . get_pid ( )
240+ if ( pid !== - 1 ) {
241+ try {
242+ let f = Gio . File . new_for_path ( `/proc/${ pid } /cmdline` )
243+ const [ , bytes ] = f . load_contents ( null )
244+ const output : string = imports . byteArray . toString ( bytes )
245+ const cmd = output . split ( ' ' ) . shift ( ) ?. split ( '/' ) . pop ( )
246+ global . log ( `is ${ cmd } equal to ${ exec } ` )
247+ if ( cmd === exec ) return window
248+ } catch ( _ ) {
249+
250+ }
251+ }
252+ }
253+ }
254+
255+ return null
256+ }
257+
226258 open ( ext : Ext ) {
227259 const mon = ext . monitor_work_area ( ext . active_monitor ( ) )
228260
0 commit comments