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 45 #215

Closed
wants to merge 8 commits into from
Closed
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
180 changes: 94 additions & 86 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,24 @@
*
*/

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;

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;

const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';

//const ByteArray = imports.byteArray;

import { utils } from "./src/utils.js"
import { checkInstalled } from "./src/checkInstalled.js"
import { notinstalled } from "./src/notinstalled.js"
import { update } from "./src/update.js"
import { indicator } from "./src/indicator.js"

import Gio from 'gi://Gio';
import GLib from 'gi://GLib';

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

function enableIndicator(instance) {
Expand All @@ -55,81 +52,92 @@ function enableIndicator(instance) {

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();

export default class CpuPowerExtension extends Extension {

export const settings = this.getSettings();
constructor(metadata) {
super(metadata);
}
const CpupowerProxy = Gio.DBusProxy.makeProxyWrapper(interfaceXml);

cpupowerProxy = new CpupowerProxy(
Gio.DBus.session,
"io.github.martin31821.cpupower",
"/io/github/martin31821/cpupower",
);

extensionReloadSignalHandler = cpupowerProxy.connectSignal("ExtensionReloadRequired", () => {
log("Reloading cpupower");
disable();
enable();
});

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));
}
enable() {
const EXTENSIONDIR = this.path;
const interfaceBinary = GLib.file_get_contents(`${EXTENSIONDIR}/schemas/io.github.martin31821.cpupower.dbus.xml`)[1];
let interfaceXml;

let decoder = new TextDecoder('utf-8');

interfaceXml = decoder.decode(interfaceBinary);

const CpupowerProxy = Gio.DBusProxy.makeProxyWrapper(interfaceXml);

cpupowerProxy = new CpupowerProxy(
Gio.DBus.session,
"io.github.martin31821.cpupower",
"/io/github/martin31821/cpupower",
);

extensionReloadSignalHandler = cpupowerProxy.connectSignal("ExtensionReloadRequired", () => {
log("Reloading cpupower");
disable();
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:
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));
}
});
} catch (e) {
logError(e.message);
}
}

if (cpupowerProxy && extensionReloadSignalHandler) {
cpupowerProxy.disconnectSignal(extensionReloadSignalHandler);
/* exported disable */

disable() {
if (indicatorInstance) {
indicatorInstance.disable();
indicatorInstance.destroy();
}

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

cpupowerProxy = null;
extensionReloadSignalHandler = null;
cpupowerProxy = null;
extensionReloadSignalHandler = null;
}
}
}
5 changes: 3 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"localedir": "/usr/local/share/locale",
"shell-version": [
"3.28", "3.30", "3.36", "3.38", "40", "41", "42"
"45"
],
"uuid": "cpupower@mko-sl.de",
"name": "CPU Power Manager",
"url": "https://github.com/deinstapel/cpupower",
"description": "Manage your CPU's frequency scaling driver",
"schema": "org.gnome.shell.extensions.cpupower"
"settings-schema": "org.gnome.shell.extensions.cpupower",
"gettext-domain": "cpupower"
}
8 changes: 6 additions & 2 deletions src/barLevel2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
* See <https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/3.38.1/COPYING> for details.
*/

const {Atk, Clutter, GObject, St} = imports.gi;
const Config = imports.misc.config;
import Clutter from 'gi://Clutter';
import Atk from 'gi://Atk';
import St from 'gi://St';
import GObject from 'gi://GObject';

import * as Config from 'resource:///org/gnome/shell/misc/config.js';

/* exported BarLevel2 */
var BarLevel2 = GObject.registerClass({
Expand Down
43 changes: 22 additions & 21 deletions src/baseindicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,36 @@
*
*/





import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Util from 'resource:///org/gnome/shell/misc/util.js';
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';

// Gnome imports
const PanelMenu = imports.ui.panelMenu;
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const PopupMenu = imports.ui.popupMenu;
const Main = imports.ui.main;
const Clutter = imports.gi.Clutter;
const Config = imports.misc.config;

// Relative and misc imports and definitions
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.src.convenience;
const SETTINGS_ID = "org.gnome.shell.extensions.cpupower";
import Gio from 'gi://Gio';
import St from 'gi://St';
import Gio from 'gi://Gio';
import Clutter from 'gi://Clutter';

//Relative imports

import { CpuPowerExtension } from "./../extension.js"


/* exported CPUFreqBaseIndicator */
var CPUFreqBaseIndicator = class CPUFreqBaseIndicator {
constructor() {
this.mainButton = new PanelMenu.Button(null, "cpupower");
this.menu = this.mainButton.menu;

if (parseFloat(Config.PACKAGE_VERSION.substring(0, 4)) > 3.32) {
this.actor = this.mainButton;
} else {
this.actor = this.mainButton.actor;
}

this.settings = Convenience.getSettings(SETTINGS_ID);

this.actor = this.mainButton;
ax
this.settings = new CpuPowerExtension().settings
Main.panel.menuManager.addMenu(this.menu);
this.hbox = new St.BoxLayout({style_class: "panel-status-menu-box"});
let gicon = Gio.icon_new_for_string(`${Me.path}/data/icons/cpu-symbolic.svg`);
Expand Down
98 changes: 0 additions & 98 deletions src/convenience.js

This file was deleted.

Loading