Skip to content

Commit 9157784

Browse files
committed
Manager: use GLib.Once
1 parent b825c76 commit 9157784

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/MainView.vala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ public class Bluetooth.MainView : Switchboard.SettingsPage {
2323
private Gtk.ListBox list_box;
2424
private Granite.OverlayBar overlaybar;
2525

26-
public Services.ObjectManager manager { get; construct set; }
26+
private Services.ObjectManager manager;
2727

2828
public signal void quit_plug ();
2929

30-
public MainView (Services.ObjectManager manager) {
30+
public MainView () {
3131
Object (
32-
manager: manager,
3332
title: _("Bluetooth"),
3433
activatable: true
3534
);
3635
}
3736

3837
construct {
38+
manager = Bluetooth.Services.ObjectManager.get_default ();
39+
3940
var empty_alert = new Granite.Placeholder (_("No Devices Found")) {
4041
description = _("Please ensure that your devices are visible and ready for pairing.")
4142
};

src/Plug.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class Bluetooth.Plug : Switchboard.Plug {
3636
icon: "bluetooth",
3737
supported_settings: settings);
3838

39-
manager = new Bluetooth.Services.ObjectManager ();
39+
manager = Bluetooth.Services.ObjectManager.get_default ();
4040
manager.bind_property ("has-object", this, "can-show", GLib.BindingFlags.SYNC_CREATE);
4141
}
4242

@@ -47,7 +47,7 @@ public class Bluetooth.Plug : Switchboard.Plug {
4747
};
4848
headerbar.add_css_class (Granite.STYLE_CLASS_FLAT);
4949

50-
main_view = new MainView (manager) {
50+
main_view = new MainView () {
5151
vexpand = true
5252
};
5353

src/Services/Manager.vala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ public class Bluetooth.Services.ObjectManager : Object {
4949
private Bluetooth.Services.AgentManager agent_manager;
5050
private Bluetooth.Services.Agent agent;
5151

52+
private static GLib.Once<ObjectManager> instance;
53+
public static unowned ObjectManager get_default () {
54+
return instance.once (() => { return new ObjectManager (); });
55+
}
56+
57+
private ObjectManager () {}
58+
5259
construct {
5360
var settings_schema = SettingsSchemaSource.get_default ().lookup (DAEMON_SCHEMA, true);
5461
if (settings_schema != null) {

0 commit comments

Comments
 (0)