2023-07-10 09:53:00 +00:00
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import GObject from 'gi://GObject';
|
2023-06-08 04:52:46 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import * as Main from '../main.js';
|
2022-07-27 01:38:28 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import {QuickToggle, SystemIndicator} from '../quickSettings.js';
|
2022-07-27 01:38:28 +00:00
|
|
|
|
|
|
|
const DarkModeToggle = GObject.registerClass(
|
|
|
|
class DarkModeToggle extends QuickToggle {
|
|
|
|
_init() {
|
|
|
|
super._init({
|
2023-01-30 20:32:39 +00:00
|
|
|
title: _('Dark Style'),
|
2022-07-27 01:38:28 +00:00
|
|
|
iconName: 'dark-mode-symbolic',
|
|
|
|
});
|
|
|
|
|
|
|
|
this._settings = new Gio.Settings({
|
|
|
|
schema_id: 'org.gnome.desktop.interface',
|
|
|
|
});
|
|
|
|
this._changedId = this._settings.connect('changed::color-scheme',
|
|
|
|
() => this._sync());
|
|
|
|
|
|
|
|
this.connectObject(
|
|
|
|
'destroy', () => this._settings.run_dispose(),
|
|
|
|
'clicked', () => this._toggleMode(),
|
|
|
|
this);
|
|
|
|
this._sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
_toggleMode() {
|
|
|
|
Main.layoutManager.screenTransition.run();
|
|
|
|
this._settings.set_string('color-scheme',
|
|
|
|
this.checked ? 'default' : 'prefer-dark');
|
|
|
|
}
|
|
|
|
|
|
|
|
_sync() {
|
|
|
|
const colorScheme = this._settings.get_string('color-scheme');
|
|
|
|
const checked = colorScheme === 'prefer-dark';
|
|
|
|
if (this.checked !== checked)
|
|
|
|
this.set({checked});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
export const Indicator = GObject.registerClass(
|
2022-07-27 01:38:28 +00:00
|
|
|
class Indicator extends SystemIndicator {
|
|
|
|
_init() {
|
|
|
|
super._init();
|
|
|
|
|
|
|
|
this.quickSettingsItems.push(new DarkModeToggle());
|
|
|
|
}
|
|
|
|
});
|