Skip to content

Commit

Permalink
Merge pull request #98 from mgalgs/schema-rename
Browse files Browse the repository at this point in the history
Schema rename (#98)

Co-Authored-By: NVieville <nicolas.vieville@uphf.fr>
  • Loading branch information
mgalgs and NVieville authored Nov 8, 2024
2 parents fce02ae + 815716b commit 8503b78
Show file tree
Hide file tree
Showing 8 changed files with 647 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extension.clean:
$(Q)git checkout -f -- ./$(UUID)/schemas/gschemas.compiled
$(call msg,$@,OK)

./$(UUID)/schemas/gschemas.compiled: ./$(UUID)/schemas/org.gnome.shell.extensions.system-monitor.gschema.xml
./$(UUID)/schemas/gschemas.compiled: ./$(UUID)/schemas/org.gnome.shell.extensions.system-monitor-next-applet.v1.gschema.xml
$(Q)glib-compile-schemas ./$(UUID)/schemas/
$(call msg,gschemas,OK)

Expand Down
38 changes: 28 additions & 10 deletions system-monitor-next@paradoxxx.zero.gmail.com/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import * as PopupMenu from "resource:///org/gnome/shell/ui/popupMenu.js";

import * as Util from "resource:///org/gnome/shell/misc/util.js";

import { sm_log } from './utils.js';
import { parse_bytearray, check_sensors } from './common.js';
import { migrateSettings } from './migration.js';

const NetworkManager = NM;
const UPower = UPowerGlib;
Expand All @@ -65,10 +67,6 @@ Clutter.Actor.prototype.reparent = function reparent(newParent) {
newParent.add_child(this);
}

function sm_log(message) {
console.log(`[system-monitor-next] ${message}`);
}

function l_limit(t) {
return (t > 0) ? t : 1000;
}
Expand Down Expand Up @@ -487,8 +485,8 @@ const smMountsMonitor = class SystemMonitor_smMountsMonitor {
// need to add the other signals here
this.connected = true;
} catch (e) {
sm_log('Failed to register on placesManager notifications');
sm_log('Got exception : ' + e);
sm_log('Failed to register on placesManager notifications', 'error');
sm_log('Got exception : ' + e, 'error');
}
this.refresh();
}
Expand Down Expand Up @@ -984,7 +982,7 @@ const ElementBase = class SystemMonitor_ElementBase extends TipBox {
restart_update_timer(interval = null) {
interval = interval || this._lastInterval;
if (!interval) {
sm_log("Invalid call to restart_update_timer");
sm_log("Invalid call to restart_update_timer", 'error');
return;
}
if (this.timeout) {
Expand Down Expand Up @@ -1127,7 +1125,7 @@ const Battery = class SystemMonitor_Battery extends ElementBase {
} else {
this._proxy.GetDevicesRemote((devices, error) => {
if (error) {
sm_log('Power proxy error: ' + error);
sm_log('Power proxy error: ' + error, 'error');
this.actor.hide();
this.menu_visible = false;
build_menu_info(this.extension);
Expand Down Expand Up @@ -2098,10 +2096,19 @@ const Thermal = class SystemMonitor_Thermal extends ElementBase {
this.update();
}
refresh() {
if (this.sensors === undefined || Object.keys(this.sensors).length === 0) {
return;
}
let label = this.extension._Schema.get_string(this.elt + '-sensor-label');
let sfile = this.sensors[label];
if (sfile === undefined && this.display_error) {
const validLabels = Object.keys(this.sensors).join(', ');
sm_log(`Invalid thermal sensor label: "${label}" (valid choices: ${validLabels})`, 'error');
this.display_error = false;
return;
}
if (!try_read_int_file(sfile, value => this.temperature = Math.round(value / 1000)) && this.display_error) {
console.error('error reading: ' + sfile);
sm_log(`Error reading thermal sensor file: ${sfile}`, 'error');
this.display_error = false;
}

Expand Down Expand Up @@ -2164,10 +2171,19 @@ const Fan = class SystemMonitor_Fan extends ElementBase {
this.update();
}
refresh() {
if (this.sensors === undefined || Object.keys(this.sensors).length === 0) {
return;
}
let label = this.extension._Schema.get_string(this.elt + '-sensor-label');
let sfile = this.sensors[label];
if (sfile === undefined && this.display_error) {
const validLabels = Object.keys(this.sensors).join(', ');
sm_log(`Invalid fan sensor label: "${label}" (valid choices: ${validLabels})`, 'error');
this.display_error = false;
return;
}
if (!try_read_int_file(sfile, value => this.rpm = value) && this.display_error) {
console.error('error reading: ' + sfile);
sm_log(`Error reading fan sensor file: ${sfile}`, 'error');
this.display_error = false;
}
if (sfile) {
Expand Down Expand Up @@ -2384,6 +2400,8 @@ export default class SystemMonitorExtension extends Extension {
enable() {
sm_log('applet enable from ' + this.path);

migrateSettings(this);

// Get locale, needed as an argument for toLocaleString() since GNOME Shell 3.24
// See: mozjs library bug https://bugzilla.mozilla.org/show_bug.cgi?id=999003
this._Locale = GLib.get_language_names()[0];
Expand Down
2 changes: 1 addition & 1 deletion system-monitor-next@paradoxxx.zero.gmail.com/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "system-monitor-next",
"url": "https://github.com/mgalgs/gnome-shell-system-monitor-applet",
"description": "Display system information in GNOME Shell status bar, such as memory, CPU, disk and battery usages, network rates…\n\nThis is a fork of the seemingly abandoned paradoxxxzero/gnome-shell-system-monitor-applet.\n\nIf you get an error after updating, try logging out and logging back in (this is a known issue that is being worked on).",
"settings-schema": "org.gnome.shell.extensions.system-monitor",
"settings-schema": "org.gnome.shell.extensions.system-monitor-next-applet",
"gettext-domain": "system-monitor",
"version": -1
}
71 changes: 71 additions & 0 deletions system-monitor-next@paradoxxx.zero.gmail.com/migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Gio from "gi://Gio";

import { sm_log } from './utils.js';

function migrateSettings(extension) {
const SCHEMA_VERSION_KEY = 'settings-schema-version';
const CURRENT_SCHEMA_VERSION = 1; // Increment this when adding new migrations

const settings = extension.getSettings();

// Get current version, defaults to 0 if not set
const currentVersion = settings.get_int(SCHEMA_VERSION_KEY);

// Skip if we're already at the current version
if (currentVersion === CURRENT_SCHEMA_VERSION) {
sm_log("No settings migration needed");
return;
}

let didMigration = false;

switch (currentVersion) {
case 0:
didMigration = migrateFrom0(extension, settings);
break;
default:
sm_log(`Unknown schema version ${currentVersion}`);
break;
}

if (!didMigration) {
const msg = `BOGUS schema migration! No migration was performed, but current version is ${currentVersion} and desired version is ${CURRENT_SCHEMA_VERSION}.`;
sm_log(msg, 'error');
} else {
settings.set_int(SCHEMA_VERSION_KEY, CURRENT_SCHEMA_VERSION);
}
}

function migrateFrom0(extension, newSettings) {
// v0 -> v1
// Handle schema name change by copying over all settings from old schema
sm_log('Migrating settings: v0 -> v1');
const OLD_SCHEMA_ID = 'org.gnome.shell.extensions.system-monitor';
const oldSettings = extension.getSettings(OLD_SCHEMA_ID);

if (!oldSettings) {
sm_log('No old settings found, skipping migration');
// Migration is successful, but no settings were migrated
return true;
}

const keys = oldSettings.list_keys();

for (const key of keys) {
try {
const value = oldSettings.get_value(key);
if (value) {
const unpackedValue = value.unpack();
sm_log(`Migrating ${key}=${unpackedValue} from old schema`);
newSettings.set_value(key, value);
}
} catch (e) {
sm_log(`Error migrating key ${key}: ${e}`, 'error');
}
}

sm_log('Successfully migrated settings from old schema');
return true;
}

export { migrateSettings };
Binary file not shown.
Loading

0 comments on commit 8503b78

Please sign in to comment.