Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1,679 changes: 590 additions & 1,089 deletions data/cpupower-preferences.glade
100644 → 100755

Large diffs are not rendered by default.

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
181 changes: 89 additions & 92 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,111 +25,108 @@
*
*/

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 {NotInstalledIndicator} 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() {
globalThis.cpupowerExtension = this;
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.
this.disable();
this.enable();
}
}.bind(this), (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.
this.disable();
this.enable();
}
}.bind(this), (inst) => this.enableIndicator(inst));
break;
default:
this.indicatorInstance = new NotInstalledIndicator(exitCode, function (success) {
if (success) {

this.disable();
this.enable();
}
}.bind(this), (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;
}
delete globalThis.cpupowerExtension;
}
}
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"
}
46 changes: 13 additions & 33 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,21 @@
*
*/

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, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import {CPUPowerPreferencesContent} from './src/preferences.js';
import Gtk from 'gi://Gtk';
import Adw from "gi://Adw"

/* 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,
);
export default class CPUPowerPreferences extends ExtensionPreferences {
fillPreferencesWindow(win) {
win._settings = this.getSettings();

return GLib.SOURCE_REMOVE;
});
return dummy;
} else {
let preferences = new CPUPowerPreferences();
if (globalThis.cpupowerExtension == undefined){
globalThis.cpupowerExtension = ExtensionPreferences.lookupByUUID('[email protected]')
}
let preferences = new CPUPowerPreferencesContent();
let mainWidget = preferences.show();

return preferences.show();
win.add(mainWidget);
}
}
Loading