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

support gnome 45 #224

Open
wants to merge 3 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
67 changes: 67 additions & 0 deletions common/Logger.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* This is a part of CPUFreq Manager
* Copyright (C) 2016-2019 konkor <konkor.github.io>
*
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export var LEVEL = { ERROR: 0, INFO: 1, DEBUG: 2 }

//DOMAIN ERROR:0:RED, INFO:1:BLUE, DEBUG:2:GREEN
const domain_color = ["00;31","00;34","00;32"];
const domain_name = ["EE","II","DD"];
const domain_source = "application";

var debug_lvl = LEVEL.ERROR;
var mono = false;

export function init (level, extension) {
level = level || 0;
debug_lvl = level;
if (extension) mono = true;
}



export function info (source, msg) {
if (!msg) {
msg = source;
source = domain_source;
}
if (debug_lvl > 0) print_msg (1, source, msg);
}

export function debug (source, msg) {
if (!msg) {
msg = source;
source = domain_source;
}
if (debug_lvl > 1) print_msg (2, source, msg);
}

export function error (source, msg) {
if (!msg) {
msg = source;
source = domain_source;
}
print_msg (0, source, msg);
}



function print_msg (domain, source, output) {
let d = new Date();
let ds = d.toString ();
let i = ds.indexOf (" GMT");
if (i > 0) ds = ds.substring (0, i);

if (mono) print ("[%s.%s](%s) [cpufreq][%s] %s".format (
ds,(d.getMilliseconds() / 1000).toFixed(3).slice(2, 5),domain_name[domain],source,output));
else print ("\x1b[%sm[%s.%s](%s) [cpufreq][%s]\x1b[0m %s".format (
domain_color[domain],ds,(d.getMilliseconds() / 1000).toFixed(3).slice(2, 5),domain_name[domain],source,output));
log ("(%s) [cpufreq][%s] %s".format (domain_name[domain], source, output));
}


2 changes: 1 addition & 1 deletion common/Preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Lang = imports.lang;

const APPDIR = getCurrentFile ()[1];

const Prefs = imports.prefs;
const Prefs = imports.prefs_gjs;

var Preferences = new Lang.Class ({
Name: 'Preferences',
Expand Down
64 changes: 64 additions & 0 deletions convenience.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This is a part of CPUFreq Manager
* Copyright (C) 2016-2019 konkor <konkor.github.io>
*
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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

// @deprecated use extension.getSettings()
export function getSettings (extension) {
// schema = schema || 'org.gnome.shell.extensions.cpufreq';
// const GioSSS = Gio.SettingsSchemaSource;
// let schemaDir = Gio.File.new_for_path (getCurrentFile()[1] + '/schemas');
// let schemaSource;

// if (schemaDir.query_exists (null))
// schemaSource = GioSSS.new_from_directory (
// schemaDir.get_path (), GioSSS.get_default (), false
// );
// else{
// schemaSource = GioSSS.get_default ();
// }
// let schemaObj = schemaSource.lookup (schema, true);
// if (!schemaObj)
// throw new Error ('Schema ' + schema + ' could not be found for extension ' +
// 'cpufreq@konkor. Please check your installation.');
//
// return new Gio.Settings ({ settings_schema: schemaObj });
return extension.getSettings();
}

export function getCurrentFile () {
let stack = (new Error()).stack;
let stackLine = stack.split('\n')[1];
if (!stackLine)
throw new Error ('Could not find current file');
let match = new RegExp ('@(.+):\\d+').exec(stackLine);
if (!match)
throw new Error ('Could not find current file');
let path = match[1];
let file = Gio.File.new_for_path (path);
return [file.get_path(), file.get_parent().get_path(), file.get_basename()];
}

export function byteArrayToString (array) {
return array instanceof Uint8Array ? new TextDecoder().decode(array):array;
}

export function get_cpu_number () {
let c = 0;
let cpulist = null;
let ret = GLib.spawn_command_line_sync ("cat /sys/devices/system/cpu/present");
if (ret[0]) cpulist = byteArrayToString(ret[1]).toString().split("\n", 1)[0].split("-");
cpulist.forEach ((f) => {
if (parseInt (f) > 0) c = parseInt (f);
});
return c + 1;
}

8 changes: 4 additions & 4 deletions cpufreq-preferences
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ function getCurrentFile () {

function get_appdir () {
let s = getCurrentFile ()[1];
if (GLib.file_test (s + "/prefs.js", GLib.FileTest.EXISTS)) return s;
if (GLib.file_test (s + "/prefs_gjs.js", GLib.FileTest.EXISTS)) return s;
s = GLib.get_home_dir () + "/.local/share/gnome-shell/extensions/cpufreq@konkor";
if (GLib.file_test (s + "/prefs.js", GLib.FileTest.EXISTS)) return s;
if (GLib.file_test (s + "/prefs_gjs.js", GLib.FileTest.EXISTS)) return s;
s = "/usr/local/share/gnome-shell/extensions/cpufreq@konkor";
if (GLib.file_test (s + "/prefs.js", GLib.FileTest.EXISTS)) return s;
if (GLib.file_test (s + "/prefs_gjs.js", GLib.FileTest.EXISTS)) return s;
s = "/usr/share/gnome-shell/extensions/cpufreq@konkor";
if (GLib.file_test (s + "/prefs.js", GLib.FileTest.EXISTS)) return s;
if (GLib.file_test (s + "/prefs_gjs.js", GLib.FileTest.EXISTS)) return s;
throw "CPUFreq installation not found...";
return s;
}
8 changes: 8 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh -e
reset
export G_MESSAGES_DEBUG=debug
export MUTTER_DEBUG_DUMMY_MODE_SPECS=1366x768

dbus-run-session -- \
gnome-shell --nested \
--wayland
140 changes: 140 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import js from '@eslint/js';

export default [
js.configs.recommended,
{
languageOptions: {
globals: {
ARGV: 'readonly',
Debugger: 'readonly',
GIRepositoryGType: 'readonly',
globalThis: 'readonly',
imports: 'readonly',
Intl: 'readonly',
log: 'readonly',
logError: 'readonly',
pkg: 'readonly',
print: 'readonly',
printerr: 'readonly',
window: 'readonly',
TextEncoder: 'readonly',
TextDecoder: 'readonly',
console: 'readonly',
setTimeout: 'readonly',
setInterval: 'readonly',
clearTimeout: 'readonly',
clearInterval: 'readonly',
},
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
},
rules: {
// See: https://eslint.org/docs/latest/rules/#possible-problems
'array-callback-return': 'error',
'no-await-in-loop': 'error',
'no-constant-binary-expression': 'error',
'no-constructor-return': 'error',
'no-new-native-nonconstructor': 'error',
'no-promise-executor-return': 'error',
'no-self-compare': 'error',
'no-template-curly-in-string': 'error',
'no-unmodified-loop-condition': 'error',
'no-unreachable-loop': 'error',
'no-unused-private-class-members': 'error',
'no-use-before-define': [
'error',
{
functions: false,
classes: true,
variables: true,
allowNamedExports: true,
},
],
// See: https://eslint.org/docs/latest/rules/#suggestions
'block-scoped-var': 'error',
'complexity': 'warn',
'consistent-return': 'error',
'default-param-last': 'error',
'eqeqeq': 'error',
'no-array-constructor': 'error',
'no-caller': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-extra-label': 'error',
'no-iterator': 'error',
'no-label-var': 'error',
'no-loop-func': 'error',
'no-multi-assign': 'warn',
'no-new-object': 'error',
'no-new-wrappers': 'error',
'no-proto': 'error',
'no-shadow': 'warn',
'no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
},
],
'no-var': 'warn',
'unicode-bom': 'error',
// GJS Restrictions
'no-restricted-globals': [
'error',
{
name: 'Debugger',
message: 'Internal use only',
},
{
name: 'GIRepositoryGType',
message: 'Internal use only',
},
{
name: 'log',
message: 'Use console.log()',
},
{
name: 'logError',
message: 'Use console.warn() or console.error()',
},
],
'no-restricted-properties': [
'error',
{
object: 'imports',
property: 'format',
message: 'Use template strings',
},
{
object: 'pkg',
property: 'initFormat',
message: 'Use template strings',
},
{
object: 'Lang',
property: 'copyProperties',
message: 'Use Object.assign()',
},
{
object: 'Lang',
property: 'bind',
message: 'Use arrow notation or Function.prototype.bind()',
},
{
object: 'Lang',
property: 'Class',
message: 'Use ES6 classes',
},
],
'no-restricted-syntax': [
'error',
{
selector: 'MethodDefinition[key.name="_init"] CallExpression[arguments.length<=1][callee.object.type="Super"][callee.property.name="_init"]',
message: 'Use constructor() and super()',
},
],
},
},
];
Loading