new view, gnome extension

This commit is contained in:
buenosairesam
2025-12-19 21:08:39 -03:00
parent 38f3c7a711
commit 0dde9f1f54
6 changed files with 220 additions and 39 deletions

View File

@@ -8,7 +8,7 @@ import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
const DESKMETER_API_URL = 'http://localhost:10000/api/current_task';
const UPDATE_INTERVAL = 3000; // 3 seconds
const DEBOUNCE_DELAY = 2200; // Wait 2.2s after workspace switch (dmcore polls every 2s)
const TaskIndicator = GObject.registerClass(
class TaskIndicator extends PanelMenu.Button {
@@ -24,11 +24,36 @@ class TaskIndicator extends PanelMenu.Button {
this.add_child(this._label);
// Start periodic updates
this._updateTask();
this._timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, UPDATE_INTERVAL, () => {
this._debounceTimeout = null;
this._workspaceManager = global.workspace_manager;
// Connect to workspace switch signal
this._workspaceSwitchedId = this._workspaceManager.connect(
'workspace-switched',
this._onWorkspaceSwitched.bind(this)
);
// Initial update
this._scheduleUpdate();
}
_onWorkspaceSwitched() {
// Debounce updates - dmcore takes ~2 seconds to detect and update
// We wait a bit to ensure the task has been updated in MongoDB
this._scheduleUpdate();
}
_scheduleUpdate() {
// Clear any pending update
if (this._debounceTimeout) {
GLib.source_remove(this._debounceTimeout);
}
// Schedule new update
this._debounceTimeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, DEBOUNCE_DELAY, () => {
this._updateTask();
return GLib.SOURCE_CONTINUE;
this._debounceTimeout = null;
return GLib.SOURCE_REMOVE;
});
}
@@ -70,10 +95,16 @@ class TaskIndicator extends PanelMenu.Button {
}
destroy() {
if (this._timeout) {
GLib.source_remove(this._timeout);
this._timeout = null;
if (this._debounceTimeout) {
GLib.source_remove(this._debounceTimeout);
this._debounceTimeout = null;
}
if (this._workspaceSwitchedId) {
this._workspaceManager.disconnect(this._workspaceSwitchedId);
this._workspaceSwitchedId = null;
}
super.destroy();
}
});