Debian Codegraph @

extensions/user-theme/extension.js

raw
1 // SPDX-FileCopyrightText: 2011 John Stowers <[email protected]>
2 // SPDX-FileCopyrightText: 2011 Giovanni Campagna <[email protected]>
3 // SPDX-FileCopyrightText: 2011 Elad Alfassa <[email protected]>
4 // SPDX-FileCopyrightText: 2014 Florian Müllner <[email protected]>
5 //
6 // SPDX-License-Identifier: GPL-2.0-or-later
7
8 import Gio from 'gi://Gio';
9
10 import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
11
12 import * as Main from 'resource:///org/gnome/shell/ui/main.js';
13
14 import {getThemeDirs, getModeThemeDirs} from './util.js';
15
16 const SETTINGS_KEY = 'name';
17
18 export default class ThemeManager extends Extension {
19 enable() {
20 this._settings = this.getSettings();
21 this._settings.connectObject(`changed::${SETTINGS_KEY}`,
22 this._changeTheme.bind(this), this);
23 this._changeTheme();
24 }
25
26 disable() {
27 this._settings?.disconnectObject();
28 this._settings = null;
29
30 Main.setThemeStylesheet(null);
31 Main.loadTheme();
32 }
33
34 _changeTheme() {
35 let stylesheet = null;
36 const themeName = this._settings.get_string(SETTINGS_KEY);
37
38 if (themeName) {
39 const stylesheetPaths = getThemeDirs()
40 .map(dir => `${dir}/${themeName}/gnome-shell/gnome-shell.css`);
41
42 stylesheetPaths.push(...getModeThemeDirs()
43 .map(dir => `${dir}/${themeName}.css`));
44
45 stylesheet = stylesheetPaths.find(path => {
46 const file = Gio.file_new_for_path(path);
47 return file.query_exists(null);
48 });
49 }
50
51 if (stylesheet)
52 log(`loading user theme: ${stylesheet}`);
53 else
54 log('loading default theme (Adwaita)');
55 Main.setThemeStylesheet(stylesheet);
56 Main.loadTheme();
57 }
58 }