Add support for Materia-compact and Arc themes, watch theme changes
This commit is contained in:
+50
-25
@@ -20,12 +20,31 @@ this program. If not, see <http s ://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
const Gio = imports.gi.Gio;
|
const Gio = imports.gi.Gio;
|
||||||
|
|
||||||
let interface_settings;
|
let interface_settings, interface_settings_connect_id;
|
||||||
let nightlight_active;
|
let nightlight_active;
|
||||||
let original_user_theme, user_theme_day, user_theme_night;
|
let original_user_theme, user_theme_day, user_theme_night;
|
||||||
let conn, proxy, proxy_connect_id;
|
let conn, proxy, proxy_connect_id;
|
||||||
|
|
||||||
|
|
||||||
|
function _connect_dbus_proxy() {
|
||||||
|
conn = Gio.bus_get_sync(Gio.BusType.SESSION, null);
|
||||||
|
if ( conn === null ) {
|
||||||
|
throw new Error('Unable to connect to the session bus');
|
||||||
|
}
|
||||||
|
proxy = Gio.DBusProxy.new_sync(
|
||||||
|
conn,
|
||||||
|
Gio.DBusProxyFlags.GET_INVALIDATED_PROPERTIES,
|
||||||
|
null,
|
||||||
|
'org.gnome.SettingsDaemon.Color',
|
||||||
|
'/org/gnome/SettingsDaemon/Color',
|
||||||
|
'org.gnome.SettingsDaemon.Color',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
if ( proxy === null ) {
|
||||||
|
throw new Error('Unable to create proxy to the session bus');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _get_theme() {
|
function _get_theme() {
|
||||||
return interface_settings.get_string('gtk-theme');
|
return interface_settings.get_string('gtk-theme');
|
||||||
}
|
}
|
||||||
@@ -34,6 +53,25 @@ function _set_theme(theme) {
|
|||||||
interface_settings.set_string('gtk-theme', theme);
|
interface_settings.set_string('gtk-theme', theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _build_theme_variants() {
|
||||||
|
if ( original_user_theme.includes('HighContrast') ) {
|
||||||
|
user_theme_day = 'HighContrast';
|
||||||
|
user_theme_night = 'HighContrastInverse';
|
||||||
|
}
|
||||||
|
else if ( original_user_theme.match(/Materia.*-compact/g) ) {
|
||||||
|
user_theme_day = original_user_theme.replace('-dark', '');
|
||||||
|
user_theme_night = user_theme_day.replace(/(-light)?-compact/g, '-dark-compact');
|
||||||
|
}
|
||||||
|
else if ( original_user_theme.includes('Arc') ) {
|
||||||
|
user_theme_day = original_user_theme.replace('-Dark', '');
|
||||||
|
user_theme_night = user_theme_day.replace('-Darker', '') + '-Dark';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
user_theme_day = original_user_theme.replace('-dark', '');
|
||||||
|
user_theme_night = user_theme_day.replace(/(-light)?(-darker)?/g, '') + '-dark';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _apply_theme_variant() {
|
function _apply_theme_variant() {
|
||||||
const variant = proxy.get_cached_property('NightLightActive');
|
const variant = proxy.get_cached_property('NightLightActive');
|
||||||
if ( variant.get_boolean() === nightlight_active ) return;
|
if ( variant.get_boolean() === nightlight_active ) return;
|
||||||
@@ -47,49 +85,36 @@ function enable() {
|
|||||||
// Store the current user theme and build day and night variants
|
// Store the current user theme and build day and night variants
|
||||||
interface_settings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
|
interface_settings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' });
|
||||||
original_user_theme = _get_theme();
|
original_user_theme = _get_theme();
|
||||||
if ( original_user_theme.includes('HighContrast') ) {
|
_build_theme_variants();
|
||||||
user_theme_day = 'HighContrast';
|
|
||||||
user_theme_night = 'HighContrastInverse';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
user_theme_day = original_user_theme.replace(/(-dark)?/gi, '');
|
|
||||||
user_theme_night = user_theme_day.replace(/(-light)?(-darker)?/gi, '') + '-dark';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect to session bus, listen to Color changes and change theme variant
|
// Connect to session bus, listen to Color changes and change theme variant
|
||||||
try {
|
try {
|
||||||
conn = Gio.bus_get_sync(Gio.BusType.SESSION, null);
|
_connect_dbus_proxy();
|
||||||
if ( conn === null ) {
|
|
||||||
throw new Error('Unable to connect to the session bus');
|
|
||||||
}
|
|
||||||
proxy = Gio.DBusProxy.new_sync(
|
|
||||||
conn,
|
|
||||||
Gio.DBusProxyFlags.GET_INVALIDATED_PROPERTIES,
|
|
||||||
null,
|
|
||||||
'org.gnome.SettingsDaemon.Color',
|
|
||||||
'/org/gnome/SettingsDaemon/Color',
|
|
||||||
'org.gnome.SettingsDaemon.Color',
|
|
||||||
null
|
|
||||||
);
|
|
||||||
if ( proxy === null ) {
|
|
||||||
throw new Error('Unable to create proxy to the session bus');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
logError(e);
|
logError(e);
|
||||||
}
|
}
|
||||||
proxy_connect_id = proxy.connect('g-properties-changed', _apply_theme_variant);
|
proxy_connect_id = proxy.connect('g-properties-changed', _apply_theme_variant);
|
||||||
_apply_theme_variant();
|
_apply_theme_variant();
|
||||||
|
|
||||||
|
// Listen to theme change
|
||||||
|
interface_settings_connect_id = interface_settings.connect('changed::gtk-theme', () => {
|
||||||
|
original_user_theme = _get_theme();
|
||||||
|
_build_theme_variants();
|
||||||
|
_apply_theme_variant();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function disable() {
|
function disable() {
|
||||||
if ( proxy && proxy_connect_id ) {
|
if ( proxy && proxy_connect_id ) {
|
||||||
proxy.disconnect(proxy_connect_id);
|
proxy.disconnect(proxy_connect_id);
|
||||||
}
|
}
|
||||||
|
interface_settings.disconnect(interface_settings_connect_id);
|
||||||
|
|
||||||
_set_theme(original_user_theme);
|
_set_theme(original_user_theme);
|
||||||
|
|
||||||
interface_settings = null;
|
interface_settings = null;
|
||||||
|
interface_settings_connect_id = null;
|
||||||
nightlight_active = null;
|
nightlight_active = null;
|
||||||
original_user_theme = null;
|
original_user_theme = null;
|
||||||
user_theme_day = null;
|
user_theme_day = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user