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
21 changes: 4 additions & 17 deletions src/AppSystem/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
});
Expand Down Expand Up @@ -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<Window>? new_windows) {
if (new_windows == null) {
windows = new GLib.GenericArray<Window> ();
Expand All @@ -206,8 +195,6 @@ public class Dock.App : Object {
if (launching && running) {
launching = false;
}

check_remove ();
}

public void perform_unity_update (VariantIter prop_iter) {
Expand Down
112 changes: 58 additions & 54 deletions src/AppSystem/AppSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,51 @@ public class Dock.AppSystem : Object, UnityClient {
id_to_app = new HashTable<unowned string, App> (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)) {
Expand All @@ -72,32 +85,27 @@ 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 () {
var windows = WindowSystem.get_default ().windows;

var app_window_list = new GLib.HashTable<App, GLib.GenericArray<Window>> (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);
Expand All @@ -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;
}
}

Expand All @@ -160,17 +162,19 @@ 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);
}
}

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 ();
}
}
}
12 changes: 8 additions & 4 deletions src/ItemManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down