Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gnome 46 support #223

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .Rhistory
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
*.log
.pgen
.last-settings
mko.cpupower.policy
Expand Down
13 changes: 13 additions & 0 deletions .tern-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"libs": [
"browser"
],
"loadEagerly": [],
"dontLoad": [],
"plugins": {
"modules": {},
"es_modules": {},
"requirejs": {},
"commonjs": {}
}
}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align="center">CPU Power Manager for Gnome Shell</h1>
<h1 align="center">CPU Power Manager for Gnome Shell - GNOME 45</h1>
<p align="center">
<img alt="Screenshot" width="331" src="./img/header.png"/>
<!--<a href="https://extensions.gnome.org/extension/945/cpu-power-manager/">
Expand All @@ -14,7 +14,7 @@
<a href="https://github.com/deinstapel/cpupower/releases">
<img alt="Lastest release" src="https://img.shields.io/github/v/release/deinstapel/cpupower?label=latest%20release&sort=semver">
</a>
<img alt="Gnome 42" src="https://img.shields.io/badge/gnome-42-blue?logo=gnome&logoColor=white">
<img alt="Gnome 43" src="https://img.shields.io/badge/gnome-43-blue?logo=gnome&logoColor=white">
<a href="https://github.com/deinstapel/cpupower/blob/master/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/deinstapel/cpupower.svg">
</a>
Expand All @@ -34,6 +34,10 @@
<a href="#developing">Developing</a>
</p>

## Disclaimer
This is a semi-"mainained" version of the original `cpupower` repo made by Nicolas Derumigny, compatible with GNOME 45. I do it on my free time and for my own configuration only. I accept PRs and bug reports, but do not expect me to fix it quick.

--- original, **NOT UPDATED** README ----
## Prerequisites

You need to have a CPU which is supported by the **cpufreq** or **intel_pstate** CPU frequency scaling driver of the Linux kernel. This applies for most modern CPU's. Furthermore, the following software needs to be installed to use this extension:
Expand Down
2 changes: 1 addition & 1 deletion data/cpupower-preferences.glade
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ along with gnome-shell extension cpupower. If not, see
<http://www.gnu.org/licenses/>.
-->
<interface>
<requires lib="gtk+" version="3.22"/>
<requires lib="gtk+" version="4.12"/>
<!-- interface-license-type gplv3 -->
<!-- interface-name CPU Power Gnome-Shell extension -->
<!-- interface-description Creates a widget to set the preferences of the cpupower extension -->
Expand Down
5 changes: 5 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

#echo /home/$USER/.local

make install PREFIX=/home/$USER/.local
4 changes: 0 additions & 4 deletions dist/rpm/SPECS/gnome-shell-extension-cpupower.spec
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,14 @@ rm -rf $RPM_BUILD_ROOT
/usr/share/gnome-shell/extensions/[email protected]/prefs.js
/usr/share/gnome-shell/extensions/[email protected]/schemas/gschemas.compiled
/usr/share/gnome-shell/extensions/[email protected]/schemas/io.github.martin31821.cpupower.dbus.xml
/usr/share/gnome-shell/extensions/[email protected]/src/barLevel2.js
/usr/share/gnome-shell/extensions/[email protected]/src/baseindicator.js
/usr/share/gnome-shell/extensions/[email protected]/src/config.js
/usr/share/gnome-shell/extensions/[email protected]/src/convenience.js
/usr/share/gnome-shell/extensions/[email protected]/src/indicator.js
/usr/share/gnome-shell/extensions/[email protected]/src/notinstalled.js
/usr/share/gnome-shell/extensions/[email protected]/src/preferences.js
/usr/share/gnome-shell/extensions/[email protected]/src/prefs40/main.js
/usr/share/gnome-shell/extensions/[email protected]/src/prefs40/misc.js
/usr/share/gnome-shell/extensions/[email protected]/src/profile.js
/usr/share/gnome-shell/extensions/[email protected]/src/profilebutton.js
/usr/share/gnome-shell/extensions/[email protected]/src/slider2.js
/usr/share/gnome-shell/extensions/[email protected]/src/update.js
/usr/share/gnome-shell/extensions/[email protected]/src/utils.js
/usr/share/gnome-shell/extensions/[email protected]/tool/cpufreqctl
Expand Down
179 changes: 87 additions & 92 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,111 +25,106 @@
*
*/

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const EXTENSIONDIR = Me.dir.get_path();
const Convenience = Me.imports.src.convenience;
const Main = imports.ui.main;
const Config = imports.misc.config;
const ByteArray = imports.byteArray;
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';

const utils = Me.imports.src.utils;
const checkInstalled = Me.imports.src.utils.checkInstalled;
const notinstalled = Me.imports.src.notinstalled;
const update = Me.imports.src.update;
const indicator = Me.imports.src.indicator;
import * as utils from './src/utils.js';
import {checkInstalled} from './src/utils.js';
import * as notinstalled from './src/notinstalled.js';
import * as update from './src/update.js';
import * as indicator from './src/indicator.js';

const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';

let indicatorInstance;
/* exported init */
function init(_meta) {
Convenience.initTranslations("gnome-shell-extension-cpupower");
}
const EXTENSIONDIR = import.meta.url.substr('file://'.length, import.meta.url.lastIndexOf('/') - 'file://'.length);

function enableIndicator(instance) {
Main.panel.addToStatusArea("cpupower", instance.mainButton);
instance.enable();
}
export default class CPUPowerExtension extends Extension {
constructor(...args) {
super(...args);
this.indicatorInstance = null;
this.cpupowerProxy = null;
this.extensionReloadSignalHandler = null;
}

let cpupowerProxy;
let extensionReloadSignalHandler;
/* exported enable */
function enable() {
const interfaceBinary = GLib.file_get_contents(`${EXTENSIONDIR}/schemas/io.github.martin31821.cpupower.dbus.xml`)[1];
let interfaceXml;
if (parseFloat(Config.PACKAGE_VERSION.substring(0, 4)) > 3.28) {
interfaceXml = ByteArray.toString(interfaceBinary);
} else {
interfaceXml = interfaceBinary.toString();
enableIndicator(instance) {
Main.panel.addToStatusArea("cpupower", instance.mainButton);
instance.enable();
}
const CpupowerProxy = Gio.DBusProxy.makeProxyWrapper(interfaceXml);

cpupowerProxy = new CpupowerProxy(
Gio.DBus.session,
"io.github.martin31821.cpupower",
"/io/github/martin31821/cpupower",
);
/* exported enable */
enable() {
const interfaceBinary = GLib.file_get_contents(`${EXTENSIONDIR}/schemas/io.github.martin31821.cpupower.dbus.xml`)[1];
let decoder = new TextDecoder('utf-8');
let interfaceXml = decoder.decode(interfaceBinary);
const CpupowerProxy = Gio.DBusProxy.makeProxyWrapper(interfaceXml);

extensionReloadSignalHandler = cpupowerProxy.connectSignal("ExtensionReloadRequired", () => {
log("Reloading cpupower");
disable();
enable();
});
this.cpupowerProxy = new CpupowerProxy(
Gio.DBus.session,
"io.github.martin31821.cpupower",
"/io/github/martin31821/cpupower",
);

try {
checkInstalled((installed, exitCode) => {
if (!installed) {
switch (exitCode) {
case utils.INSTALLER_NEEDS_UPDATE:
indicatorInstance = new update.UpdateIndicator(update.UPDATE, function (success) {
if (success) {
// reenable the extension to allow immediate operation.
disable();
enable();
}
}, (inst) => enableIndicator(inst));
break;
case utils.INSTALLER_NEEDS_SECURITY_UPDATE:
indicatorInstance = new update.UpdateIndicator(update.SECURITY_UPDATE, function (success) {
if (success) {
// reenable the extension to allow immediate operation.
disable();
enable();
}
}, (inst) => enableIndicator(inst));
break;
default:
indicatorInstance = new notinstalled.NotInstalledIndicator(exitCode, function (success) {
if (success) {
// reenable the extension to allow immediate operation.
disable();
enable();
}
}, (inst) => enableIndicator(inst));
break;
}
} else {
indicatorInstance = new indicator.CPUFreqIndicator((inst) => enableIndicator(inst));
}
this.extensionReloadSignalHandler = this.cpupowerProxy.connectSignal("ExtensionReloadRequired", () => {
log("Reloading cpupower");
this.disable();
this.enable();
});
} catch (e) {
logError(e.message);
}
}

/* exported disable */
function disable() {
if (indicatorInstance) {
indicatorInstance.disable();
indicatorInstance.destroy();
try {
checkInstalled((installed, exitCode) => {
if (!installed) {
switch (exitCode) {
case utils.INSTALLER_NEEDS_UPDATE:
this.indicatorInstance = new update.UpdateIndicator(update.UPDATE, function (success) {
if (success) {
// reenable the extension to allow immediate operation.
disable();
enable();
}
}, (inst) => this.enableIndicator(inst));
break;
case utils.INSTALLER_NEEDS_SECURITY_UPDATE:
this.indicatorInstance = new update.UpdateIndicator(update.SECURITY_UPDATE, function (success) {
if (success) {
// reenable the extension to allow immediate operation.
disable();
enable();
}
}, (inst) => this.enableIndicator(inst));
break;
default:
this.indicatorInstance = new notinstalled.NotInstalledIndicator(exitCode, function (success) {
if (success) {
// reenable the extension to allow immediate operation.
disable();
enable();
}
}, (inst) => this.enableIndicator(inst));
break;
}
} else {
this.indicatorInstance = new indicator.CPUFreqIndicator((inst) => this.enableIndicator(inst));
}
});
} catch (e) {
logError(e);
}
}

if (cpupowerProxy && extensionReloadSignalHandler) {
cpupowerProxy.disconnectSignal(extensionReloadSignalHandler);
/* exported disable */
disable() {
if (this.indicatorInstance) {
this.indicatorInstance.disable();
this.indicatorInstance.destroy();
}

if (this.cpupowerProxy && this.extensionReloadSignalHandler) {
this.cpupowerProxy.disconnectSignal(this.extensionReloadSignalHandler);

cpupowerProxy = null;
extensionReloadSignalHandler = null;
this.cpupowerProxy = null;
this.extensionReloadSignalHandler = null;
}
}
}
17 changes: 8 additions & 9 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"localedir": "/usr/local/share/locale",
"shell-version": [
"3.28", "3.30", "3.36", "3.38", "40", "41", "42"
],
"uuid": "[email protected]",
"name": "CPU Power Manager",
"url": "https://github.com/deinstapel/cpupower",
"description": "Manage your CPU's frequency scaling driver",
"schema": "org.gnome.shell.extensions.cpupower"
"localedir": "/usr/local/share/locale",
"shell-version": ["45", "45.1", "45.2", "45.3", "46", "47"],
"uuid": "[email protected]",
"name": "CPU Power Manager",
"url": "https://github.com/deinstapel/cpupower",
"description": "Manage your CPU's frequency scaling driver",
"settings-schema": "org.gnome.shell.extensions.cpupower",
"gettext-domain": "cpupower"
}
49 changes: 15 additions & 34 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,22 @@
*
*/

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const EXTENSIONDIR = Me.dir.get_path();
const Convenience = Me.imports.src.convenience;
const CPUPowerPreferences = Me.imports.src.preferences.CPUPowerPreferences;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import {CPUPowerPreferencesContent} from './src/preferences.js';
import Gtk from 'gi://Gtk';

/* exported init */
function init() {
Convenience.initTranslations("gnome-shell-extension-cpupower");
}

/* exported buildPrefsWidget */
function buildPrefsWidget() {
if (Gtk.get_major_version() === 4) {
let dummy = new Gtk.Label();
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 0, () => {
let window = dummy.get_root();
window.close();

GLib.spawn_sync(
null,
[`${EXTENSIONDIR}/src/prefs40/main.js`],
null,
null,
null,
);

return GLib.SOURCE_REMOVE;
export default class CPUPowerPreferences extends ExtensionPreferences {
fillPreferencesWindow(win) {
win._settings = this.getSettings();
win.connect("delete-event", () => {
Gtk.main_quit();
});
return dummy;
} else {
let preferences = new CPUPowerPreferences();

return preferences.show();
let headerbar = new Gtk.HeaderBar();
headerbar.set_show_close_button(true);
headerbar.title = "CPU Power Manager";
let preferences = new CPUPowerPreferencesContent();
let mainWidget = preferences.show();
win.set_titlebar(headerbar);
win.add(mainWidget);
}
}
Loading