Skip to content

Commit

Permalink
power-profiles@rcalixte: Version 1.1 (#6428)
Browse files Browse the repository at this point in the history
* Added a new option to choose the icon style
* Added a notification if the system package `power-profiles-daemon` is not
installed
* Updated URLs in the README

* Closes #6426
  • Loading branch information
rcalixte authored Sep 15, 2024
1 parent 6829b6e commit 5793ca8
Show file tree
Hide file tree
Showing 21 changed files with 1,754 additions and 165 deletions.
9 changes: 8 additions & 1 deletion power-profiles@rcalixte/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@

### 1.1

* Added a new option to choose the icon style
* Added a notification if the system package `power-profiles-daemon` is not
installed
* Updated URLs in the README

### 1.0.1

* Fixing a minor bug
* Fixed a minor bug
* Markdown cleanup
* Minor screenshot edit

Expand Down
69 changes: 0 additions & 69 deletions power-profiles@rcalixte/README.md

This file was deleted.

1 change: 1 addition & 0 deletions power-profiles@rcalixte/README.md
65 changes: 53 additions & 12 deletions power-profiles@rcalixte/files/power-profiles@rcalixte/5.4/applet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const Applet = imports.ui.applet;
const GLib = imports.gi.GLib;
const Main = imports.ui.main;
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;
const PopupMenu = imports.ui.popupMenu;
const Settings = imports.ui.settings;
const St = imports.gi.St;
Expand Down Expand Up @@ -49,9 +50,38 @@ PowerProfilesApplet.prototype = {

this.setAllowedLayout(Applet.AllowedLayout.BOTH);

this.metadata = metadata;
this._profilesProxy = null;
this._proxyId = 0;

if (!GLib.find_program_in_path("powerprofilesctl")) {
let source = new MessageTray.Source(this.metadata.name);
let params = { icon: new St.Icon({ icon_name: "dialog-error-symbolic", icon_size: 48 }) };
let notification = new MessageTray.Notification(source, _("Power Profiles Applet Error"),
_("The system package 'power-profiles-daemon' is not installed.\n\nPlease install it and reload the applet."), params);

notification.addButton("open-readme", _("Open README"));
notification.addButton("open-website", _("Open Website"));
notification.connect("action-invoked", (self, action) => {
let launcher = new Gio.SubprocessLauncher({
flags: (Gio.SubprocessFlags.STDIN_PIPE |
Gio.SubprocessFlags.STDOUT_PIPE |
Gio.SubprocessFlags.STDERR_PIPE)
});

if (action == "open-readme") {
launcher.spawnv(["open", `${metadata.path}/../README.md`]);
} else if (action == "open-website") {
launcher.spawnv(["open",
"https://github.com/linuxmint/cinnamon-spices-applets/tree/master/power-profiles@rcalixte#dependencies"]);
}
});

Main.messageTray.add(source);
source.notify(notification);
return;
}

try {
this._profilesProxy = new PowerProfilesProxy(Gio.DBus.system, BUS_NAME, BUS_PATH);
} catch (error) {
Expand All @@ -65,15 +95,19 @@ PowerProfilesApplet.prototype = {
return;
}

this.settings = new Settings.AppletSettings(this, UUID, instance_id);
this.settings.bind("previousProfileKey", "previousProfileKey", this._setKeybinding);
this.settings.bind("nextProfileKey", "nextProfileKey", this._setKeybinding);
this.settings.bind("cycleProfiles", "cycleProfiles");
this.settings.bind("showOSD", "showOSD");
this.settings.bind("iconStyle", "iconStyle", this._onIconStyleChanged);

this.ActiveProfile = this._profilesProxy.ActiveProfile;
this.PerformanceDegraded = this._profilesProxy.PerformanceDegraded;
this.Profiles = this._profilesProxy.Profiles;
this.ActiveProfileHolds = this._profilesProxy.ActiveProfileHolds;
this.iconMap = new Map();
this.iconMap.set(this.Profiles[0].Profile.unpack(), metadata.path + "/../icons/profile-0-symbolic.svg");
this.iconMap.set(this.Profiles.slice(-1)[0].Profile.unpack(), metadata.path + "/../icons/profile-100-symbolic.svg");
if (this.iconMap.size != this.Profiles.length)
this.iconMap.set(this.Profiles[1].Profile.unpack(), metadata.path + "/../icons/profile-50-symbolic.svg");

this._setIconMap();

this._proxyId = this._profilesProxy.connect("g-properties-changed", (proxy, changed, invalidated) => {
for (let [changedProperty, changedValue] of Object.entries(changed.deepUnpack())) {
Expand All @@ -90,12 +124,6 @@ PowerProfilesApplet.prototype = {

this._updateApplet();
this.set_show_label_in_vertical_panels(false);

this.settings = new Settings.AppletSettings(this, UUID, instance_id);
this.settings.bind("previousProfileKey", "previousProfileKey", this._setKeybinding);
this.settings.bind("nextProfileKey", "nextProfileKey", this._setKeybinding);
this.settings.bind("cycleProfiles", "cycleProfiles");
this.settings.bind("showOSD", "showOSD");
this._setKeybinding();
},

Expand Down Expand Up @@ -207,6 +235,19 @@ PowerProfilesApplet.prototype = {

on_applet_clicked(event) {
this.menu.toggle();
},

_onIconStyleChanged() {
this._setIconMap();
this._updateApplet();
},

_setIconMap() {
this.iconMap = new Map();
this.iconMap.set(this.Profiles[0].Profile.unpack(), this.metadata.path + `/../icons/${this.iconStyle}/profile-0-symbolic.svg`);
this.iconMap.set(this.Profiles.slice(-1)[0].Profile.unpack(), this.metadata.path + `/../icons/${this.iconStyle}/profile-100-symbolic.svg`);
if (this.iconMap.size != this.Profiles.length)
this.iconMap.set(this.Profiles[1].Profile.unpack(), this.metadata.path + `/../icons/${this.iconStyle}/profile-50-symbolic.svg`);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,19 @@
"default": true,
"description": "On-screen display for keyboard shortcuts",
"tooltip": "Show on-screen display of the new profile when using the keyboard shortcuts"
},
"section2": {
"type": "section",
"description": "Appearance"
},
"iconStyle": {
"type": "combobox",
"default": "classic",
"description": "Icon Style",
"options": {
"Classic": "classic",
"Papirus": "papirus"
},
"tooltip": "Choose the style of the applet's icon. This is used for the panel and the on-screen display."
}
}
69 changes: 69 additions & 0 deletions power-profiles@rcalixte/files/power-profiles@rcalixte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
POWER PROFILES
==============

An applet to modify the current system power profile as determined by
`power-profiles-daemon` (accessible via the command-line as `powerprofilesctl`
if installed correctly)

DESCRIPTION
-----------

This is an applet that will set the profile via the input menu or keyboard
shortcuts.

The following options are selectable from the applet menu (see the screenshot):

* Power Saver
* Balanced
* Performance (if available)

There are two customizable keyboard shortcuts for switching profiles:

* Previous profile
* Next profile

There are also settings for customizing the operation of the keyboard
shortcuts:

* Cycle through profiles when using keyboard shortcuts (Default: `false`)

This will determine whether the keyboard shortcuts will cycle through the
available system power profiles.
_Example:_ The current profile is 'Power Saver' and the keyboard shortcut for
'Previous profile' is entered. If this option is set to `false`, the profile
will stay set at 'Power Saver' and if the option is set to `true`, the
profile will change to 'Performance' if it is available or 'Balanced'
otherwise.

* On-screen display for keyboard shortcuts (Default: `true`)

This will control whether there is an on-screen display (see the screenshot)
if a keyboard shortcut defined via the applet configuration settings is
entered. Similar to volume and other system on-screen displays, even if the
option to cycle is set to `false` and the profile is unchanged by the keyboard
shortcut, the on-screen display will still be shown.

COMPATIBILITY
-------------

This applet has been tested to be compatible with Cinnamon 5.6+ but is
supported for Cinnamon 5.4+.

DEPENDENCIES
------------

This applet depends on the following packages being installed:

* [power-profiles-daemon](https://gitlab.freedesktop.org/upower/power-profiles-daemon)

On Debian-based, Arch-based, Fedora-based, and Gentoo-based systems, the
package is available in the default repositories as `power-profiles-daemon`.

KNOWN ISSUES
------------

The `power-profiles-daemon` package and daemon conflicts with TLP and other
similar applications - there should only be one such tool installed and
running to ensure overall stability.

[READ MORE](https://gitlab.freedesktop.org/upower/power-profiles-daemon#conflicts)
Loading

0 comments on commit 5793ca8

Please sign in to comment.