🔧 Add initial code to disable on power-save mode

This commit is contained in:
Simon Schneegans
2023-01-07 13:02:22 +01:00
parent 581a045c69
commit e4aa5e7aae
3 changed files with 34 additions and 3 deletions
+17 -3
View File
@@ -88,6 +88,16 @@ class Extension {
this._upowerProxy = new UPowerProxy(Gio.DBus.system, 'org.freedesktop.UPower',
'/org/freedesktop/UPower');
// This is used to get the current power profile.
// Ab 41??
const PowerProfilesProxy = Gio.DBusProxy.makeProxyWrapper(
utils.getStringResource('/interfaces/net.hadess.PowerProfiles.xml'));
this._powerProfilesProxy = new PowerProfilesProxy(
Gio.DBus.system, 'net.hadess.PowerProfiles', '/net/hadess/PowerProfiles');
console.log(this._powerProfilesProxy);
console.log(this._powerProfilesProxy.get_connection());
// We will monkey-patch these methods. Let's store the original ones.
this._origAddWindowClone = Workspace.prototype._addWindowClone;
this._origWindowRemoved = Workspace.prototype._windowRemoved;
@@ -381,9 +391,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 == '') {
// We may have to do nothing if running on battery power or if in power-save mode.
let disableOnBattery =
this._settings.get_boolean('disable-on-battery') && this._upowerProxy.OnBattery;
let disableOnPowerSave = this._settings.get_boolean('disable-on-power-save') &&
this._powerProfilesProxy.ActiveProfile == 'power-saver';
if ((disableOnBattery || disableOnPowerSave) && previewNick == '') {
this._fixAnimationTimes(isDialogWindow, forOpening, null);
return;
}
@@ -0,0 +1,11 @@
<!--
SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
SPDX-License-Identifier: CC0-1.0
-->
<node>
<interface name="net.hadess.PowerProfiles">
<property name="ActiveProfile" type="s" access="read"/>
</interface>
</node>
@@ -25,6 +25,12 @@ SPDX-License-Identifier: CC0-1.0
<description>Enable effects only if plugged in.</description>
</key>
<key name="disable-on-power-save" type="b">
<default>false</default>
<summary>Disable on Power Save</summary>
<description>Enable effects only if power saver is disabled.</description>
</key>
<key name="close-preview-effect" type="s">
<default>""</default>
<summary>Close Preview Effect</summary>