@@ -29,38 +29,51 @@ public class Dock.AppSystem : Object, UnityClient {
2929 id_to_app = new HashTable<unowned string, App > (str_hash, str_equal);
3030 }
3131
32- public App ? get_app (string id ) {
33- return id_to_app[id];
34- }
32+ public App ? get_app_by_id (string id ) {
33+ if ( ! (id in id_to_app)) {
34+ var app_info = new DesktopAppInfo (id);
3535
36- public async void load () {
37- foreach (string app_id in settings. get_strv (" launchers" )) {
38- var app_info = new GLib .DesktopAppInfo (app_id);
39- add_app (app_info, true );
40- }
36+ if (app_info == null ) {
37+ return null ;
38+ }
4139
42- yield sync_windows ();
43- WindowSystem . get_default (). notify[" windows" ]. connect (sync_windows);
44- }
40+ var app = new App (app_info);
41+ app. notify[" pinned" ]. connect (save_pinned);
42+ app. notify[" pinned" ]. connect (check_app);
43+ app. notify[" running" ]. connect (check_app);
4544
46- private App add_app (DesktopAppInfo app_info , bool pinned ) {
47- var app = new App (app_info, pinned);
48- app. removed. connect (remove_app);
49- app. notify[" pinned" ]. connect (save_pinned);
50- id_to_app[app_info. get_id ()] = app;
51- apps_store. append (app);
52- return app;
45+ id_to_app[app_info. get_id ()] = app;
46+ }
47+
48+ return id_to_app[id];
5349 }
5450
55- private void remove_app ( App app ) {
56- id_to_app . remove ( app. app_info . get_id ()) ;
51+ private void check_app ( Object obj , ParamSpec pspec ) {
52+ var app = ( App ) obj ;
5753
5854 uint pos;
59- if (apps_store. find (app, out pos)) {
55+ var exists = apps_store. find (app, out pos);
56+
57+ if ((app. pinned || app. running) && ! exists) {
58+ apps_store. append (app);
59+ } else if ((! app. pinned && ! app. running) && exists) {
6060 apps_store. remove (pos);
6161 }
6262 }
6363
64+ public async void load () {
65+ foreach (string app_id in settings. get_strv (" launchers" )) {
66+ var app = get_app_by_id (app_id);
67+ if (app == null ) {
68+ continue ;
69+ }
70+ app. pinned = true ;
71+ }
72+
73+ yield sync_windows ();
74+ WindowSystem . get_default (). notify[" windows" ]. connect (sync_windows);
75+ }
76+
6477 public void reorder_app (App app , uint new_index ) {
6578 uint pos;
6679 if (! apps_store. find (app, out pos)) {
@@ -90,14 +103,9 @@ public class Dock.AppSystem : Object, UnityClient {
90103
91104 var app_window_list = new GLib .HashTable<App , GLib .GenericArray<Window > > (direct_hash, direct_equal);
92105 foreach (var window in windows) {
93- App ? app = id_to_app[ window. app_id] ;
106+ var app = get_app_by_id ( window. app_id) ;
94107 if (app == null ) {
95- var app_info = new GLib .DesktopAppInfo (window. app_id);
96- if (app_info == null ) {
97- continue ;
98- }
99-
100- app = add_app (app_info, false );
108+ continue ;
101109 }
102110
103111 var window_list = app_window_list. get (app);
@@ -118,24 +126,21 @@ public class Dock.AppSystem : Object, UnityClient {
118126 }
119127
120128 public App ? add_app_for_id (string app_id ) {
121- if (app_id in id_to_app) {
122- id_to_app[app_id]. pinned = true ;
123- return id_to_app[app_id];
124- }
129+ var app = get_app_by_id (app_id);
125130
126- var app_info = new DesktopAppInfo (app_id);
127-
128- if (app_info == null ) {
129- warning (" App not found: %s " , app_id);
131+ if (app == null ) {
130132 return null ;
131133 }
132134
133- return add_app (app_info, true );
135+ app. pinned = true ;
136+ return app;
134137 }
135138
136139 public void remove_app_by_id (string app_id ) {
137- if (app_id in id_to_app) {
138- id_to_app[app_id]. pinned = false ;
140+ var app = get_app_by_id (app_id);
141+
142+ if (app != null ) {
143+ app. pinned = false ;
139144 }
140145 }
141146
@@ -160,17 +165,19 @@ public class Dock.AppSystem : Object, UnityClient {
160165 parameters. get (" (sa{sv})" , out app_uri, out prop_iter);
161166
162167 var app_id = app_uri. replace (" application://" , " " );
163- if (id_to_app[app_id] != null ) {
164- id_to_app[app_id]. perform_unity_update (prop_iter);
168+ var app = get_app_by_id (app_id);
169+ if (app != null ) {
170+ app. perform_unity_update (prop_iter);
165171 } else {
166172 critical (" unable to update missing launcher: %s " , app_id);
167173 }
168174 }
169175
170176 private void remove_launcher_entry (string sender_name ) {
171177 var app_id = sender_name + " .desktop" ;
172- if (id_to_app[app_id] != null ) {
173- id_to_app[app_id]. remove_launcher_entry ();
178+ var app = get_app_by_id (app_id);
179+ if (app != null ) {
180+ app. remove_launcher_entry ();
174181 }
175182 }
176183}
0 commit comments