Skip to content

Commit e9727e7

Browse files
committed
Make AppSystem not a singleton
1 parent 93c0b93 commit e9727e7

5 files changed

Lines changed: 43 additions & 21 deletions

File tree

src/AppSystem/App.vala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class Dock.App : Object {
2222

2323
public signal void removed ();
2424

25+
public unowned AppSystem app_system { get; construct; }
2526
public bool pinned { get; construct set; }
2627
public GLib.DesktopAppInfo app_info { get; construct; }
2728

@@ -52,8 +53,8 @@ public class Dock.App : Object {
5253

5354
private static Dock.SwitcherooControl switcheroo_control;
5455

55-
public App (GLib.DesktopAppInfo app_info, bool pinned) {
56-
Object (app_info: app_info, pinned: pinned);
56+
public App (AppSystem app_system, GLib.DesktopAppInfo app_info, bool pinned) {
57+
Object (app_system: app_system, app_info: app_info, pinned: pinned);
5758
}
5859

5960
static construct {
@@ -255,7 +256,7 @@ public class Dock.App : Object {
255256
if (timer_id != 0) {
256257
Source.remove (timer_id);
257258
} else {
258-
yield AppSystem.get_default ().sync_windows (); // Get the current stacking order
259+
yield app_system.sync_windows (); // Get the current stacking order
259260
current_index = windows.length > 1 && windows[0].has_focus ? 1 : 0;
260261
current_windows = {};
261262
foreach (var window in windows) {

src/AppSystem/AppSystem.vala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55

66
public class Dock.AppSystem : Object, UnityClient {
77
private static Settings settings;
8-
private static GLib.Once<AppSystem> instance;
98

109
static construct {
1110
settings = new Settings ("io.elementary.dock");
1211
}
1312

14-
public static unowned AppSystem get_default () {
15-
return instance.once (() => { return new AppSystem (); });
16-
}
17-
1813
public signal void app_added (App app);
1914

15+
public WindowSystem window_system { get; construct; }
16+
2017
private GLib.HashTable<unowned string, App> id_to_app;
2118

22-
private AppSystem () { }
19+
public AppSystem (WindowSystem window_system) {
20+
Object (window_system: window_system);
21+
}
2322

2423
construct {
2524
id_to_app = new HashTable<unowned string, App> (str_hash, str_equal);
@@ -40,7 +39,7 @@ public class Dock.AppSystem : Object, UnityClient {
4039
}
4140

4241
private App add_app (DesktopAppInfo app_info, bool pinned) {
43-
var app = new App (app_info, pinned);
42+
var app = new App (this, app_info, pinned);
4443
id_to_app[app_info.get_id ()] = app;
4544
app.removed.connect ((_app) => id_to_app.remove (_app.app_info.get_id ()));
4645
app_added (app);

src/Application.vala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
public class Dock.Application : Gtk.Application {
7+
private AppSystem app_system;
8+
79
public Application () {
810
Object (application_id: "io.elementary.dock");
911
}
@@ -14,6 +16,9 @@ public class Dock.Application : Gtk.Application {
1416
Granite.init ();
1517
ShellKeyGrabber.init ();
1618
GalaDBus.init.begin ();
19+
20+
app_system = new AppSystem (WindowSystem.get_default ());
21+
ItemManager.init (app_system);
1722
}
1823

1924
protected override void activate () {
@@ -23,7 +28,7 @@ public class Dock.Application : Gtk.Application {
2328
add_window (main_window);
2429

2530
unowned var unity_client = Unity.get_default ();
26-
unity_client.add_client (AppSystem.get_default ());
31+
unity_client.add_client (app_system);
2732
}
2833

2934
active_window.present ();
@@ -32,7 +37,7 @@ public class Dock.Application : Gtk.Application {
3237
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
3338
base.dbus_register (connection, object_path);
3439

35-
connection.register_object (object_path, new ItemInterface ());
40+
connection.register_object (object_path, new ItemInterface (app_system));
3641

3742
return true;
3843
}

src/DBus/ItemInterface.vala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@
55

66
[DBus (name = "io.elementary.dock.items")]
77
public class Dock.ItemInterface : Object {
8+
[DBus (visible = false)]
9+
public AppSystem app_system { private get; construct; }
10+
11+
[DBus (visible = false)]
12+
public ItemInterface (AppSystem app_system) {
13+
Object (app_system: app_system);
14+
}
15+
816
public void add_launcher (string app_id) throws DBusError, IOError {
9-
AppSystem.get_default ().add_app_for_id (app_id);
17+
app_system.add_app_for_id (app_id);
1018
}
1119

1220
public void remove_launcher (string app_id) throws DBusError, IOError {
13-
AppSystem.get_default ().remove_app_by_id (app_id);
21+
app_system.remove_app_by_id (app_id);
1422
}
1523

1624
public string[] list_launchers () throws DBusError, IOError {
17-
return AppSystem.get_default ().list_launchers ();
25+
return app_system.list_launchers ();
1826
}
1927
}

src/ItemManager.vala

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
public class Dock.ItemManager : Gtk.Fixed {
77
private static Settings settings;
88

9-
private static GLib.Once<ItemManager> instance;
9+
private static ItemManager instance;
10+
11+
public static void init (AppSystem app_system) {
12+
instance = new ItemManager (app_system);
13+
}
14+
1015
public static unowned ItemManager get_default () {
11-
return instance.once (() => { return new ItemManager (); });
16+
return instance;
1217
}
1318

19+
public AppSystem app_system { private get; construct; }
20+
1421
public Launcher? added_launcher { get; set; default = null; }
1522

1623
private Adw.TimedAnimation resize_animation;
@@ -27,6 +34,10 @@
2734
settings = new Settings ("io.elementary.dock");
2835
}
2936

37+
private ItemManager (AppSystem app_system) {
38+
Object (app_system: app_system);
39+
}
40+
3041
construct {
3142
launchers = new GLib.GenericArray<Launcher> ();
3243

@@ -88,8 +99,6 @@
8899
return;
89100
}
90101

91-
var app_system = AppSystem.get_default ();
92-
93102
var app = app_system.get_app (app_info.get_id ());
94103
if (app != null) {
95104
app.pinned = true;
@@ -145,7 +154,7 @@
145154
return false;
146155
});
147156

148-
AppSystem.get_default ().app_added.connect ((app) => {
157+
app_system.app_added.connect ((app) => {
149158
var launcher = new Launcher (app);
150159

151160
if (drop_target_file.get_value () != null && added_launcher == null) { // The launcher is being added via dnd from wingpanel
@@ -167,7 +176,7 @@
167176
#endif
168177

169178
map.connect (() => {
170-
AppSystem.get_default ().load.begin ();
179+
app_system.load.begin ();
171180
background_item.load ();
172181
#if WORKSPACE_SWITCHER
173182
WorkspaceSystem.get_default ().load.begin ();

0 commit comments

Comments
 (0)