@@ -78,9 +78,6 @@ export class Launcher extends search.Search {
7878
7979 if ( selected ) {
8080 this . service ?. activate ( selected . result . id )
81- global . log ( `service exists? ${ this . service !== null } ` )
82- } else {
83- global . log ( `option does not exist` )
8481 }
8582 }
8683
@@ -197,29 +194,51 @@ export class Launcher extends search.Search {
197194 const app = Shell . AppSystem . get_default ( ) . lookup_desktop_wmclass ( wmclass )
198195
199196 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 ) {
201201 app . activate ( )
202202 const window = app . get_windows ( ) [ 0 ]
203203 if ( window ) shell_window . activate ( true , DefaultPointerPosition . TopLeft , window )
204204 return ;
205205 }
206206
207+ const existing_windows = app . get_windows ( ) . length
208+
207209 app . launch ( 0 , - 1 , gpuPref )
208210
209- GLib . timeout_add ( GLib . PRIORITY_DEFAULT , 100 , ( ) => {
211+ GLib . timeout_add ( GLib . PRIORITY_DEFAULT , 500 , ( ) => {
210212 if ( app . state === Shell . AppState . STOPPED ) {
211- const info = app . get_app_info ( )
212213 if ( info ) {
213- this . locate_by_app_info ( info ) ?. activate ( false )
214+ const window = this . locate_by_app_info ( info ) ;
215+ if ( window ) {
216+ window . activate ( false )
217+ return false ;
218+ }
219+ }
220+ } else if ( app . state === Shell . AppState . RUNNING ) {
221+ const windows : Array < Meta . Window > = app . get_windows ( ) ;
222+
223+ if ( windows . length > existing_windows ) {
224+ let newest_window = null
225+ let newest_time = - 1
226+ for ( const window of windows ) {
227+ const this_time = window . get_user_time ( )
228+ if ( newest_time < this_time ) {
229+ newest_window = window
230+ newest_time = this_time
231+ }
232+
233+ if ( this_time === 0 ) newest_window = window
234+ }
235+
236+ if ( newest_window ) {
237+ shell_window . activate ( true , DefaultPointerPosition . TopLeft , newest_window )
238+ }
239+
240+ return false
214241 }
215-
216- return false ;
217- }
218-
219- const window = app . get_windows ( ) [ 0 ]
220- if ( window ) {
221- shell_window . activate ( true , DefaultPointerPosition . TopLeft , window )
222- return false
223242 }
224243
225244 return true ;
0 commit comments