🎉 Add option to disable effects if on battery power
This commit is contained in:
@@ -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).
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<node>
|
||||
<interface name="org.freedesktop.UPower">
|
||||
<property name="OnBattery" type="b" access="read" />
|
||||
</interface>
|
||||
</node>
|
||||
|
||||
@@ -227,6 +227,50 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="margin-start">10</property>
|
||||
<property name="margin-end">10</property>
|
||||
<property name="margin-top">10</property>
|
||||
<property name="margin-bottom">10</property>
|
||||
<property name="activatable">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="spacing">8</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label" translatable="yes">Disable on Battery Power</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">1</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="disable-on-battery">
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="reset-disable-on-battery">
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="icon-name">edit-clear-symbolic</property>
|
||||
<property name="icon-size">1</property>
|
||||
</object>
|
||||
</child>
|
||||
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
||||
@@ -174,6 +174,40 @@
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkListBoxRow">
|
||||
<property name="activatable">0</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label" translatable="yes">Disable on Battery Power</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">1</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="disable-on-battery">
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">center</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="reset-disable-on-battery">
|
||||
<property name="icon-name">edit-clear-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Reset to Default Value</property>
|
||||
<style>
|
||||
<class name="flat" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
<description>Set to true to burn dialogs as well.</description>
|
||||
</key>
|
||||
|
||||
<key name="disable-on-battery" type="b">
|
||||
<default>false</default>
|
||||
<summary>Disable on Battery</summary>
|
||||
<description>Enable effects only if plugged in.</description>
|
||||
</key>
|
||||
|
||||
<key name="close-preview-effect" type="s">
|
||||
<default>""</default>
|
||||
<summary>Close Preview Effect</summary>
|
||||
|
||||
+9
-1
@@ -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.
|
||||
@@ -84,3 +85,10 @@ 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));
|
||||
}
|
||||
Reference in New Issue
Block a user