new view, gnome extension
This commit is contained in:
80
gnome-extension/README.md
Normal file
80
gnome-extension/README.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# Deskmeter GNOME Task Indicator
|
||||
|
||||
A GNOME Shell extension that displays your current deskmeter task in the top panel, positioned to the left of the panel indicators.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- GNOME Shell (versions 40-47 supported)
|
||||
- Deskmeter web server running on `http://localhost:10000`
|
||||
- The `/api/current_task` endpoint must be accessible
|
||||
|
||||
## Installation
|
||||
|
||||
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/
|
||||
```
|
||||
|
||||
2. Restart GNOME Shell:
|
||||
- On X11: Press `Alt+F2`, type `r`, and press Enter
|
||||
- On Wayland: Log out and log back in
|
||||
|
||||
3. Enable the extension:
|
||||
|
||||
```bash
|
||||
gnome-extensions enable deskmeter-indicator@local
|
||||
```
|
||||
|
||||
Or use GNOME Extensions app (install with `sudo apt install gnome-shell-extension-prefs` if needed).
|
||||
|
||||
## Configuration
|
||||
|
||||
The extension polls the API every 3 seconds. You can adjust this in `extension.js`:
|
||||
|
||||
```javascript
|
||||
const UPDATE_INTERVAL = 3000; // milliseconds
|
||||
```
|
||||
|
||||
The API URL is set to:
|
||||
|
||||
```javascript
|
||||
const DESKMETER_API_URL = 'http://localhost:10000/api/current_task';
|
||||
```
|
||||
|
||||
## Uninstallation
|
||||
|
||||
```bash
|
||||
gnome-extensions disable deskmeter-indicator@local
|
||||
rm -rf ~/.local/share/gnome-shell/extensions/deskmeter-indicator@local
|
||||
```
|
||||
|
||||
Then restart GNOME Shell.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Extension not showing
|
||||
|
||||
1. Check if the extension is enabled:
|
||||
```bash
|
||||
gnome-extensions list --enabled
|
||||
```
|
||||
|
||||
2. Check for errors:
|
||||
```bash
|
||||
journalctl -f -o cat /usr/bin/gnome-shell
|
||||
```
|
||||
|
||||
### Shows "offline" or "error"
|
||||
|
||||
- Ensure dmweb Flask server is running on port 10000
|
||||
- Test the API endpoint:
|
||||
```bash
|
||||
curl http://localhost:10000/api/current_task
|
||||
```
|
||||
Should return JSON like: `{"task_id":"12345678","task_path":"work/default"}`
|
||||
|
||||
### Task path too long
|
||||
|
||||
The extension automatically truncates paths longer than 40 characters, showing only the last two segments with a `.../ ` prefix.
|
||||
101
gnome-extension/deskmeter-indicator@local/extension.js
Normal file
101
gnome-extension/deskmeter-indicator@local/extension.js
Normal file
@@ -0,0 +1,101 @@
|
||||
import GObject from 'gi://GObject';
|
||||
import St from 'gi://St';
|
||||
import Gio from 'gi://Gio';
|
||||
import GLib from 'gi://GLib';
|
||||
import Clutter from 'gi://Clutter';
|
||||
|
||||
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 TaskIndicator = GObject.registerClass(
|
||||
class TaskIndicator extends PanelMenu.Button {
|
||||
_init() {
|
||||
super._init(0.0, 'Deskmeter Task Indicator', false);
|
||||
|
||||
// Create label for task display
|
||||
this._label = new St.Label({
|
||||
text: 'loading...',
|
||||
y_align: Clutter.ActorAlign.CENTER,
|
||||
style_class: 'deskmeter-task-label'
|
||||
});
|
||||
|
||||
this.add_child(this._label);
|
||||
|
||||
// Start periodic updates
|
||||
this._updateTask();
|
||||
this._timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, UPDATE_INTERVAL, () => {
|
||||
this._updateTask();
|
||||
return GLib.SOURCE_CONTINUE;
|
||||
});
|
||||
}
|
||||
|
||||
_updateTask() {
|
||||
try {
|
||||
// Create HTTP request
|
||||
let file = Gio.File.new_for_uri(DESKMETER_API_URL);
|
||||
file.load_contents_async(null, (source, result) => {
|
||||
try {
|
||||
let [success, contents] = source.load_contents_finish(result);
|
||||
if (success) {
|
||||
let decoder = new TextDecoder('utf-8');
|
||||
let data = JSON.parse(decoder.decode(contents));
|
||||
|
||||
// Update label with task path
|
||||
let displayText = data.task_path || 'no task';
|
||||
|
||||
// Optionally truncate long paths
|
||||
if (displayText.length > 40) {
|
||||
let parts = displayText.split('/');
|
||||
if (parts.length > 2) {
|
||||
displayText = '.../' + parts.slice(-2).join('/');
|
||||
} else {
|
||||
displayText = displayText.substring(0, 37) + '...';
|
||||
}
|
||||
}
|
||||
|
||||
this._label.set_text(displayText);
|
||||
}
|
||||
} catch (e) {
|
||||
this._label.set_text('error');
|
||||
logError(e, 'Failed to parse deskmeter response');
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
this._label.set_text('offline');
|
||||
logError(e, 'Failed to fetch deskmeter task');
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this._timeout) {
|
||||
GLib.source_remove(this._timeout);
|
||||
this._timeout = null;
|
||||
}
|
||||
super.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
export default class Extension {
|
||||
constructor() {
|
||||
this._indicator = null;
|
||||
}
|
||||
|
||||
enable() {
|
||||
this._indicator = new TaskIndicator();
|
||||
|
||||
// Add to panel - position after workspace indicator
|
||||
// Panel boxes: left, center, right
|
||||
// We'll add it to the left panel, after other items
|
||||
Main.panel.addToStatusArea('deskmeter-task-indicator', this._indicator, 1, 'left');
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._indicator) {
|
||||
this._indicator.destroy();
|
||||
this._indicator = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
gnome-extension/deskmeter-indicator@local/metadata.json
Normal file
17
gnome-extension/deskmeter-indicator@local/metadata.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "Deskmeter Task Indicator",
|
||||
"description": "Displays current deskmeter task in GNOME panel",
|
||||
"uuid": "deskmeter-indicator@local",
|
||||
"shell-version": [
|
||||
"40",
|
||||
"41",
|
||||
"42",
|
||||
"43",
|
||||
"44",
|
||||
"45",
|
||||
"46",
|
||||
"47"
|
||||
],
|
||||
"url": "",
|
||||
"version": 1
|
||||
}
|
||||
5
gnome-extension/deskmeter-indicator@local/stylesheet.css
Normal file
5
gnome-extension/deskmeter-indicator@local/stylesheet.css
Normal file
@@ -0,0 +1,5 @@
|
||||
.deskmeter-task-label {
|
||||
font-weight: normal;
|
||||
padding: 0 8px;
|
||||
color: #ffffff;
|
||||
}
|
||||
27
gnome-extension/install.sh
Normal file
27
gnome-extension/install.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Install Deskmeter GNOME Task Indicator
|
||||
|
||||
EXTENSION_DIR="$HOME/.local/share/gnome-shell/extensions"
|
||||
EXTENSION_NAME="deskmeter-indicator@local"
|
||||
SOURCE_DIR="$(cd "$(dirname "$0")" && pwd)/$EXTENSION_NAME"
|
||||
|
||||
echo "Installing Deskmeter Task Indicator..."
|
||||
|
||||
# Create extensions directory if it doesn't exist
|
||||
mkdir -p "$EXTENSION_DIR"
|
||||
|
||||
# Copy extension files
|
||||
cp -r "$SOURCE_DIR" "$EXTENSION_DIR/"
|
||||
|
||||
echo "Extension copied to $EXTENSION_DIR/$EXTENSION_NAME"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Restart GNOME Shell:"
|
||||
echo " - On X11: Press Alt+F2, type 'r', press Enter"
|
||||
echo " - On Wayland: Log out and log back in"
|
||||
echo ""
|
||||
echo "2. Enable the extension:"
|
||||
echo " gnome-extensions enable $EXTENSION_NAME"
|
||||
echo ""
|
||||
echo "Make sure dmweb is running on http://localhost:10000"
|
||||
Reference in New Issue
Block a user