new view, gnome extension
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user