Skip to content

Commit

Permalink
Fix current frequency display & support Gnome 3.26
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Lambiris authored and martin31821 committed Oct 23, 2017
1 parent bfd285c commit 295f38b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 29 deletions.
15 changes: 4 additions & 11 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
{
"localedir":"/usr/local/share/locale",
"shell-version": [
"3.10",
"3.12",
"3.14",
"3.16",
"3.18",
"3.20",
"3.22",
"3.24"
],
"uuid": "cpupower@mko-sl.de",
"3.10", "3.12", "3.14", "3.16", "3.18", "3.20", "3.22", "3.24", "3.26"
],
"uuid": "cpupower@mko-sl.de",
"name": "CPU Power Manager",
"url": "https://github.com/martin31821/cpupower",
"url": "https://github.com/martin31821/cpupower",
"description": "Manage Intel_pstate CPU Frequency scaling driver",
"schema": "org.gnome.shell.extensions.cpupower"
}
2 changes: 1 addition & 1 deletion src/baseindicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.src.convenience;
const SETTINGS_ID = 'org.gnome.shell.extensions.cpupower';

const CPUFreqBaseIndicator = new Lang.Class({
var CPUFreqBaseIndicator = new Lang.Class({
Name: 'cpupower.CPUFreqBaseIndicator',
Extends: PanelMenu.Button,
Abstract: true,
Expand Down
41 changes: 29 additions & 12 deletions src/indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const EXTENSIONDIR = Me.dir.get_path();
const CPUFREQCTL = EXTENSIONDIR + '/src/cpufreqctl';
const PKEXEC = GLib.find_program_in_path('pkexec');

const CPUFreqIndicator = new Lang.Class({
var CPUFreqIndicator = new Lang.Class({
Name: 'cpupower.CPUFreqIndicator',
Extends: CPUFreqBaseIndicator,

Expand All @@ -64,15 +64,15 @@ const CPUFreqIndicator = new Lang.Class({
// read the last-settings file.
if(!GLib.file_test(EXTENSIONDIR + '/.last-settings', GLib.FileTest.EXISTS))
{
let result = GLib.spawn_command_line_sync(CPUFREQCTL + ' turbo get', this.out);
let result = GLib.spawn_command_line_sync(CPUFREQCTL + ' turbo get');
let returnCode = result[1];
this.isTurboBoostActive = returnCode;

result = GLib.spawn_command_line_sync(CPUFREQCTL + ' min get', this.out);
result = GLib.spawn_command_line_sync(CPUFREQCTL + ' min get');
returnCode = result[1];
this.minVal = returnCode;

result = GLib.spawn_command_line_sync(CPUFREQCTL + ' max get', this.out);
result = GLib.spawn_command_line_sync(CPUFREQCTL + ' max get');
returnCode = result[1];
this.maxVal = returnCode;
}
Expand All @@ -89,6 +89,19 @@ const CPUFreqIndicator = new Lang.Class({
this._updateTurbo(true);
}
}

let result = GLib.spawn_command_line_sync(CPUFREQCTL + ' turbo get');
let returnCode = result[1];
this.isTurboBoostActive = returnCode;

result = GLib.spawn_command_line_sync(CPUFREQCTL + ' min get');
returnCode = result[1];
this.minVal = returnCode;

result = GLib.spawn_command_line_sync(CPUFREQCTL + ' max get');
returnCode = result[1];
this.maxVal = returnCode;

this.parent();
},

Expand Down Expand Up @@ -250,7 +263,7 @@ const CPUFreqIndicator = new Lang.Class({
_updateFile: function()
{
let cmd = Math.floor(this.minVal) + '\n' + Math.floor(this.maxVal) + '\n' + (this.isTurboBoostActive ? 'true':'false') + '\n';
let path = EXTENSIONDIR + '/.last-settings';
let path = EXTENSIONDIR + '/.last-settings';
GLib.file_set_contents(path, cmd);
},

Expand Down Expand Up @@ -306,21 +319,25 @@ const CPUFreqIndicator = new Lang.Class({

_updateFreq: function()
{
let cpufreq = 0, cpucount = 0;
let lines = Shell.get_file_contents_utf8_sync('/proc/cpuinfo').split('\n');
for(let i = 0; i < lines.length; i++)
{
let line = lines[i];

if(line.search(/cpu mhz/i) < 0)
continue;
this.cpufreq = parseInt(line.substring(line.indexOf(':') + 2));
this.imCurrentLabel.set_text(this._getCurFreq());
if(this.lblActive)
this.lbl.set_text(this._getCurFreq());
else
this.lbl.set_text('');
break;

let f = Shell.get_file_contents_utf8_sync('/sys/devices/system/cpu/cpu' + cpucount++ + '/cpufreq/scaling_cur_freq');
cpufreq += parseInt(f / 1024);
}
this.cpufreq = (cpufreq / cpucount)
this.imCurrentLabel.set_text(this._getCurFreq());
if(this.lblActive)
this.lbl.set_text(this._getCurFreq());
else
this.lbl.set_text('');

return true;
},

Expand Down
2 changes: 1 addition & 1 deletion src/notinstalled.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const SETTINGS_ID = 'org.gnome.shell.extensions.cpupower';
const Gettext = imports.gettext.domain('gnome-shell-extension-cpupower');
const _ = Gettext.gettext;

const NotInstalledIndicator = new Lang.Class({
var NotInstalledIndicator = new Lang.Class({
Name: 'cpupower.CPUFreqNotInstalledIndicator',
Extends: CPUFreqBaseIndicator,

Expand Down
2 changes: 1 addition & 1 deletion src/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const EXTENSIONDIR = Me.dir.get_path();
const GLADE_FILE = EXTENSIONDIR + "/data/cpupower-preferences.glade";
const SETTINGS_SCHEMA = 'org.gnome.shell.extensions.cpupower';

const CPUPowerPreferences = new Lang.Class({
var CPUPowerPreferences = new Lang.Class({
Name: 'cpupower.Preferences',

_init: function()
Expand Down
2 changes: 1 addition & 1 deletion src/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const GenerateUUID = function ()
return Math.floor(1 + Math.random() * 0xFFFFFFFE).toString();
};

const CPUFreqProfile = new Lang.Class({
var CPUFreqProfile = new Lang.Class({
Name: 'cpupower.CPUFreqProfile',

_init: function()
Expand Down
2 changes: 1 addition & 1 deletion src/profilebutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const PopupMenu = imports.ui.popupMenu;

const DEFAULT_EMPTY_NAME = 'No name';

const CPUFreqProfileButton = new Lang.Class({
var CPUFreqProfileButton = new Lang.Class({
Name: 'cpupower.CPUFreqProfileButton',
Extends: PopupMenu.PopupMenuItem,

Expand Down
2 changes: 1 addition & 1 deletion src/unsupported.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Gettext = imports.gettext.domain('gnome-shell-extension-cpupower');
const _ = Gettext.gettext;


const UnsupportedIndicator = new Lang.Class({
var UnsupportedIndicator = new Lang.Class({
Name: 'cpupower.CPUFreqUnsupportedIndicator',
Extends: CPUFreqBaseIndicator,

Expand Down

0 comments on commit 295f38b

Please sign in to comment.