diff --git a/src/AppSystem/App.vala b/src/AppSystem/App.vala index 5ebadc82..32d29ea2 100644 --- a/src/AppSystem/App.vala +++ b/src/AppSystem/App.vala @@ -22,6 +22,7 @@ public class Dock.App : Object { public signal void removed (); + public unowned AppSystem app_system { get; construct; } public bool pinned { get; construct set; } public GLib.DesktopAppInfo app_info { get; construct; } @@ -52,8 +53,8 @@ public class Dock.App : Object { private static Dock.SwitcherooControl switcheroo_control; - public App (GLib.DesktopAppInfo app_info, bool pinned) { - Object (app_info: app_info, pinned: pinned); + public App (AppSystem app_system, GLib.DesktopAppInfo app_info, bool pinned) { + Object (app_system: app_system, app_info: app_info, pinned: pinned); } static construct { @@ -255,7 +256,7 @@ public class Dock.App : Object { if (timer_id != 0) { Source.remove (timer_id); } else { - yield AppSystem.get_default ().sync_windows (); // Get the current stacking order + yield app_system.sync_windows (); // Get the current stacking order current_index = windows.length > 1 && windows[0].has_focus ? 1 : 0; current_windows = {}; foreach (var window in windows) { diff --git a/src/AppSystem/AppSystem.vala b/src/AppSystem/AppSystem.vala index 6148b170..ef9164d4 100644 --- a/src/AppSystem/AppSystem.vala +++ b/src/AppSystem/AppSystem.vala @@ -5,21 +5,20 @@ public class Dock.AppSystem : Object, UnityClient { private static Settings settings; - private static GLib.Once instance; static construct { settings = new Settings ("io.elementary.dock"); } - public static unowned AppSystem get_default () { - return instance.once (() => { return new AppSystem (); }); - } - public signal void app_added (App app); + public WindowSystem window_system { get; construct; } + private GLib.HashTable id_to_app; - private AppSystem () { } + public AppSystem (WindowSystem window_system) { + Object (window_system: window_system); + } construct { id_to_app = new HashTable (str_hash, str_equal); @@ -36,11 +35,11 @@ public class Dock.AppSystem : Object, UnityClient { } yield sync_windows (); - WindowSystem.get_default ().notify["windows"].connect (sync_windows); + window_system.notify["windows"].connect (sync_windows); } private App add_app (DesktopAppInfo app_info, bool pinned) { - var app = new App (app_info, pinned); + var app = new App (this, app_info, pinned); id_to_app[app_info.get_id ()] = app; app.removed.connect ((_app) => id_to_app.remove (_app.app_info.get_id ())); app_added (app); @@ -48,7 +47,7 @@ public class Dock.AppSystem : Object, UnityClient { } public async void sync_windows () { - var windows = WindowSystem.get_default ().windows; + var windows = window_system.windows; var app_window_list = new GLib.HashTable> (direct_hash, direct_equal); foreach (var window in windows) { diff --git a/src/Application.vala b/src/Application.vala index eea910c0..73eb7285 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -4,6 +4,8 @@ */ public class Dock.Application : Gtk.Application { + private AppSystem app_system; + public Application () { Object (application_id: "io.elementary.dock"); } @@ -14,6 +16,9 @@ public class Dock.Application : Gtk.Application { Granite.init (); ShellKeyGrabber.init (); GalaDBus.init.begin (); + + app_system = new AppSystem (WindowSystem.get_default ()); + ItemManager.init (app_system); } protected override void activate () { @@ -23,7 +28,7 @@ public class Dock.Application : Gtk.Application { add_window (main_window); unowned var unity_client = Unity.get_default (); - unity_client.add_client (AppSystem.get_default ()); + unity_client.add_client (app_system); } active_window.present (); @@ -32,7 +37,7 @@ public class Dock.Application : Gtk.Application { public override bool dbus_register (DBusConnection connection, string object_path) throws Error { base.dbus_register (connection, object_path); - connection.register_object (object_path, new ItemInterface ()); + connection.register_object (object_path, new ItemInterface (app_system)); return true; } diff --git a/src/DBus/ItemInterface.vala b/src/DBus/ItemInterface.vala index 6e5f431c..9b1505e0 100644 --- a/src/DBus/ItemInterface.vala +++ b/src/DBus/ItemInterface.vala @@ -5,15 +5,23 @@ [DBus (name = "io.elementary.dock.items")] public class Dock.ItemInterface : Object { + [DBus (visible = false)] + public AppSystem app_system { private get; construct; } + + [DBus (visible = false)] + public ItemInterface (AppSystem app_system) { + Object (app_system: app_system); + } + public void add_launcher (string app_id) throws DBusError, IOError { - AppSystem.get_default ().add_app_for_id (app_id); + app_system.add_app_for_id (app_id); } public void remove_launcher (string app_id) throws DBusError, IOError { - AppSystem.get_default ().remove_app_by_id (app_id); + app_system.remove_app_by_id (app_id); } public string[] list_launchers () throws DBusError, IOError { - return AppSystem.get_default ().list_launchers (); + return app_system.list_launchers (); } } diff --git a/src/ItemManager.vala b/src/ItemManager.vala index ee5a25a6..c71204b2 100644 --- a/src/ItemManager.vala +++ b/src/ItemManager.vala @@ -6,11 +6,18 @@ public class Dock.ItemManager : Gtk.Fixed { private static Settings settings; - private static GLib.Once instance; + private static ItemManager instance; + + public static void init (AppSystem app_system) { + instance = new ItemManager (app_system); + } + public static unowned ItemManager get_default () { - return instance.once (() => { return new ItemManager (); }); + return instance; } + public AppSystem app_system { private get; construct; } + public Launcher? added_launcher { get; set; default = null; } private Adw.TimedAnimation resize_animation; @@ -27,6 +34,10 @@ settings = new Settings ("io.elementary.dock"); } + private ItemManager (AppSystem app_system) { + Object (app_system: app_system); + } + construct { launchers = new GLib.GenericArray (); @@ -88,8 +99,6 @@ return; } - var app_system = AppSystem.get_default (); - var app = app_system.get_app (app_info.get_id ()); if (app != null) { app.pinned = true; @@ -145,7 +154,7 @@ return false; }); - AppSystem.get_default ().app_added.connect ((app) => { + app_system.app_added.connect ((app) => { var launcher = new Launcher (app); if (drop_target_file.get_value () != null && added_launcher == null) { // The launcher is being added via dnd from wingpanel @@ -167,7 +176,7 @@ #endif map.connect (() => { - AppSystem.get_default ().load.begin (); + app_system.load.begin (); background_item.load (); #if WORKSPACE_SWITCHER WorkspaceSystem.get_default ().load.begin ();