-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.js
274 lines (238 loc) · 9.78 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
* Arc Menu - A traditional application menu for GNOME 3
*
* Arc Menu Lead Developer
* Andrew Zaech https://gitlab.com/AndrewZaech
*
* Arc Menu Founder/Maintainer/Graphic Designer
* LinxGem33 https://gitlab.com/LinxGem33
*
* 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/>.
*/
const Me = imports.misc.extensionUtils.getCurrentExtension();
const {GLib, Gio, St} = imports.gi;
const Constants = Me.imports.constants;
const Controller = Me.imports.controller;
const Convenience = Me.imports.convenience;
const Main = imports.ui.main;
const Util = imports.misc.util;
const Utils = Me.imports.utils;
// Initialize panel button variables
let settings;
let settingsControllers;
let extensionChangedId;
let dockToggleID;
let dockExtension;
// Initialize menu language translations
function init(metadata) {
Convenience.initTranslations(Me.metadata['gettext-domain']);
}
// Enable the extension
function enable() {
if(imports.gi.Meta.is_wayland_compositor())
Me.metadata.isWayland = true;
else
Me.metadata.isWayland = false;
let stylesheet = Utils.getStylesheet();
let theme = St.ThemeContext.get_for_stage(global.stage).get_theme();
if(Me.stylesheet)
theme.unload_stylesheet(Me.stylesheet);
Me.stylesheet = stylesheet;
theme.load_stylesheet(Me.stylesheet);
settings = Convenience.getSettings(Me.metadata['settings-schema']);
settings.connect('changed::multi-monitor', () => _onMultiMonitorChange());
settings.connect('changed::arc-menu-placement', () => _onArcMenuPlacementChange());
settingsControllers = [];
let boolArray = settings.get_default_value('dtp-dtd-state').deep_unpack();
settings.set_value('dtp-dtd-state', new GLib.Variant('ab', boolArray));
_enableButtons();
// dash to panel might get enabled after Arc-Menu
extensionChangedId = Main.extensionManager.connect('extension-state-changed', (data, extension) => {
if (extension.uuid === '[email protected]') {
let arcMenuPlacement = settings.get_enum('arc-menu-placement');
if(extension.state === 1){
this.set_DtD_DtP_State(Constants.EXTENSION.DTP, true);
if(arcMenuPlacement == Constants.ArcMenuPlacement.PANEL || arcMenuPlacement == Constants.ArcMenuPlacement.DTP){
_connectDtpSignals();
_enableButtons();
}
}
else if(extension.state === 2) {
this.set_DtD_DtP_State(Constants.EXTENSION.DTP, false);
}
}
if ((extension.uuid === "[email protected]" || extension.uuid === "[email protected]") && (extension.state === 1 || extension.state === 2)) {
_disconnectDtdSignals();
let state = extension.state === 1 ? true : false;
this.set_DtD_DtP_State(Constants.EXTENSION.DTD, state);
let arcMenuPlacement = settings.get_enum('arc-menu-placement');
if(arcMenuPlacement == Constants.ArcMenuPlacement.DASH){
for (let i = settingsControllers.length - 1; i >= 0; --i) {
let sc = settingsControllers[i];
_disableButton(sc, 1);
}
_enableButtons();
_connectDtdSignals();
}
}
});
// listen to dash to panel / dash to dock if they are compatible and already enabled
_connectDtdSignals();
_connectDtpSignals();
}
function set_DtD_DtP_State(extension, state){
let boolArray = settings.get_value('dtp-dtd-state').deep_unpack();
if(boolArray[extension] !== state){
boolArray[extension] = state;
settings.set_value('dtp-dtd-state', new GLib.Variant('ab', boolArray));
}
}
// Disable the extension
function disable() {
if ( extensionChangedId > 0){
Main.extensionManager.disconnect(extensionChangedId);
extensionChangedId = 0;
}
_disconnectDtpSignals();
_disconnectDtdSignals();
for (let i = settingsControllers.length - 1; i >= 0; --i) {
let sc = settingsControllers[i];
_disableButton(sc, 1);
}
settingsControllers = null;
settings.run_dispose();
settings = null;
}
function _connectDtpSignals() {
if (global.dashToPanel) {
global.dashToPanel._amPanelsCreatedId = global.dashToPanel.connect('panels-created', () => _enableButtons());
}
}
function _disconnectDtpSignals() {
if (global.dashToPanel && global.dashToPanel._amPanelsCreatedId) {
global.dashToPanel.disconnect(global.dashToPanel._amPanelsCreatedId);
delete global.dashToPanel._amPanelsCreatedId;
}
}
function _connectDtdSignals(){
dockExtension = _getDockExtensions();
if(dockExtension){
let dock = dockExtension.stateObj.dockManager;
dockToggleID = dock.connect("toggled",() => {
for (let i = settingsControllers.length - 1; i >= 0; --i) {
let sc = settingsControllers[i];
_disableButton(sc, 1);
}
_enableButtons();
});
}
}
function _disconnectDtdSignals() {
if(dockExtension){
let dock = dockExtension.stateObj.dockManager;
if(dock && dockToggleID){
dock.disconnect(dockToggleID);
dockToggleID = null;
}
}
}
function _onArcMenuPlacementChange() {
let arcMenuPlacement = settings.get_enum('arc-menu-placement');
if(arcMenuPlacement == Constants.ArcMenuPlacement.PANEL || arcMenuPlacement == Constants.ArcMenuPlacement.DTP){
_disconnectDtdSignals();
_connectDtpSignals();
}
else{
_disconnectDtpSignals();
_connectDtdSignals();
}
for (let i = settingsControllers.length - 1; i >= 0; --i) {
let sc = settingsControllers[i];
_disableButton(sc, 1);
}
_enableButtons();
}
function _onMultiMonitorChange() {
for (let i = settingsControllers.length - 1; i >= 0; --i) {
let sc = settingsControllers[i];
_disableButton(sc, 1);
}
_enableButtons();
}
function _getDockExtensions(){
let dashToDock = Main.extensionManager.lookup("[email protected]");
let ubuntuDash = Main.extensionManager.lookup("[email protected]");
let dock;
if(dashToDock && dashToDock.stateObj && dashToDock.stateObj.dockManager){
dock = dashToDock;
}
if(ubuntuDash && ubuntuDash.stateObj && ubuntuDash.stateObj.dockManager){
dock = ubuntuDash;
}
return dock;
}
function _enableButtons() {
let multiMonitor = settings.get_boolean('multi-monitor');
dockExtension = _getDockExtensions();
let arcMenuPlacement = settings.get_enum('arc-menu-placement');
if(arcMenuPlacement == Constants.ArcMenuPlacement.DASH && dockExtension){
this.set_DtD_DtP_State(Constants.EXTENSION.DTD, true);
let panel = dockExtension.stateObj.dockManager;
if(panel){
if(panel._allDocks.length){
let iterLength = multiMonitor ? panel._allDocks.length : 1;
for(var index = 0; index < iterLength; index++){
if(!panel._allDocks[index].dash.arcMenuEnabled){
let settingsController = new Controller.MenuSettingsController(settings, settingsControllers, panel, index, Constants.ArcMenuPlacement.DASH);
settingsController.enableButton(index);
settingsController.bindSettingsChanges();
settingsControllers.push(settingsController);
}
}
}
}
}
else{
let panelArray = global.dashToPanel ? global.dashToPanel.panels.map(pw => pw.panel || pw) : [Main.panel];
let iterLength = multiMonitor ? panelArray.length : 1;
for(var index = 0; index < iterLength; index++){
let panel = panelArray[index];
if(global.dashToPanel) this.set_DtD_DtP_State(Constants.EXTENSION.DTP, true);
let isMainPanel = ('isSecondary' in panel && !panel.isSecondary) || panel == Main.panel;
if (panel.statusArea['arc-menu'])
continue;
else if (settingsControllers[index])
_disableButton(settingsControllers[index], 1);
// Create a Menu Controller that is responsible for controlling
// and managing the menu as well as the menu button.
let settingsController = new Controller.MenuSettingsController(settings, settingsControllers, panel, isMainPanel, Constants.ArcMenuPlacement.PANEL);
if (!isMainPanel) {
panel._amDestroyId = panel.connect('destroy', () => extensionChangedId ? _disableButton(settingsController, 1) : null);
}
settingsController.enableButton();
settingsController.bindSettingsChanges();
settingsControllers.push(settingsController);
}
}
}
function _disableButton(controller, remove) {
if (controller.panel._amDestroyId) {
controller.panel.disconnect(controller.panel._amDestroyId);
delete controller.panel._amDestroyId;
}
controller.destroy();
if (remove) {
settingsControllers.splice(settingsControllers.indexOf(controller), 1);
}
}