diff --git a/src/App.vala b/src/App.vala index 52bb571d..f9bb09d2 100644 --- a/src/App.vala +++ b/src/App.vala @@ -20,6 +20,7 @@ public class Dock.App : Object { public bool progress_visible { get; set; default = false; } public double progress { get; set; default = 0; } public bool prefers_nondefault_gpu { get; private set; default = false; } + public bool exists { get; private set; default = true; } public SimpleActionGroup action_group { get; construct; } public Menu menu_model { get; construct; } @@ -28,6 +29,8 @@ public class Dock.App : Object { private static Dock.SwitcherooControl switcheroo_control; + private FileMonitor? launcher_file_monitor = null; + private uint removal_timer = 0U; private SimpleAction pinned_action; public App (GLib.DesktopAppInfo app_info, bool pinned) { @@ -94,6 +97,17 @@ public class Dock.App : Object { action_group.add_action (simple_action); } + unowned string? launcher_filename = app_info.get_filename (); + if (launcher_filename != null) { + var launcher_file = File.new_for_path (launcher_filename); + try { + launcher_file_monitor = launcher_file.monitor_file (FileMonitorFlags.SEND_MOVED); + launcher_file_monitor.changed.connect (launcher_file_changed); + } catch (Error e) { + warning ("Unable to monitor %s: %s", launcher_filename, e.message); + } + } + notify["pinned"].connect (() => { pinned_action.set_state (pinned); LauncherManager.get_default ().sync_pinned (); @@ -155,6 +169,39 @@ public class Dock.App : Object { return false; } + + private void launcher_file_changed (GLib.File file, GLib.File? other_file, GLib.FileMonitorEvent event_type) { + switch (event_type) { + case GLib.FileMonitorEvent.CHANGES_DONE_HINT: + //TODO + break; + case GLib.FileMonitorEvent.DELETED: + exists = false; + removal_timer = GLib.Timeout.add_seconds (60, () => { + unowned string? launcher_filename = app_info.get_filename (); + if (launcher_filename != null) { + var launcher_file = File.new_for_path (launcher_filename); + exists = launcher_file.query_exists (); + } + + if (!exists) { + pinned = false; + } + + removal_timer = 0U; + return GLib.Source.REMOVE; + }); + break; + case GLib.FileMonitorEvent.CREATED: + exists = true; + GLib.Source.remove (removal_timer); + removal_timer = 0U; + break; + default: + break; + } + } + public void update_windows (Gee.List? new_windows) { if (new_windows == null) { windows = new Gee.LinkedList (); diff --git a/src/LauncherManager.vala b/src/LauncherManager.vala index 23c9230d..d7cffc3a 100644 --- a/src/LauncherManager.vala +++ b/src/LauncherManager.vala @@ -40,6 +40,23 @@ if (key == "icon-size") { reposition_launchers (); } + + if (key == "launchers") { + int index = 0; + foreach (string app_id in settings.get_strv ("launchers")) { + var app_info = new GLib.DesktopAppInfo (app_id); + unowned List? launcher = launchers.search (app_info, (l, info) => { + return l.app.app_info.equal (info) ? 0 : -1; + }); + if (launcher == null) { + add_launcher (app_info, true, false, index); + } else { + index = launchers.index (launcher.data) + 1; + } + } + + reposition_launchers (); + } }); var drop_target_file = new Gtk.DropTarget (typeof (File), COPY) {