As gnome-shell is moving to ESM, it will now load extensions as standard modules instead of using legacy imports. The change boils down to exporting the Extension class as default, but we can also start using standard imports for introspected modules now, so do that at the same time. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/259>
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
|
|
// Load shell theme from ~/.local/share/themes/name/gnome-shell
|
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
|
const Main = imports.ui.main;
|
|
|
|
import {getThemeDirs, getModeThemeDirs} from './util.js';
|
|
|
|
const SETTINGS_KEY = 'name';
|
|
|
|
export default class ThemeManager {
|
|
enable() {
|
|
this._settings = ExtensionUtils.getSettings();
|
|
this._settings.connect(`changed::${SETTINGS_KEY}`, this._changeTheme.bind(this));
|
|
this._changeTheme();
|
|
}
|
|
|
|
disable() {
|
|
this._settings?.run_dispose();
|
|
this._settings = null;
|
|
|
|
Main.setThemeStylesheet(null);
|
|
Main.loadTheme();
|
|
}
|
|
|
|
_changeTheme() {
|
|
let stylesheet = null;
|
|
let themeName = this._settings.get_string(SETTINGS_KEY);
|
|
|
|
if (themeName) {
|
|
const stylesheetPaths = getThemeDirs()
|
|
.map(dir => `${dir}/${themeName}/gnome-shell/gnome-shell.css`);
|
|
|
|
stylesheetPaths.push(...getModeThemeDirs()
|
|
.map(dir => `${dir}/${themeName}.css`));
|
|
|
|
stylesheet = stylesheetPaths.find(path => {
|
|
let file = Gio.file_new_for_path(path);
|
|
return file.query_exists(null);
|
|
});
|
|
}
|
|
|
|
if (stylesheet)
|
|
global.log(`loading user theme: ${stylesheet}`);
|
|
else
|
|
global.log('loading default theme (Adwaita)');
|
|
Main.setThemeStylesheet(stylesheet);
|
|
Main.loadTheme();
|
|
}
|
|
}
|