generated from jmmaranan/gnome-shell-ext-template
-
Notifications
You must be signed in to change notification settings - Fork 55
/
extension.js
103 lines (90 loc) · 3.92 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* This file is part of the Forge GNOME extension
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Gnome imports
import * as Main from "resource:///org/gnome/shell/ui/main.js";
import { Extension, gettext as _ } from "resource:///org/gnome/shell/extensions/extension.js";
// Shared state
import { Logger } from "./lib/shared/logger.js";
import { ConfigManager } from "./lib/shared/settings.js";
// Application imports
import { Keybindings } from "./lib/extension/keybindings.js";
import { WindowManager } from "./lib/extension/window.js";
import { FeatureIndicator, FeatureMenuToggle } from "./lib/extension/indicator.js";
import { ExtensionThemeManager } from "./lib/extension/extension-theme-manager.js";
export default class ForgeExtension extends Extension {
enable() {
this.settings = this.getSettings();
this.kbdSettings = this.getSettings("org.gnome.shell.extensions.forge.keybindings");
Logger.init(this.settings);
Logger.info("enable");
this.configMgr = new ConfigManager(this);
this.theme = new ExtensionThemeManager(this);
this.extWm = new WindowManager(this);
this.keybindings = new Keybindings(this);
this._onSessionModeChanged(Main.sessionMode);
this._sessionId = Main.sessionMode.connect("updated", this._onSessionModeChanged.bind(this));
this.theme.patchCss();
this.theme.reloadStylesheet();
this.extWm.enable();
Logger.info(`enable: finalized vars`);
}
disable() {
Logger.info("disable");
// See session mode unlock-dialog explanation on _onSessionModeChanged()
if (this._sessionId) {
Main.sessionMode.disconnect(this._sessionId);
this._sessionId = null;
}
this._removeIndicator();
this.extWm?.disable();
this.keybindings?.disable();
this.keybindings = null;
this.extWm = null;
this.themeWm = null;
this.configMgr = null;
this.settings = null;
this.kbdSettings = null;
}
_onSessionModeChanged(session) {
if (session.currentMode === "user" || session.parentMode === "user") {
Logger.info("user on session change");
this._addIndicator();
this.keybindings?.enable();
} else if (session.currentMode === "unlock-dialog") {
// To the reviewer and maintainer: this extension needs to persist the window data structure in memory so it has to keep running on lock screen.
// This is previous feature but was removed during GNOME 45 update due to the session-mode rule review.
// The argument is that users will keep re-arranging windows when it times out or locks up.
// Intent to serialize/deserialize to disk but that will take a longer time or probably a longer argument during review.
// To keep following, added to only disable keybindings() and re-enable them during user session.
// https://gjs.guide/extensions/review-guidelines/review-guidelines.html#session-modes
Logger.info("lock-screen on session change");
this.keybindings?.disable();
this._removeIndicator();
}
}
_addIndicator() {
this.indicator ??= new FeatureIndicator(this);
this.indicator.quickSettingsItems.push(new FeatureMenuToggle(this));
Main.panel.statusArea.quickSettings.addExternalIndicator(this.indicator);
}
_removeIndicator() {
this.indicator?.quickSettingsItems.forEach((item) => item.destroy());
this.indicator?.destroy();
this.indicator = null;
}
}