This commit is contained in:
2024-07-08 22:46:35 +02:00
parent 02f44c49d2
commit 27254d817a
56249 changed files with 808097 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
export var powerProfileIndicatorExtensionInstance;
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import * as Log from './modules/log.js';
import * as Panel from './modules/panel.js';
import * as Resources from './modules/resources.js';
export default class PowerProfileIndicatorExtension extends Extension {
constructor(metadata) {
super(metadata);
this.PowerProfileIndicatorInstance = null;
this.systemMenu = null;
Resources.File.extensionPath = this.path;
powerProfileIndicatorExtensionInstance = this;
}
enable() {
this.systemMenu = Main.panel.statusArea.quickSettings;
if (!this.systemMenu) {
Log.raw("init", "system menu is not defined");
return false;
}
if (this.systemMenu._powerProfiles) {
this.PowerProfileIndicatorInstance = new Panel.powerProfileIndicator();
}
}
disable() {
if (this.PowerProfileIndicatorInstance) {
this.PowerProfileIndicatorInstance.stop();
if (this.PowerProfileIndicatorInstance._indicator)
this.PowerProfileIndicatorInstance._indicator.destroy();
this.PowerProfileIndicatorInstance._indicator = null;
this.PowerProfileIndicatorInstance.destroy();
this.PowerProfileIndicatorInstance = null;
}
}
populate() {
if (this.PowerProfileIndicatorInstance !== null) {
if (this.systemMenu._system)
this.systemMenu._indicators.remove_child(this.systemMenu._system);
this.systemMenu._indicators.add_child(this.PowerProfileIndicatorInstance);
if (this.systemMenu._system)
this.systemMenu._indicators.add_child(this.systemMenu._system);
}
}
}
//# sourceMappingURL=extension.js.map

View File

@@ -0,0 +1,13 @@
{
"_generated": "Generated by SweetTooth, do not edit",
"description": "a simple indicator in the system icons area of the top panel that represent the current power profile",
"name": "power-profile-indicator",
"shell-version": [
"45",
"46"
],
"url": "",
"uuid": "power-profile-indicator@laux.wtf",
"uuid-dev": "power-profile-indicator-dev@laux.wtf",
"version": 10
}

View File

@@ -0,0 +1,8 @@
export function raw(text = "", e = null) {
if (e !== null)
logError(e, `power-profile-indicator: ${text}`);
else {
log(`power-profile-indicator: ${text}`);
}
}
//# sourceMappingURL=log.js.map

View File

@@ -0,0 +1,72 @@
import Gio from 'gi://Gio';
import GObject from 'gi://GObject';
import * as quickSettings from 'resource:///org/gnome/shell/ui/quickSettings.js';
import * as Log from './log.js';
import * as Resources from './resources.js';
import * as Extension from '../extension.js';
const PROFILE_ICONS = {
"performance": "power-profile-performance-symbolic",
"balanced": "power-profile-balanced-symbolic",
"power-saver": "power-profile-power-saver-symbolic"
};
export const powerProfileIndicator = GObject.registerClass(class powerProfileIndicator extends quickSettings.SystemIndicator {
constructor() {
super(...arguments);
this.powerProfilesProxy = null;
this.powerProfilesSignalProxy = null;
this.connected = false;
this._state = "balanced";
this.profiles = [];
}
_init() {
super._init();
this.createProxy();
}
async createProxy() {
this._indicator = this._addIndicator();
this._indicator.icon_name = "power-profile-balanced-symbolic";
this._indicator.visible = true;
let xmlProfiles = Resources.File.DBus("net.hadess.PowerProfiles-0.10.1");
this.powerProfilesProxy = await new Gio.DBusProxy.makeProxyWrapper(xmlProfiles)(Gio.DBus.system, "net.hadess.PowerProfiles", "/net/hadess/PowerProfiles", (proxy, e) => {
try {
this.connected = true;
if (this.updateProfile())
Extension.powerProfileIndicatorExtensionInstance.populate();
}
catch (error) {
Log.raw('could not get ActiveProfile', error);
}
});
let xmlSignals = Resources.File.DBus("net.hadess.PowerProfilesSignals-0.10.1");
this.powerProfilesSignalProxy = await new Gio.DBusProxy.makeProxyWrapper(xmlSignals)(Gio.DBus.system, "org.freedesktop.DBus.Properties", "/net/hadess/PowerProfiles", (proxy, e) => {
try {
proxy.connectSignal("PropertiesChanged", (name = "", variant, profile) => {
this.updateProfile();
});
}
catch (error) {
Log.raw('error creating signal', error);
}
});
}
updateProfile() {
if (this.connected)
try {
this._state = this.powerProfilesProxy.ActiveProfile;
if (typeof this._state !== 'string')
return false;
this._indicator.icon_name = PROFILE_ICONS[this._state];
return true;
}
catch (error) {
Log.raw("updateProfile", error);
}
return false;
}
stop() {
this.connected = false;
this.powerProfilesProxy = null;
this.powerProfilesSignalProxy = null;
}
});
//# sourceMappingURL=panel.js.map

View File

@@ -0,0 +1,17 @@
import GLib from 'gi://GLib';
import * as Log from './log.js';
export class File {
static DBus(name) {
let file = `${File.extensionPath}/resources/dbus/${name}.xml`;
try {
let [_ok, bytes] = GLib.file_get_contents(file);
if (!_ok)
Log.raw(`Couldn't read contents of "${file}"`);
return _ok ? imports.byteArray.toString(bytes) : null;
}
catch (e) {
Log.raw(`Failed to load "${file}"`, e);
}
}
}
//# sourceMappingURL=resources.js.map

View File

@@ -0,0 +1,37 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.70.2 -->
<node name="/net/hadess/PowerProfiles">
<interface name="net.hadess.PowerProfiles">
<method name="HoldProfile">
<arg type="s" name="profile" direction="in">
</arg>
<arg type="s" name="reason" direction="in">
</arg>
<arg type="s" name="application_id" direction="in">
</arg>
<arg type="u" name="cookie" direction="out">
</arg>
</method>
<method name="ReleaseProfile">
<arg type="u" name="cookie" direction="in">
</arg>
</method>
<signal name="ProfileReleased">
<arg type="u" name="cookie">
</arg>
</signal>
<property type="s" name="ActiveProfile" access="readwrite">
</property>
<property type="s" name="PerformanceInhibited" access="read">
</property>
<property type="s" name="PerformanceDegraded" access="read">
</property>
<property type="aa{sv}" name="Profiles" access="read">
</property>
<property type="as" name="Actions" access="read">
</property>
<property type="aa{sv}" name="ActiveProfileHolds" access="read">
</property>
</interface>
</node>

View File

@@ -0,0 +1,26 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.70.2 -->
<node name="/net/hadess/PowerProfiles">
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg type="s" name="interface_name" direction="in"/>
<arg type="s" name="property_name" direction="in"/>
<arg type="v" name="value" direction="out"/>
</method>
<method name="GetAll">
<arg type="s" name="interface_name" direction="in"/>
<arg type="a{sv}" name="properties" direction="out"/>
</method>
<method name="Set">
<arg type="s" name="interface_name" direction="in"/>
<arg type="s" name="property_name" direction="in"/>
<arg type="v" name="value" direction="in"/>
</method>
<signal name="PropertiesChanged">
<arg type="s" name="interface_name"/>
<arg type="a{sv}" name="changed_properties"/>
<arg type="as" name="invalidated_properties"/>
</signal>
</interface>
</node>