snapshot of https://github.com/ActivityWatch/aw-server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Build / Test on ubuntu-latest (push) Successful in 3m6s
Lint / lint (push) Successful in 22s
Build / typecheck (ubuntu-latest, 3.9) (push) Successful in 1m49s
Lint / format (push) Successful in 42s
Build / Test on macOS-latest (push) Has been cancelled
Build / Test on windows-latest (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1m31s
Some checks failed
Build / Test on ubuntu-latest (push) Successful in 3m6s
Lint / lint (push) Successful in 22s
Build / typecheck (ubuntu-latest, 3.9) (push) Successful in 1m49s
Lint / format (push) Successful in 42s
Build / Test on macOS-latest (push) Has been cancelled
Build / Test on windows-latest (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1m31s
This commit is contained in:
55
aw_server/custom_static.py
Normal file
55
aw_server/custom_static.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
Contains endpoints, as well as utility functions for custom static content.
|
||||
|
||||
NOTE: Experimental, not (yet) implemented in aw-server-rust.
|
||||
|
||||
Idea: Allow custom watchers to extend the Web UI and to write custom visualizations completely independently and free.
|
||||
|
||||
Usage for the watcher developer:
|
||||
- You can use Vanilla JavaScript, Vue, React, ... as long as you have static content at the end.
|
||||
|
||||
- Register your watcher visualization in the config:
|
||||
|
||||
[server.custom_static]
|
||||
aw-watcher-example=/home/user/path/to/static_dir/
|
||||
|
||||
- Your custom static content automatically gets the data for the requested time span as GET parameter called "data".
|
||||
Another parameter called "view" can be used if you want to create multiple visualizations for a single watcher.
|
||||
|
||||
- You can show your custom visualizations in the official Activity Watch UI using the "Custom Watcher View"
|
||||
See https://github.com/ActivityWatch/activitywatch/issues/453#issuecomment-910567848
|
||||
|
||||
"""
|
||||
|
||||
from flask import (
|
||||
Blueprint,
|
||||
escape,
|
||||
jsonify,
|
||||
send_from_directory,
|
||||
)
|
||||
|
||||
|
||||
def get_custom_static_blueprint(custom_static_directories):
|
||||
custom_static_blueprint = Blueprint("custom_static", __name__, url_prefix="/")
|
||||
|
||||
@custom_static_blueprint.route("pages/")
|
||||
def custom_static_supported_pages():
|
||||
"""Serves a list of all watchers that are supported / were registered successfully"""
|
||||
return jsonify(list(custom_static_directories.keys()))
|
||||
|
||||
@custom_static_blueprint.route(
|
||||
"pages/<string:name>/", defaults={"path": "index.html"}
|
||||
)
|
||||
@custom_static_blueprint.route("pages/<string:name>/<path:path>")
|
||||
def custom_static_pages(name: str, path: str):
|
||||
"""Serves the custom static content"""
|
||||
|
||||
if name in custom_static_directories:
|
||||
return send_from_directory(custom_static_directories[name], path)
|
||||
else:
|
||||
return (
|
||||
f"Static content: {escape(path)} of watcher: {escape(name)} not found!",
|
||||
404,
|
||||
)
|
||||
|
||||
return custom_static_blueprint
|
||||
Reference in New Issue
Block a user