Skip to content
Merged
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
1 change: 0 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
src/Indicator.vala
src/PopoverWidget.vala
src/DBus/AccountsService.vala
src/DBus/EndSessionDialogServer.vala
src/DBus/LockInterface.vala
src/DBus/SeatInterface.vala
Expand Down
9 changes: 0 additions & 9 deletions src/DBus/AccountsService.vala

This file was deleted.

46 changes: 5 additions & 41 deletions src/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,11 @@ public class QuickSettings.PopoverWidget : Gtk.Box {
bottom_box.remove (current_user_button);
}

setup_accounts_services.begin ((obj, res) => {
var pantheon_service = setup_accounts_services.end (res);
if (pantheon_service != null &&
((DBusProxy) pantheon_service).get_cached_property ("PrefersColorScheme") != null
) {
if (server_type != GREETER) {
var darkmode_button = new DarkModeToggle (pantheon_service);
toggle_box.add (darkmode_button);
show_all ();
}
}
});
if (server_type != GREETER) {
var darkmode_button = new DarkModeToggle ();
toggle_box.add (darkmode_button);
show_all ();
}

setup_sensor_proxy.begin ((obj, res) => {
var sensor_proxy = setup_sensor_proxy.end (res);
Expand Down Expand Up @@ -185,35 +178,6 @@ public class QuickSettings.PopoverWidget : Gtk.Box {
});
}

private async PantheonAccountsService? setup_accounts_services () {
unowned GLib.DBusConnection connection;
string path;

try {
connection = yield GLib.Bus.get (SYSTEM);

var reply = yield connection.call (
FDO_ACCOUNTS_NAME, FDO_ACCOUNTS_PATH,
FDO_ACCOUNTS_NAME, "FindUserByName",
new Variant.tuple ({ new Variant.string (Environment.get_user_name ()) }),
new VariantType ("(o)"),
NONE,
-1
);
reply.get_child (0, "o", out path);
} catch {
critical ("Could not connect to AccountsService");
return null;
}

try {
return yield connection.get_proxy (FDO_ACCOUNTS_NAME, path, GET_INVALIDATED_PROPERTIES);
} catch {
critical ("Unable to get Pantheon's AccountsService proxy, Dark mode toggle will not be available");
return null;
}
}

private async SensorProxy? setup_sensor_proxy () {
try {
return yield Bus.get_proxy (BusType.SYSTEM, "net.hadess.SensorProxy", "/net/hadess/SensorProxy");
Expand Down
35 changes: 11 additions & 24 deletions src/Widgets/DarkModeToggle.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
*/

public class QuickSettings.DarkModeToggle: SettingsToggle {
public PantheonAccountsService pantheon_service { get; construct; }

public DarkModeToggle (PantheonAccountsService pantheon_service) {
public DarkModeToggle () {
Object (
pantheon_service: pantheon_service,
icon: new ThemedIcon ("dark-mode-symbolic"),
label: _("Dark Mode")
);
Expand All @@ -17,29 +14,19 @@ public class QuickSettings.DarkModeToggle: SettingsToggle {
construct {
settings_uri = "settings://desktop/appearance";

active = pantheon_service.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
var settings = new GLib.Settings ("io.elementary.settings-daemon.prefers-color-scheme");

notify["active"].connect (on_activate);
active = settings.get_enum ("color-scheme") == Granite.Settings.ColorScheme.DARK;
settings.changed["color-scheme"].connect (() => {
active = settings.get_enum ("color-scheme") == Granite.Settings.ColorScheme.DARK;
});

((DBusProxy) pantheon_service).g_properties_changed.connect ((changed, invalid) => {
var color_scheme = changed.lookup_value ("PrefersColorScheme", new VariantType ("i"));
if (color_scheme != null) {
/* Disconnect signal before updating to avoid changing schedule */
notify.disconnect (on_activate);
active = (Granite.Settings.ColorScheme) color_scheme.get_int32 () == Granite.Settings.ColorScheme.DARK;
notify["active"].connect (on_activate);
notify["active"].connect (() => {
if (active) {
settings.set_enum ("color-scheme", Granite.Settings.ColorScheme.DARK);
} else {
settings.set_enum ("color-scheme", Granite.Settings.ColorScheme.NO_PREFERENCE);
}
});
}

private void on_activate () {
var settings = new Settings ("io.elementary.settings-daemon.prefers-color-scheme");
settings.set_string ("prefer-dark-schedule", "disabled");

if (active) {
pantheon_service.prefers_color_scheme = Granite.Settings.ColorScheme.DARK;
} else {
pantheon_service.prefers_color_scheme = Granite.Settings.ColorScheme.NO_PREFERENCE;
}
}
}
1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ config_file = configure_file(
sources = [
'Indicator.vala',
'PopoverWidget.vala',
'DBus' / 'AccountsService.vala',
'DBus' / 'EndSessionDialogServer.vala',
'DBus' / 'LockInterface.vala',
'DBus' / 'SeatInterface.vala',
Expand Down