Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ jobs:
# A stand-in collector: nothing is sent until the export is on, then the figures of /metrics arrive under the
# same names with the headers given, a refusal is told, and switching it off stops the sending.
run: sh Linux/tests/otlp.sh .build/release/tokenmeter
- name: Desktops other than Plasma
# The installer's check against stand-in folders of Qt, package managers and desktops: the missing parts of
# Qt are named with the command that brings them, GNOME's extension is named, nothing is installed.
run: sh Linux/tests/desktops.sh
- name: The idle service stays within its budget
# Processor time, wake-ups, open files and memory of a service with nothing to watch, over a minute.
# The stand-in engines of the steps above are stopped first: with them it has work to do.
Expand All @@ -372,6 +376,8 @@ jobs:
# The same in the web dashboard (/view/): pairs a browser, taps every building and machine of each drill's
# Machine Room, opens its session, checks every figure is offered to pin, then pins a proof and solves it.
run: |
# The job's container has Swift but no Node.
command -v npm >/dev/null || DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nodejs npm > /dev/null
mkdir -p /tmp/pw && (cd /tmp/pw && npm install --silent playwright@1.48.2 && npx playwright install --with-deps chromium >/dev/null)
mkdir -p /tmp/drill-web
env HOME=/tmp/drill-web TOKENMETER_NAME=drills .build/release/tokenmeter serve --port 7799 >/tmp/drill-web/service.log 2>&1 &
Expand Down
2 changes: 1 addition & 1 deletion Android/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ platform=${ANDROID_PLATFORM:-35}
jar=$sdk/platforms/android-$platform/android.jar
[ -f "$jar" ] || { echo "No $jar: install the platform with sdkmanager \"platforms;android-$platform\"." >&2; exit 1; }
tools=$(ls -d "$sdk"/build-tools/* | sort -V | tail -1)
version=${APP_VERSION:-0.9.11}
version=${APP_VERSION:-0.9.12}
IFS=. read -r major minor patch <<<"$version.0.0"
code=$((major * 10000 + minor * 100 + ${patch%%[^0-9]*}))

Expand Down
151 changes: 145 additions & 6 deletions App/ServiceInstallerSources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ enum ServiceInstallerSources {
# Linux/install.sh --service-only only the service, for a machine without a desktop (a DGX Spark, a server):
# it keeps running after you log out, and other machines' Tokenmeter can read it
# Linux/install.sh --uninstall remove everything but the usage history
# Linux/install.sh --check install nothing: say what this desktop has for the window, the notification
# area icon, the widget and alerts, and which packages bring what is missing
#
# With --service-only, --local-only keeps the service to this machine (other machines can't read it).
#
Expand Down Expand Up @@ -54,15 +56,140 @@ service_only=""
# Not $share, which is the data folder above: --service-only lets other machines read the service unless --local-only.
let_others_read=yes
uninstall=""
check=""
for argument in "$@"; do
case "$argument" in
--uninstall) uninstall=yes ;;
--check) check=yes ;;
--service-only|--headless) service_only=yes ;;
--local-only) let_others_read="" ;;
*) echo "Unknown option $argument. Use --service-only, --local-only or --uninstall." >&2; exit 2 ;;
*) echo "Unknown option $argument. Use --service-only, --local-only, --check or --uninstall." >&2; exit 2 ;;
esac
done

# What the window needs of Qt 6, whatever the desktop (Plasma brings all of it; GNOME, Xfce and others bring little
# or none). Debian and Ubuntu split Qt's QML modules into a package each, so a missing one is named by its package.
# Sets $qml_tool (Qt's `qml` program, empty when there is none), $qml_folder (where Qt keeps its QML modules, empty
# when it can't be found) and $qt_missing (the modules that aren't there, by their import names).
# TOKENMETER_QML_FOLDER names the folder when Qt is somewhere this script does not look.
qt_modules="QtQuick QtQuick.Controls QtQuick.Layouts QtQuick.Templates QtQuick.Window QtQml.WorkerScript QtCore"
look_at_qt() {
qml_tool=""
for candidate in qml6 qml-qt6 /usr/lib/qt6/bin/qml /usr/lib64/qt6/bin/qml; do
if have "$candidate"; then qml_tool=$candidate; break; fi
done
qml_folder=""
asked=""
for tool in qtpaths6 qtpaths-qt6 /usr/lib/qt6/bin/qtpaths /usr/lib64/qt6/bin/qtpaths; do
if have "$tool"; then asked=$("$tool" --query QT_INSTALL_QML 2>/dev/null || true); break; fi
done
for folder in "${TOKENMETER_QML_FOLDER:-}" "$asked" /usr/lib/*/qt6/qml /usr/lib64/qt6/qml /usr/lib/qt6/qml; do
if [ -n "$folder" ] && [ -d "$folder" ]; then qml_folder=$folder; break; fi
done
qt_missing=""
if [ -z "$qml_folder" ]; then
# No folder of modules anywhere: with no `qml` tool either, Qt's QML isn't installed at all.
[ -n "$qml_tool" ] || qt_missing=$qt_modules
return 0
fi
for module in $qt_modules; do
[ -f "$qml_folder/$(echo "$module" | tr . /)/qmldir" ] || qt_missing="$qt_missing $module"
done
# Settings moved into QtCore with Qt 6.5; an older Qt has them in Qt.labs.settings.
if [ -f "$qml_folder/QtCore/plugins.qmltypes" ] && ! grep -qs Settings "$qml_folder/QtCore/plugins.qmltypes" \
&& [ ! -f "$qml_folder/Qt/labs/settings/qmldir" ]; then
qt_missing="$qt_missing Qt.labs.settings"
fi
qt_missing=${qt_missing# }
}

# The command that installs what `look_at_qt` found missing, for this distribution's package manager; empty when
# nothing is missing or the package manager is one this script does not know.
qt_install_line() {
[ -n "$qt_missing" ] || [ -z "$qml_tool" ] || return 0
if have apt-get; then
packages=""
[ -n "$qml_tool" ] || packages="qml-qt6"
for module in $qt_missing; do
case "$module" in
Qt.labs.settings) packages="$packages qml6-module-qt-labs-settings" ;;
*) packages="$packages qml6-module-$(echo "$module" | tr 'A-Z' 'a-z' | sed 's/\./-/')" ;;
esac
done
echo "sudo apt install${packages:+ }${packages# }"
elif have dnf; then echo "sudo dnf install qt6-qtdeclarative-devel"
elif have pacman; then echo "sudo pacman -S --needed qt6-declarative"
elif have zypper; then echo "sudo zypper install qt6-declarative-tools qt6-declarative-imports"
fi
}

# Whether this session has a notification area that shows app icons (a StatusNotifierItem host): "yes", "no", or
# "unknown" when there is no session to ask (an install over SSH). Plasma, Xfce, Cinnamon, MATE, LXQt and COSMIC
# have one; GNOME has one only with the AppIndicator extension, which Ubuntu switches on and Fedora does not.
tray_host() {
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && [ ! -S "${XDG_RUNTIME_DIR:-/nonexistent}/bus" ]; then echo unknown; return 0; fi
if have gdbus; then
answer=$(gdbus call --session --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus \
--method org.freedesktop.DBus.NameHasOwner org.kde.StatusNotifierWatcher 2>/dev/null || true)
elif have dbus-send; then
answer=$(dbus-send --session --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus \
org.freedesktop.DBus.NameHasOwner string:org.kde.StatusNotifierWatcher 2>/dev/null || true)
else
echo unknown; return 0
fi
case "$answer" in *true*) echo yes ;; *false*) echo no ;; *) echo unknown ;; esac
}

# What to do about a desktop with no notification area for app icons, by the desktop's own name.
tray_advice() {
case "${XDG_CURRENT_DESKTOP:-}" in
*GNOME*|*gnome*)
echo "GNOME shows app icons in its top bar only with the \"AppIndicator and KStatusNotifierItem Support\" extension."
if have dnf; then echo " Install it with: sudo dnf install gnome-shell-extension-appindicator"
elif have pacman; then echo " Install it with: sudo pacman -S --needed gnome-shell-extension-appindicator"
elif have apt-get; then echo " Install it with: sudo apt install gnome-shell-extension-appindicator"
elif have zypper; then echo " Install it from https://extensions.gnome.org/extension/615/appindicator-support/"
fi
echo " Then log out and in, switch it on in the Extensions app, and run: tokenmeter-app --tray" ;;
*)
echo "This desktop has no notification area that shows app icons (a StatusNotifierItem tray). Add one to a panel,"
echo " then run: tokenmeter-app --tray" ;;
esac
}

if [ -n "$check" ]; then
look_at_qt
wrong=0
echo "Tokenmeter on this desktop (${XDG_CURRENT_DESKTOP:-no desktop named}):"
if [ -z "$qt_missing" ] && [ -n "$qml_folder" ]; then
echo " The window: Qt 6 has what it needs ($qml_folder)."
elif [ -z "$qt_missing" ]; then
echo " The window: Qt's qml tool is here ($qml_tool), but not where Qt keeps its modules, so they weren't checked."
else
wrong=1
echo " The window: these parts of Qt 6 are missing: $(echo "$qt_missing" | sed 's/ /, /g')."
line=$(qt_install_line); [ -z "$line" ] || echo " $line"
fi
if [ -z "$qml_tool" ] && [ -z "$qt_missing" ]; then
echo " Qt's qml tool is not here; the window then has to be compiled (CMake, a C++ compiler, Qt 6's development files)."
fi
if have cmake && { have c++ || have g++ || have clang++; }; then
echo " The notification area icon: CMake and a C++ compiler are here, so install.sh compiles it."
else
echo " The notification area icon: needs CMake, a C++ compiler and Qt 6's development files to be compiled."
fi
case "$(tray_host)" in
yes) echo " This desktop shows app icons in its notification area." ;;
no) wrong=1; echo " $(tray_advice)" ;;
*) echo " No desktop session to ask whether it shows app icons (run this from a terminal on the desktop)." ;;
esac
if have kpackagetool6; then echo " The widget: Plasma 6 is here."
else echo " The widget: is for Plasma 6 only; on other desktops the notification area icon takes its place."; fi
if have notify-send; then echo " Alerts: notify-send is here."
else echo " Alerts: need notify-send (libnotify on Fedora and Arch, libnotify-bin on Debian and Ubuntu)."; fi
exit $wrong
fi

# The service package (scripts/package-service.sh) carries no app, so from there only the service is installed.
if [ -x "$here/tokenmeter" ] && [ ! -d "$here/kde" ]; then service_only=yes; fi

Expand Down Expand Up @@ -204,9 +331,12 @@ for qml in qml6 qml-qt6 /usr/lib/qt6/bin/qml /usr/lib64/qt6/bin/qml; do
exec "\$qml" "$share/tokenmeter-kde/app/main.qml" -- "\$@"
fi
done
message="Tokenmeter needs Qt 6's QML runtime. Install qt6-declarative (Arch), qml-qt6 (Debian, Ubuntu, KDE neon), qt6-qtdeclarative-devel (Fedora) or qt6-declarative-tools (openSUSE)."
message="Tokenmeter needs Qt 6's QML runtime. Linux/install.sh --check says which packages bring it on this system."
echo "\$message" >&2
command -v kdialog >/dev/null 2>&1 && kdialog --title Tokenmeter --error "\$message"
if command -v kdialog >/dev/null 2>&1; then kdialog --title Tokenmeter --error "\$message"
elif command -v zenity >/dev/null 2>&1; then zenity --error --title Tokenmeter --text "\$message"
elif command -v notify-send >/dev/null 2>&1; then notify-send Tokenmeter "\$message"
fi
exit 1
LAUNCHER
chmod 755 "$bin/tokenmeter-app"
Expand All @@ -225,7 +355,7 @@ else
fi

# The Plasma widget, with its own copy of the shared pages.
widget="No Plasma 6 found (kpackagetool6), so the tray widget was not installed."
widget="The widget is for Plasma 6, which is not here (no kpackagetool6); the notification area icon takes its place."
if have kpackagetool6; then
package=$(mktemp -d)
cp -R "$here/kde/plasmoid/." "$package/"
Expand All @@ -251,7 +381,7 @@ fi

# The icon in the notification area, from the compiled window: started at login (unless it was turned off from
# its menu, which leaves the entry with Hidden=true) and now.
tray="The notification area icon needs the compiled window (see below)."
tray="The notification area icon needs the compiled window (see above)."
pkill -f "tokenmeter-window --tray" 2>/dev/null || true
if [ -n "$window" ]; then
autostart="$config/autostart/tokenmeter-tray.desktop"
Expand All @@ -272,6 +402,8 @@ AUTOSTART
tray="The notification area icon is turned off; start it with: tokenmeter-app --tray (then tick Show Icon at Login in its menu)."
else
tray="Tokenmeter's icon is in the notification area and comes back at login (untick Show Icon at Login in its menu to stop that)."
# A desktop that shows no app icons (GNOME without its extension) is told so, rather than promised an icon.
if [ "$(tray_host)" = no ]; then tray="Tokenmeter's icon is set to start at login, but nothing shows it yet. $(tray_advice)"; fi
if [ -n "${WAYLAND_DISPLAY:-}${DISPLAY:-}" ]; then
nohup "$bin/tokenmeter-app" --tray >/dev/null 2>&1 &
fi
Expand All @@ -281,7 +413,14 @@ fi
echo
echo "Tokenmeter is installed."
echo " $started"
echo " Open the app from the menu, or run: tokenmeter-app"
look_at_qt
if [ -n "$qt_missing" ]; then
echo " The window will NOT open yet: these parts of Qt 6 are missing: $(echo "$qt_missing" | sed 's/ /, /g')."
line=$(qt_install_line); [ -z "$line" ] || echo " $line"
echo " After that, open the app from the menu, or run: tokenmeter-app"
else
echo " Open the app from the menu, or run: tokenmeter-app"
fi
if [ -n "${window_failed:-}" ]; then
# The tools are there but the window didn't compile: said loudly, since the app still opens (with Qt's qml tool)
# and only its icon in the task bar and title bar is missing.
Expand Down
2 changes: 1 addition & 1 deletion App/StatusJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ struct LocalResponse {
extension StatusReport {
/// Tokenmeter's version. The Mac app reads it from its Info.plist, which build-library-app.sh writes; the
/// Linux service has no Info.plist, so it uses `releaseVersion`. Keep that in step with the build scripts.
static let releaseVersion = "0.9.11"
static let releaseVersion = "0.9.12"
static var appVersion: String {
Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? releaseVersion
}
Expand Down
Loading
Loading