Skip to content

Commit

Permalink
Even better workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
popov895 committed Apr 2, 2024
1 parent 9b5ca50 commit 0df6539
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
54 changes: 25 additions & 29 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
'use strict';

const { Gio, GLib } = imports.gi;
const { GLib } = imports.gi;

const Main = imports.ui.main;
const ExtensionUtils = imports.misc.extensionUtils;

class Extension {
enable() {
const dashToDockSettingsSchema = Gio.SettingsSchemaSource.get_default().lookup(
`org.gnome.shell.extensions.dash-to-dock`,
true
);
if (!dashToDockSettingsSchema) {
return;
this._applyWorkaround();
}

disable() {
if (this._workaroundTimeoutId) {
GLib.Source.remove(this._workaroundTimeoutId);
delete this._workaroundTimeoutId;
}
}

const values = {
'animation-time': GLib.Variant.new_double(0),
'dock-fixed': GLib.Variant.new_boolean(false),
};
_applyWorkaround() {
const extension = Main.extensionManager.lookup(`ubuntu-dock@ubuntu.com`);
if (!extension) {
return;
}

const dashToDockSettings = new Gio.Settings({
settings_schema: dashToDockSettingsSchema,
});
const dockManager = extension.imports.extension.dockManager;
if (!dockManager || !dockManager.settings.dockFixed) {
return;
}

const snapshot = {};
for (const key in values) {
snapshot[key] = dashToDockSettings.get_value(key);
dashToDockSettings.set_value(key, values[key]);
const mainDock = dockManager.mainDock;
if (!mainDock) {
return;
}

this._showDashToDockTimeoutId = GLib.timeout_add(
this._workaroundTimeoutId = GLib.timeout_add(
GLib.PRIORITY_DEFAULT,
ExtensionUtils.getSettings().get_int(`delay`),
() => {
for (const key in snapshot) {
dashToDockSettings.set_value(key, snapshot[key]);
}
mainDock._animateOut(0, 0);
mainDock._animateIn(dockManager.settings.animationTime, 0);
return GLib.SOURCE_REMOVE;
}
);
}

disable() {
if (this._showDashToDockTimeoutId) {
GLib.Source.remove(this._showDashToDockTimeoutId);
delete this._showDashToDockTimeoutId;
}
}
}

function init() {
Expand Down
4 changes: 2 additions & 2 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var fillPreferencesWindow = (window) => {

const delaySpinBox = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
lower: 0,
upper: 5000,
step_increment: 1,
}),
Expand All @@ -33,7 +33,7 @@ var fillPreferencesWindow = (window) => {

const delayRow = new Adw.ActionRow({
activatable_widget: delaySpinBox,
subtitle: _(`Delay in applying the workaround (a very short delay may not work)`),
subtitle: _(`Delay in applying the workaround (increase if it doesn't work for you)`),
title: _(`Delay (in milliseconds)`),
});
delayRow.add_suffix(delaySpinBox);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<schemalist>
<schema id="org.gnome.shell.extensions.dash-to-dock-workaround" path="/org/gnome/shell/extensions/dash-to-dock-workaround/">
<key name="delay" type="i">
<range min="1" max="5000"/>
<default>350</default>
<range min="0" max="5000"/>
<default>0</default>
</key>
</schema>
</schemalist>

0 comments on commit 0df6539

Please sign in to comment.