Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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) {
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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, () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment about why we have this on a timer?

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<AppWindow>? new_windows) {
if (new_windows == null) {
windows = new Gee.LinkedList<AppWindow> ();
Expand Down
17 changes: 17 additions & 0 deletions src/LauncherManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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>? launcher = launchers.search<DesktopAppInfo> (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) {
Expand Down