@@ -78,9 +78,6 @@ export class Launcher extends search.Search {
78
78
79
79
if ( selected ) {
80
80
this . service ?. activate ( selected . result . id )
81
- global . log ( `service exists? ${ this . service !== null } ` )
82
- } else {
83
- global . log ( `option does not exist` )
84
81
}
85
82
}
86
83
@@ -197,30 +194,60 @@ export class Launcher extends search.Search {
197
194
const app = Shell . AppSystem . get_default ( ) . lookup_desktop_wmclass ( wmclass )
198
195
199
196
if ( app ) {
200
- if ( app . state === Shell . AppState . RUNNING ) {
197
+ const info = app . get_app_info ( )
198
+ const is_gnome_settings = info ? info . get_executable ( ) === "gnome-control-center" : false ;
199
+
200
+ if ( is_gnome_settings && app . state === Shell . AppState . RUNNING ) {
201
201
app . activate ( )
202
202
const window = app . get_windows ( ) [ 0 ]
203
203
if ( window ) shell_window . activate ( true , DefaultPointerPosition . TopLeft , window )
204
204
return ;
205
205
}
206
206
207
+ const existing_windows = app . get_windows ( ) . length
208
+
207
209
app . launch ( 0 , - 1 , gpuPref )
208
210
211
+ let attempts = 0
212
+
209
213
GLib . timeout_add ( GLib . PRIORITY_DEFAULT , 100 , ( ) => {
210
214
if ( app . state === Shell . AppState . STOPPED ) {
211
- const info = app . get_app_info ( )
212
215
if ( info ) {
213
- this . locate_by_app_info ( info ) ?. activate ( false )
216
+ const window = this . locate_by_app_info ( info ) ;
217
+ if ( window ) {
218
+ window . activate ( false )
219
+ return false ;
220
+ }
221
+ }
222
+ } else if ( app . state === Shell . AppState . RUNNING ) {
223
+ const windows : Array < Meta . Window > = app . get_windows ( ) ;
224
+
225
+ if ( windows . length > existing_windows ) {
226
+ let newest_window = null
227
+ let newest_time = - 1
228
+ for ( const window of windows ) {
229
+ const this_time = window . get_user_time ( )
230
+ if ( newest_time < this_time ) {
231
+ newest_window = window
232
+ newest_time = this_time
233
+ }
234
+
235
+ if ( this_time === 0 ) {
236
+ newest_window = window
237
+ break
238
+ }
239
+ }
240
+
241
+ if ( newest_window ) {
242
+ shell_window . activate ( true , DefaultPointerPosition . TopLeft , newest_window )
243
+ }
244
+
245
+ return false
214
246
}
215
-
216
- return false ;
217
247
}
218
248
219
- const window = app . get_windows ( ) [ 0 ]
220
- if ( window ) {
221
- shell_window . activate ( true , DefaultPointerPosition . TopLeft , window )
222
- return false
223
- }
249
+ attempts += 1
250
+ if ( attempts === 20 ) return false
224
251
225
252
return true ;
226
253
} )
0 commit comments