diff --git a/src/AppSystem/App.vala b/src/AppSystem/App.vala index e4aabd30..075fecaf 100644 --- a/src/AppSystem/App.vala +++ b/src/AppSystem/App.vala @@ -23,11 +23,10 @@ public class Dock.App : Object { } } - public signal void removed (); - - public bool pinned { get; construct set; } public GLib.DesktopAppInfo app_info { get; construct; } + public bool pinned { get; set; } + public bool count_visible { get; private set; default = false; } public int64 current_count { get; private set; default = 0; } public bool progress_visible { get; set; default = false; } @@ -59,8 +58,8 @@ public class Dock.App : Object { private string appstream_comp_id = ""; - public App (GLib.DesktopAppInfo app_info, bool pinned) { - Object (app_info: app_info, pinned: pinned); + public App (GLib.DesktopAppInfo app_info) { + Object (app_info: app_info); } static construct { @@ -123,10 +122,6 @@ public class Dock.App : Object { on_appcenter_dbus_changed.begin (); } - notify["pinned"].connect (() => { - check_remove (); - }); - WindowSystem.get_default ().notify["active-workspace"].connect (() => { notify_property ("running-on-active-workspace"); }); @@ -187,12 +182,6 @@ public class Dock.App : Object { return false; } - private void check_remove () { - if (!pinned && !running) { - removed (); - } - } - public void update_windows (GLib.GenericArray? new_windows) { if (new_windows == null) { windows = new GLib.GenericArray (); @@ -206,8 +195,6 @@ public class Dock.App : Object { if (launching && running) { launching = false; } - - check_remove (); } public void perform_unity_update (VariantIter prop_iter) { diff --git a/src/AppSystem/AppSystem.vala b/src/AppSystem/AppSystem.vala index 3ba2fc52..f7cfde79 100644 --- a/src/AppSystem/AppSystem.vala +++ b/src/AppSystem/AppSystem.vala @@ -29,38 +29,51 @@ public class Dock.AppSystem : Object, UnityClient { id_to_app = new HashTable (str_hash, str_equal); } - public App? get_app (string id) { - return id_to_app[id]; - } + public App? get_app_by_id (string id) { + if (!(id in id_to_app)) { + var app_info = new DesktopAppInfo (id); - public async void load () { - foreach (string app_id in settings.get_strv ("launchers")) { - var app_info = new GLib.DesktopAppInfo (app_id); - add_app (app_info, true); - } + if (app_info == null) { + return null; + } - yield sync_windows (); - WindowSystem.get_default ().notify["windows"].connect (sync_windows); - } + var app = new App (app_info); + app.notify["running"].connect (check_app); + app.notify["pinned"].connect (check_app); + app.notify["pinned"].connect (save_pinned); + + id_to_app[app_info.get_id ()] = app; + } - private App add_app (DesktopAppInfo app_info, bool pinned) { - var app = new App (app_info, pinned); - app.removed.connect (remove_app); - app.notify["pinned"].connect (save_pinned); - id_to_app[app_info.get_id ()] = app; - apps_store.append (app); - return app; + return id_to_app[id]; } - private void remove_app (App app) { - id_to_app.remove (app.app_info.get_id ()); + private void check_app (Object obj, ParamSpec pspec) { + var app = (App) obj; uint pos; - if (apps_store.find (app, out pos)) { + var exists = apps_store.find (app, out pos); + + if ((app.pinned || app.running) && !exists) { + apps_store.append (app); + } else if ((!app.pinned && !app.running) && exists) { apps_store.remove (pos); } } + private void save_pinned () { + string[] new_pinned_ids = {}; + + for (uint i = 0; i < apps_store.get_n_items (); i++) { + var app = (App) apps_store.get_item (i); + if (app.pinned) { + new_pinned_ids += app.app_info.get_id (); + } + } + + settings.set_strv ("launchers", new_pinned_ids); + } + public void reorder_app (App app, uint new_index) { uint pos; if (!apps_store.find (app, out pos)) { @@ -72,17 +85,17 @@ public class Dock.AppSystem : Object, UnityClient { apps_store.insert (new_index, app); } - private void save_pinned () { - string[] new_pinned_ids = {}; - - for (uint i = 0; i < apps_store.get_n_items (); i++) { - var app = (App) apps_store.get_item (i); - if (app.pinned) { - new_pinned_ids += app.app_info.get_id (); + public async void load () { + foreach (string app_id in settings.get_strv ("launchers")) { + var app = get_app_by_id (app_id); + if (app == null) { + continue; } + app.pinned = true; } - settings.set_strv ("launchers", new_pinned_ids); + yield sync_windows (); + WindowSystem.get_default ().notify["windows"].connect (sync_windows); } public async void sync_windows () { @@ -90,14 +103,9 @@ public class Dock.AppSystem : Object, UnityClient { var app_window_list = new GLib.HashTable> (direct_hash, direct_equal); foreach (var window in windows) { - App? app = id_to_app[window.app_id]; + var app = get_app_by_id (window.app_id); if (app == null) { - var app_info = new GLib.DesktopAppInfo (window.app_id); - if (app_info == null) { - continue; - } - - app = add_app (app_info, false); + continue; } var window_list = app_window_list.get (app); @@ -117,25 +125,19 @@ public class Dock.AppSystem : Object, UnityClient { } } - public App? add_app_for_id (string app_id) { - if (app_id in id_to_app) { - id_to_app[app_id].pinned = true; - return id_to_app[app_id]; - } - - var app_info = new DesktopAppInfo (app_id); + public void add_app_for_id (string app_id) { + var app = get_app_by_id (app_id); - if (app_info == null) { - warning ("App not found: %s", app_id); - return null; + if (app != null) { + app.pinned = true; } - - return add_app (app_info, true); } public void remove_app_by_id (string app_id) { - if (app_id in id_to_app) { - id_to_app[app_id].pinned = false; + var app = get_app_by_id (app_id); + + if (app != null) { + app.pinned = false; } } @@ -160,8 +162,9 @@ public class Dock.AppSystem : Object, UnityClient { parameters.get ("(sa{sv})", out app_uri, out prop_iter); var app_id = app_uri.replace ("application://", ""); - if (id_to_app[app_id] != null) { - id_to_app[app_id].perform_unity_update (prop_iter); + var app = get_app_by_id (app_id); + if (app != null) { + app.perform_unity_update (prop_iter); } else { critical ("unable to update missing launcher: %s", app_id); } @@ -169,8 +172,9 @@ public class Dock.AppSystem : Object, UnityClient { private void remove_launcher_entry (string sender_name) { var app_id = sender_name + ".desktop"; - if (id_to_app[app_id] != null) { - id_to_app[app_id].remove_launcher_entry (); + var app = get_app_by_id (app_id); + if (app != null) { + app.remove_launcher_entry (); } } } diff --git a/src/ItemManager.vala b/src/ItemManager.vala index a3e7e964..95e17142 100644 --- a/src/ItemManager.vala +++ b/src/ItemManager.vala @@ -82,15 +82,19 @@ var app_system = AppSystem.get_default (); - var app = app_system.get_app (app_info.get_id ()); - if (app != null) { + var app = app_system.get_app_by_id (app_info.get_id ()); + + if (app == null) { + return; + } + + if (app.pinned || app.running) { + // Already in the dock app.pinned = true; drop_target_file.reject (); return; } - app = app_system.add_app_for_id (app_info.get_id ()); - for (var child = app_group.get_first_child (); child != null; child = child.get_next_sibling ()) { if (child is Launcher && child.app == app) { added_launcher = (Launcher) child;