-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
211 lines (200 loc) · 6.85 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
/** Gnome libs imports */
const { GLib, St, Gio } = imports.gi;
const Main = imports.ui.main;
const Signals = imports.signals;
/** Extension imports */
const Me = imports.misc.extensionUtils.getCurrentExtension();
const {
DisableIncompatibleExtensionsModule,
} = Me.imports.src.module.disableIncompatibleExtensionsModule;
const { OverrideModule } = Me.imports.src.module.overrideModule;
const { HotKeysModule } = Me.imports.src.module.hotKeysModule;
const { RequiredSettingsModule } = Me.imports.src.module.requiredSettingsModule;
const { LayoutManager } = Me.imports.src.manager.layoutManager;
const { StateManager } = Me.imports.src.manager.stateManager;
const { MsWindowManager } = Me.imports.src.manager.msWindowManager;
const { MsWorkspaceManager } = Me.imports.src.manager.msWorkspaceManager;
const { MsThemeManager } = Me.imports.src.manager.msThemeManager;
const { TooltipManager } = Me.imports.src.manager.tooltipManager;
const { MsMain } = Me.imports.src.layout.main;
const { MsNotificationManager } = Me.imports.src.manager.msNotificationManager;
const { getSettings } = Me.imports.src.utils.settings;
let disableIncompatibleExtensionsModule,
modules,
_startupPreparedId,
_splashscreenTimeoutId,
splashscreenCalled;
let splashScreens = [];
// eslint-disable-next-line no-unused-vars
function init() {
log('--------------');
log('INIT EXTENSION');
log('--------------');
Signals.addSignalMethods(Me);
global.ms = Me;
Me.showSplashScreens = showSplashScreens;
Me.hideSplashScreens = hideSplashScreens;
Me.closing = false;
Me.locked = false;
splashscreenCalled = false;
//St.set_slow_down_factor(10);
global.display.connect('closing', () => {
Me.closing = true;
});
}
// eslint-disable-next-line no-unused-vars
function enable() {
log('----------------');
log('ENABLE EXTENSION');
log('----------------');
if (Me.locked) {
Me.locked = false;
Me.layout.panel.enable();
return;
}
Me.imports.src.utils.debug.init();
Me.monitorsLength = Main.layoutManager.monitors.length;
// Show a splashscreen while we are updating the UI layout and theme
// if (Main.layoutManager._startingUp) {
// Me.showSplashScreens();
// }
Me.loaded = false;
Me.stateManager = new StateManager();
GLib.idle_add(GLib.PRIORITY_LOW, () => {
//Then disable incompatibles extensions;
disableIncompatibleExtensionsModule = new DisableIncompatibleExtensionsModule();
//Load persistent data
Me.stateManager.loadRegistry((state) => {
modules = [new RequiredSettingsModule(), new OverrideModule()];
Me.tooltipManager = new TooltipManager();
Me.layoutManager = new LayoutManager();
Me.msWindowManager = new MsWindowManager();
Me.msWorkspaceManager = new MsWorkspaceManager(
state['workspaces-state']
);
Me.msNotificationManager = new MsNotificationManager();
modules = [...modules, (Me.hotKeysModule = new HotKeysModule())];
Me.msThemeManager = new MsThemeManager();
Me.msThemeManager.regenerateStylesheet();
if (getSettings('tweaks').get_boolean('enable-persistence')) {
Me.msWorkspaceManager.restorePreviousState();
} else {
Me.msWorkspaceManager.initState();
}
new MsMain();
Me.msWindowManager.handleExistingMetaWindow();
if (Main.layoutManager._startingUp) {
_startupPreparedId = Main.layoutManager.connect(
'startup-complete',
() => loaded(true)
);
} else {
loaded(false);
}
});
return GLib.SOURCE_REMOVE;
});
}
function loaded(disconnect) {
log('----------------');
log('EXTENSION LOADED');
log('----------------');
if (disconnect) {
Main.layoutManager.disconnect(_startupPreparedId);
}
Me.loaded = true;
Me.locked = false;
Me.emit('extension-loaded');
Me.msNotificationManager.check();
if (splashscreenCalled) {
if (_splashscreenTimeoutId) {
GLib.source_remove(_splashscreenTimeoutId);
_splashscreenTimeoutId = 0;
}
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
hideSplashScreens();
return GLib.SOURCE_REMOVE;
});
}
log('--------------------');
log('END EXTENSION LOADED');
log('--------------------');
}
// eslint-disable-next-line no-unused-vars
function disable() {
log('-----------------');
log('DISABLE EXTENSION');
log('-----------------');
if (Main.sessionMode.currentMode === 'unlock-dialog') {
Me.locked = true;
Me.layout.panel.disable();
} else {
Me.disableInProgress = true;
if (!modules) return;
Me.emit('extension-disable');
modules.reverse().forEach((module) => {
module.destroy();
});
Me.tooltipManager.destroy();
Me.layoutManager.destroy();
Me.msWorkspaceManager.destroy();
Me.msWindowManager.destroy();
Me.layout.destroy();
Me.msThemeManager.destroy();
disableIncompatibleExtensionsModule.destroy();
Me.stateManager.destroy();
Me.loaded = false;
delete Me.disableInProgress;
}
log('---------------------');
log('END DISABLE EXTENSION');
log('---------------------');
}
function showSplashScreens() {
log('show splashscreen');
splashscreenCalled = true;
Main.layoutManager.monitors.forEach((monitor) => {
let icon = new St.Icon({
gicon: Gio.icon_new_for_string(
`${Me.path}/assets/icons/on-dark-small.svg`
),
icon_size: 200,
});
let splashscreen = new St.Bin({
style_class: 'ms-splashscreen',
style: 'background: rgb(25,25,25)',
child: icon,
x: monitor.x,
y: monitor.y,
width: monitor.width,
height: monitor.height,
});
Main.layoutManager.addChrome(splashscreen);
splashScreens.push(splashscreen);
});
_splashscreenTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
5000,
() => {
_splashscreenTimeoutId = 0;
hideSplashScreens();
return GLib.SOURCE_REMOVE;
}
);
}
function hideSplashScreens() {
if (splashScreens.length < 1) return;
splashScreens.forEach((splashscreen) => {
splashscreen.ease({
opacity: 0,
duration: 800,
transition: 'easeInQuad',
onComplete: () => {
Main.layoutManager.removeChrome(splashscreen);
splashscreen.destroy();
},
});
});
splashScreens = [];
splashscreenCalled = false;
}