@@ -15,7 +15,7 @@ import type { ShellWindow } from 'window'
15
15
import type { JsonIPC } from 'launcher_service'
16
16
17
17
const { DefaultPointerPosition } = config
18
- const { Clutter, GLib, Meta, Shell } = imports . gi
18
+ const { Clutter, Gio , GLib, Meta, Shell } = imports . gi
19
19
20
20
interface SearchOption {
21
21
result : JsonIPC . SearchResult
@@ -192,7 +192,6 @@ export class Launcher extends search.Search {
192
192
193
193
if ( app ) {
194
194
if ( app . state === Shell . AppState . RUNNING ) {
195
- global . log ( `activating window` )
196
195
app . activate ( )
197
196
const window = app . get_windows ( ) [ 0 ]
198
197
if ( window ) shell_window . activate ( true , DefaultPointerPosition . TopLeft , window )
@@ -202,6 +201,15 @@ export class Launcher extends search.Search {
202
201
app . launch ( 0 , - 1 , gpuPref )
203
202
204
203
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
+
205
213
const window = app . get_windows ( ) [ 0 ]
206
214
if ( window ) {
207
215
shell_window . activate ( true , DefaultPointerPosition . TopLeft , window )
@@ -223,6 +231,30 @@ export class Launcher extends search.Search {
223
231
log . warn ( "pop-shell: deprecated function called (dialog_launcher::load_desktop_files)" )
224
232
}
225
233
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
+
226
258
open ( ext : Ext ) {
227
259
const mon = ext . monitor_work_area ( ext . active_monitor ( ) )
228
260
0 commit comments