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

@@ -13,8 +13,7 @@ A GNOME Shell extension that displays your current deskmeter task in the top pan
1. Copy the extension to your GNOME extensions directory:
```bash
cp -r /home/mariano/wdir/dm/gnome-extension/deskmeter-indicator@local \
~/.local/share/gnome-shell/extensions/
cp -r /home/mariano/wdir/dm/gnome-extension/deskmeter-indicator@local ~/.local/share/gnome-shell/extensions/
```
2. Restart GNOME Shell:
@@ -31,10 +30,12 @@ Or use GNOME Extensions app (install with `sudo apt install gnome-shell-extensio
## Configuration
The extension polls the API every 3 seconds. You can adjust this in `extension.js`:
The extension updates automatically when you switch workspaces. It waits 2.2 seconds after a workspace switch to allow dmcore (which polls every 2 seconds) to detect the change and update MongoDB.
You can adjust the delay in `extension.js`:
```javascript
const UPDATE_INTERVAL = 3000; // milliseconds
const DEBOUNCE_DELAY = 2200; // milliseconds
```
The API URL is set to:
@@ -52,6 +53,28 @@ rm -rf ~/.local/share/gnome-shell/extensions/deskmeter-indicator@local
Then restart GNOME Shell.
## Updating the Extension
After making changes to the extension code:
```bash
# Use the update script
cd /home/mariano/wdir/dm/gnome-extension
./update.sh
# Then restart GNOME Shell (X11 only)
Alt+F2, type: r, press Enter
# On Wayland: log out and back in
```
Or manually:
```bash
cp -r /home/mariano/wdir/dm/gnome-extension/deskmeter-indicator@local \
~/.local/share/gnome-shell/extensions/
# Then restart GNOME Shell
```
## Troubleshooting
### Extension not showing
@@ -66,6 +89,12 @@ Then restart GNOME Shell.
journalctl -f -o cat /usr/bin/gnome-shell
```
3. Try disabling and re-enabling:
```bash
gnome-extensions disable deskmeter-indicator@local
gnome-extensions enable deskmeter-indicator@local
```
### Shows "offline" or "error"
- Ensure dmweb Flask server is running on port 10000
@@ -75,6 +104,16 @@ Then restart GNOME Shell.
```
Should return JSON like: `{"task_id":"12345678","task_path":"work/default"}`
### Changes not appearing
- Make sure you copied files after editing
- GNOME Shell must be restarted (no way around this)
- Check logs for JavaScript errors: `journalctl -b -o cat /usr/bin/gnome-shell | grep deskmeter`
### Debug with Looking Glass
Press `Alt+F2`, type `lg`, press Enter. Go to Extensions tab to see if the extension loaded and check for errors.
### Task path too long
The extension automatically truncates paths longer than 40 characters, showing only the last two segments with a `.../ ` prefix.

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();
}
});

20
gnome-extension/update.sh Normal file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
# Quick update script for GNOME extension development
EXTENSION_DIR="$HOME/.local/share/gnome-shell/extensions"
EXTENSION_NAME="deskmeter-indicator@local"
SOURCE_DIR="$(cd "$(dirname "$0")" && pwd)/$EXTENSION_NAME"
echo "Updating Deskmeter Task Indicator..."
# Copy extension files
cp -r "$SOURCE_DIR" "$EXTENSION_DIR/"
echo "Files copied."
echo ""
echo "Next: Restart GNOME Shell"
echo " X11: Alt+F2, type 'r', press Enter"
echo " Wayland: Log out and back in"
echo ""
echo "Check logs: journalctl -f -o cat /usr/bin/gnome-shell"