-
Notifications
You must be signed in to change notification settings - Fork 280
/
extension.js
133 lines (102 loc) · 4.39 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Dash-To-Panel extension for Gnome 3
* Copyright 2016 Jason DeRose (jderose9) and Charles Gagnon (charlesg99)
*
* 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 2 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/>.
*
*/
import Gio from 'gi://Gio';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import {EventEmitter} from 'resource:///org/gnome/shell/misc/signals.js';
import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
import * as PanelManager from './panelManager.js';
import * as AppIcons from './appIcons.js';
const UBUNTU_DOCK_UUID = 'ubuntu-dock@ubuntu.com';
let panelManager;
let extensionChangedHandler;
let startupCompleteHandler;
let disabledUbuntuDock;
let extensionSystem = Main.extensionManager;
export let DTP_EXTENSION = null;
export let SETTINGS = null;
export let DESKTOPSETTINGS = null;
export let TERMINALSETTINGS = null;
export let PERSISTENTSTORAGE = null;
export let EXTENSION_UUID = null;
export let EXTENSION_PATH = null;
export default class DashToPanelExtension extends Extension {
constructor(metadata) {
super(metadata);
this._realHasOverview = Main.sessionMode.hasOverview;
//create an object that persists until gnome-shell is restarted, even if the extension is disabled
PERSISTENTSTORAGE = {};
}
enable() {
DTP_EXTENSION = this;
// The Ubuntu Dock extension might get enabled after this extension
extensionChangedHandler = extensionSystem.connect('extension-state-changed', (data, extension) => {
if (extension.uuid === UBUNTU_DOCK_UUID && extension.state === 1) {
_enable(this);
}
});
//create a global object that can emit signals and conveniently expose functionalities to other extensions
global.dashToPanel = new EventEmitter();
_enable(this);
}
disable(reset = false) {
panelManager.disable();
DTP_EXTENSION = null;
SETTINGS = null;
DESKTOPSETTINGS = null;
TERMINALSETTINGS = null;
panelManager = null;
if (!reset) {
extensionSystem.disconnect(extensionChangedHandler);
if (disabledUbuntuDock) {
disabledUbuntuDock = false;
extensionSystem.enableExtension(UBUNTU_DOCK_UUID);
}
delete global.dashToPanel;
AppIcons.resetRecentlyClickedApp();
}
if (startupCompleteHandler) {
Main.layoutManager.disconnect(startupCompleteHandler);
startupCompleteHandler = null;
}
Main.sessionMode.hasOverview = this._realHasOverview;
}
}
function _enable(extension) {
let enabled = global.settings.get_strv('enabled-extensions');
if (enabled?.indexOf(UBUNTU_DOCK_UUID) >= 0) {
disabledUbuntuDock = true;
extensionSystem.disableExtension(UBUNTU_DOCK_UUID);
}
if (panelManager)
return panelManager.toggleDash(); // already initialized but ubuntu dock restored the original dash on disable
SETTINGS = extension.getSettings('org.gnome.shell.extensions.dash-to-panel');
DESKTOPSETTINGS = new Gio.Settings({schema_id: 'org.gnome.desktop.interface'});
TERMINALSETTINGS = new Gio.Settings({schema_id: 'org.gnome.desktop.default-applications.terminal'})
EXTENSION_UUID = extension.uuid
EXTENSION_PATH = extension.path
Main.layoutManager.startInOverview = !SETTINGS.get_boolean('hide-overview-on-startup');
if (SETTINGS.get_boolean('hide-overview-on-startup') && Main.layoutManager._startingUp) {
Main.sessionMode.hasOverview = false;
startupCompleteHandler = Main.layoutManager.connect('startup-complete', () => {
Main.sessionMode.hasOverview = extension._realHasOverview
});
}
panelManager = new PanelManager.PanelManager();
panelManager.enable();
}