diff --git a/extension.js b/extension.js index b61f168..26cca45 100644 --- a/extension.js +++ b/extension.js @@ -73,6 +73,12 @@ class Extension { // We will use extensionThis to refer to the extension inside the patched methods. const extensionThis = this; + // This is used to get the battery state. + const UPowerProxy = Gio.DBusProxy.makeProxyWrapper( + utils.getStringResource('/interfaces/org.freedesktop.UPower.xml')); + this._upowerProxy = new UPowerProxy(Gio.DBus.system, 'org.freedesktop.UPower', + '/org/freedesktop/UPower'); + // We will monkey-patch these methods. Let's store the original ones. this._origAddWindowClone = Workspace.prototype._addWindowClone; this._origWindowRemoved = Workspace.prototype._windowRemoved; @@ -365,6 +371,13 @@ class Extension { return; } + // We may have to do nothing if running on battery power. + if (this._settings.get_boolean('disable-on-battery') && this._upowerProxy.OnBattery && + previewNick == '') { + this._fixAnimationTimes(isDialogWindow, forOpening, null); + return; + } + // There is the weird case where an animation is already ongoing. This happens when a // window is closed which has been created before the session was started (e.g. when // GNOME Shell has been restarted in the meantime). diff --git a/prefs.js b/prefs.js index bb45daa..ef0a373 100644 --- a/prefs.js +++ b/prefs.js @@ -14,7 +14,6 @@ 'use strict'; const {Gio, Gtk, Gdk, GLib, GObject} = imports.gi; -const ByteArray = imports.byteArray; // libadwaita is available starting with GNOME Shell 42. let Adw = null; @@ -95,7 +94,7 @@ var PreferencesDialog = class PreferencesDialog { // Bind general options properties. this.bindSwitch('destroy-dialogs'); - + this.bindSwitch('disable-on-battery'); // Starting with GNOME Shell 42, the settings dialog uses libadwaita (at least most of // the time - it seems that pop!_OS does not support libadwaita even on GNOME 42). We @@ -460,9 +459,7 @@ var PreferencesDialog = class PreferencesDialog { // Reads the contents of a JSON file contained in the global resources archive. The data // is parsed and returned as a JavaScript object / array. _getJSONResource(path) { - const data = Gio.resources_lookup_data(path, 0); - const string = ByteArray.toString(ByteArray.fromGBytes(data)); - return JSON.parse(string); + return JSON.parse(utils.getStringResource(path)); } // This traverses the widget tree below the given parent recursively and returns the diff --git a/resources/interfaces/org.freedesktop.UPower.xml b/resources/interfaces/org.freedesktop.UPower.xml new file mode 100644 index 0000000..aadb03f --- /dev/null +++ b/resources/interfaces/org.freedesktop.UPower.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/resources/ui/gtk3/prefs.ui b/resources/ui/gtk3/prefs.ui index 28859dd..02807ae 100644 --- a/resources/ui/gtk3/prefs.ui +++ b/resources/ui/gtk3/prefs.ui @@ -227,6 +227,50 @@ + + + 10 + 10 + 10 + 10 + 0 + + + 8 + + + Disable on Battery Power + 0 + start + center + 1 + + + + + end + center + + + + + + + edit-clear-symbolic + 1 + + + Reset to Default Value + + + + + + + + diff --git a/resources/ui/gtk4/prefs.ui b/resources/ui/gtk4/prefs.ui index 2b5778f..f9632da 100644 --- a/resources/ui/gtk4/prefs.ui +++ b/resources/ui/gtk4/prefs.ui @@ -174,6 +174,40 @@ + + + 0 + + + + + Disable on Battery Power + 0 + start + center + 1 + + + + + end + center + + + + + edit-clear-symbolic + Reset to Default Value + + + + + + + + diff --git a/schemas/org.gnome.shell.extensions.burn-my-windows.gschema.xml b/schemas/org.gnome.shell.extensions.burn-my-windows.gschema.xml index f852dad..7444661 100644 --- a/schemas/org.gnome.shell.extensions.burn-my-windows.gschema.xml +++ b/schemas/org.gnome.shell.extensions.burn-my-windows.gschema.xml @@ -13,6 +13,12 @@ Set to true to burn dialogs as well. + + false + Disable on Battery + Enable effects only if plugged in. + + "" Close Preview Effect diff --git a/src/utils.js b/src/utils.js index 9f528d8..b6fee63 100644 --- a/src/utils.js +++ b/src/utils.js @@ -13,7 +13,8 @@ 'use strict'; -const {Gtk} = imports.gi; +const {Gtk, Gio} = imports.gi; +const ByteArray = imports.byteArray; // Returns the given argument, except for "alpha", "beta", and "rc". In these cases -3, // -2, and -1 are returned respectively. @@ -83,4 +84,11 @@ function shellVersionIsAtLeast(major, minor) { } return false; +} + +// Reads the contents of a file contained in the global resources archive. The data +// is returned as a string. +function getStringResource(path) { + const data = Gio.resources_lookup_data(path, 0); + return ByteArray.toString(ByteArray.fromGBytes(data)); } \ No newline at end of file