Skip to content
Open
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
2 changes: 1 addition & 1 deletion Android/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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.14}
version=${APP_VERSION:-0.9.16}
IFS=. read -r major minor patch <<<"$version.0.0"
code=$((major * 10000 + minor * 100 + ${patch%%[^0-9]*}))

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.14"
static let releaseVersion = "0.9.16"
static var appVersion: String {
Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? releaseVersion
}
Expand Down
2 changes: 1 addition & 1 deletion Linux/kde/app/AppVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// update keeps saying the version it is, while the service reports its own (backend.snapshot.version).
// scripts/package-linux.sh and package-flatpak.sh write it from the package's version; keep it in step with
// StatusReport.releaseVersion when bumping (a unit test checks it).
var version = "0.9.14"
var version = "0.9.16"
2 changes: 1 addition & 1 deletion Linux/kde/mock/machines.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"report": {
"schema": 1,
"app": "Tokenmeter",
"version": "0.9.14",
"version": "0.9.16",
"host": "studio",
"chip": "Apple M3 Ultra",
"time": "2026-11-13T19:00:00Z",
Expand Down
2 changes: 1 addition & 1 deletion Linux/kde/mock/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"addresses": [
"192.168.1.20"
],
"version": "0.9.14",
"version": "0.9.16",
"shareHistory": false,
"footprint": {
"cpuPercent": 0.4,
Expand Down
2 changes: 1 addition & 1 deletion Linux/kde/plasmoid/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Icon": "tokenmeter",
"Category": "System Information",
"License": "Apache-2.0",
"Version": "0.9.14",
"Version": "0.9.16",
"Website": "https://github.com/tokenmeter1/Tokenmeter"
},
"X-Plasma-API-Minimum-Version": "6.0",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Made for KDE Plasma 6; [other desktops](docs/wiki/Install-Linux.md#other-desktop

**NVIDIA DGX Spark** and other machines without a desktop: unpack the service package and run `./install.sh` (on Linux, `install.sh --service-only` from an app tarball does the same). Your Mac or PC then shows it as another machine of its mesh. [More →](docs/wiki/DGX-Spark.md)

**Windows** (10 and 11): the service alone, built with Swift for Windows by `Windows\build.ps1` and installed by `Windows\install.ps1`, and watched from your Mac or Linux desktop as another machine of its mesh. There is no Windows download yet, and it has been compiled on very few machines. [More →](docs/wiki/Windows.md)
**Windows** (10 and 11): the service alone, built with Swift for Windows by `Windows\build.ps1` and installed by `Windows\install.ps1` (or by the `Tokenmeter-<version>-windows-x64.msi` installer that `Windows\build.ps1 -Msi` makes, which releases carry from 0.9.16), and watched from your Mac or Linux desktop as another machine of its mesh. It has been compiled on very few machines. [More →](docs/wiki/Windows.md)

**Phones.** Every machine serves a read-only web dashboard at `/view/`; see [Phones, tablets and the web](#phones-tablets-and-the-web). The Android app is `Tokenmeter-<version>-android.apk` on the release page: copy it to the phone and open it ([Android/](Android/README.md)).

Expand Down
80 changes: 80 additions & 0 deletions Windows/Tokenmeter.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Tokenmeter's service as a Windows installer (MSI), built by Windows\package.ps1 with WiX Toolset 5:

powershell -ExecutionPolicy Bypass -File Windows\build.ps1 -Msi

It does what Windows\install.ps1 does, for this user only and without administrator rights: the service and
the libraries it needs go to %LOCALAPPDATA%\Tokenmeter, and install.ps1 (installed beside them) makes it start
at login and starts it. A newer version installs over an older one, and one installed by install.ps1 is taken
over. Uninstalling (Settings > Apps) stops it and removes the start at login; the usage history is kept.

msiexec /i Tokenmeter-<version>-windows-x64.msi install or update
msiexec /i Tokenmeter-<version>-windows-x64.msi LOCALONLY=1 other machines can't read it

package.ps1 passes the version (Version), the folder of files to install (Stage) and the list of them
(files.wxs, which it writes). Keep UpgradeCode as it is: it is how Windows knows a new MSI replaces the old.
-->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="Tokenmeter Service"
Manufacturer="Tokenmeter"
Version="$(Version)"
UpgradeCode="DF29D25D-41F5-44C5-AD95-5AAAEAC895DE"
Scope="perUser"
Language="1033">
<SummaryInformation Description="Tokenmeter's service: watches the inference servers on this PC for your mesh" />

<!-- The same version again is allowed too, so a rebuilt MSI can be reinstalled. -->
<MajorUpgrade AllowSameVersionUpgrades="yes"
DowngradeErrorMessage="A newer Tokenmeter is already installed. Uninstall it first to go back to this one." />
<MediaTemplate EmbedCab="yes" />

<Property Id="ARPURLINFOABOUT" Value="https://github.com/tokenmeter1/Tokenmeter" />
<Property Id="ARPHELPLINK" Value="https://github.com/tokenmeter1/Tokenmeter/blob/main/docs/wiki/Windows.md" />
<Property Id="ARPNOMODIFY" Value="1" />
<Property Id="ARPNOREPAIR" Value="1" />
<!-- msiexec ... LOCALONLY=1 keeps the service to this PC, as install.ps1 -LocalOnly does. -->
<Property Id="LOCALONLY" Secure="yes" />

<StandardDirectory Id="LocalAppDataFolder">
<Directory Id="INSTALLFOLDER" Name="Tokenmeter" />
</StandardDirectory>

<Feature Id="Service" Title="Tokenmeter's service" Level="1">
<ComponentGroupRef Id="ServiceFiles" />
</Feature>

<!--
install.ps1 -Msi does the parts Windows Installer has no element for, as the user, with no window:
stopping the running service, the scheduled task that starts it at login (or a Startup shortcut where
Windows won't let the account make a task), and starting it. A failure there doesn't undo the install;
it is in the installer's log (msiexec /l*v log.txt).
-->
<SetProperty Id="TmLocalOnly" Value="-LocalOnly" Condition="LOCALONLY" After="CostFinalize" Sequence="execute" />

<!-- Before files are replaced or removed: the running service would hold them. (No braces in these
values: Windows Installer reads {...} as a group of its own.) -->
<SetProperty Id="TmStop" Before="TmStop" Sequence="execute"
Value="&quot;[SystemFolder]WindowsPowerShell\v1.0\powershell.exe&quot; -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command &quot;Get-Process -Name tokenmeter -ErrorAction SilentlyContinue | Where-Object Path -eq '[INSTALLFOLDER]tokenmeter.exe' | Stop-Process -Force; Start-Sleep -Milliseconds 500&quot;" />
<CustomAction Id="TmStop" BinaryRef="Wix4UtilCA_$(sys.BUILDARCHSHORT)" DllEntry="WixQuietExec"
Execute="deferred" Impersonate="yes" Return="ignore" />

<!-- Uninstalled for good (not replaced by a newer version): no more start at login. -->
<SetProperty Id="TmUnregister" Before="TmUnregister" Sequence="execute"
Value="&quot;[SystemFolder]WindowsPowerShell\v1.0\powershell.exe&quot; -NoProfile -NonInteractive -ExecutionPolicy Bypass -File &quot;[INSTALLFOLDER]install.ps1&quot; -Msi -Uninstall" />
<CustomAction Id="TmUnregister" BinaryRef="Wix4UtilCA_$(sys.BUILDARCHSHORT)" DllEntry="WixQuietExec"
Execute="deferred" Impersonate="yes" Return="ignore" />

<!-- Installed or updated: start at login, and start it now. -->
<SetProperty Id="TmRegister" Before="TmRegister" Sequence="execute"
Value="&quot;[SystemFolder]WindowsPowerShell\v1.0\powershell.exe&quot; -NoProfile -NonInteractive -ExecutionPolicy Bypass -File &quot;[INSTALLFOLDER]install.ps1&quot; -Msi [TmLocalOnly]" />
<CustomAction Id="TmRegister" BinaryRef="Wix4UtilCA_$(sys.BUILDARCHSHORT)" DllEntry="WixQuietExec"
Execute="deferred" Impersonate="yes" Return="ignore" />

<InstallExecuteSequence>
<Custom Action="TmStop" Before="RemoveFiles" />
<Custom Action="TmUnregister" After="TmStop" Condition="REMOVE~=&quot;ALL&quot; AND NOT UPGRADINGPRODUCTCODE" />
<Custom Action="TmRegister" After="InstallFiles" Condition="NOT REMOVE~=&quot;ALL&quot;" />
</InstallExecuteSequence>
</Package>
</Wix>
10 changes: 10 additions & 0 deletions Windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# It needs the Swift toolchain for Windows (https://www.swift.org/install/windows, or
# `winget install --id Swift.Toolchain -e`), which brings the Visual Studio build tools and the Windows SDK.
# The service is left at .build\release\tokenmeter.exe; Windows\install.ps1 installs it.
#
# powershell -ExecutionPolicy Bypass -File Windows\build.ps1 -Msi
#
# also packs it as dist\Tokenmeter-<version>-windows-x64.msi for a release (Windows\package.ps1, which needs WiX).
param([switch]$Msi)
$ErrorActionPreference = "Stop"
$project = Split-Path -Parent $PSScriptRoot
Set-Location $project
Expand All @@ -29,7 +34,12 @@ $ErrorActionPreference = "Stop"
if ($code -eq 0) {
Write-Host ""
Write-Host "Built: .build\release\tokenmeter.exe"
if ($Msi) {
& (Join-Path $PSScriptRoot "package.ps1")
exit $LASTEXITCODE
}
Write-Host "Install it with: powershell -ExecutionPolicy Bypass -File Windows\install.ps1"
Write-Host "Or pack it as an MSI for a release: powershell -ExecutionPolicy Bypass -File Windows\package.ps1"
exit 0
}

Expand Down
48 changes: 36 additions & 12 deletions Windows/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
#
# The service is taken from a tokenmeter.exe next to this script, else from .build\release (Windows\build.ps1
# builds it there). It goes to %LOCALAPPDATA%\Tokenmeter and answers on port 7733.
param([switch]$LocalOnly, [switch]$Uninstall)
#
# The MSI (Windows\package.ps1) installs this script beside the service and runs it with -Msi: the files are
# already in place, so it only sets up the start at login and starts the service (with -Uninstall, it only stops
# the service and removes the start at login, leaving the files to the installer).
param([switch]$LocalOnly, [switch]$Uninstall, [switch]$Msi)
$ErrorActionPreference = "Stop"

$project = Split-Path -Parent $PSScriptRoot
$folder = Join-Path $env:LOCALAPPDATA "Tokenmeter"
# Run by the MSI, this script is in the folder the MSI installed to.
if ($Msi) { $folder = $PSScriptRoot }
$program = Join-Path $folder "tokenmeter.exe"
$task = "Tokenmeter"
$shortcut = Join-Path ([Environment]::GetFolderPath("Startup")) "Tokenmeter.lnk"
Expand All @@ -25,23 +31,32 @@ if ($Uninstall) {
Stop-Service-Process
& schtasks.exe /Delete /TN $task /F 2>$null | Out-Null
Remove-Item $shortcut -ErrorAction SilentlyContinue
if ($Msi) { exit 0 }
Remove-Item $program -ErrorAction SilentlyContinue
Write-Host "Tokenmeter's service is removed. Its usage history is kept."
exit 0
}

$source = @((Join-Path $PSScriptRoot "tokenmeter.exe"), (Join-Path $project ".build\release\tokenmeter.exe")) |
Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $source) {
Write-Host "There is no tokenmeter.exe to install. Build it first: powershell -ExecutionPolicy Bypass -File Windows\build.ps1"
exit 1
}
if ($Msi) {
if (-not (Test-Path $program)) {
Write-Host "The installer didn't leave $program."
exit 1
}
Stop-Service-Process
} else {
$source = @((Join-Path $PSScriptRoot "tokenmeter.exe"), (Join-Path $project ".build\release\tokenmeter.exe")) |
Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $source) {
Write-Host "There is no tokenmeter.exe to install. Build it first: powershell -ExecutionPolicy Bypass -File Windows\build.ps1"
exit 1
}

New-Item -ItemType Directory -Force -Path $folder | Out-Null
Stop-Service-Process
Copy-Item $source $program -Force
# The libraries a build leaves beside the program (Swift's own are found through PATH on a machine with Swift).
Get-ChildItem (Split-Path -Parent $source) -Filter *.dll -ErrorAction SilentlyContinue | Copy-Item -Destination $folder -Force
New-Item -ItemType Directory -Force -Path $folder | Out-Null
Stop-Service-Process
Copy-Item $source $program -Force
# The libraries a build leaves beside the program (Swift's own are found through PATH on a machine with Swift).
Get-ChildItem (Split-Path -Parent $source) -Filter *.dll -ErrorAction SilentlyContinue | Copy-Item -Destination $folder -Force
}

$arguments = if ($LocalOnly) { "serve" } else { "serve --network" }

Expand Down Expand Up @@ -69,10 +84,19 @@ try {

if ($made) {
Start-ScheduledTask -TaskName $task
} elseif ($Msi) {
# Started through WMI, so it holds none of the installer's handles (the installer waits for those to close).
Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = "`"$program`" $arguments"; CurrentDirectory = $folder } | Out-Null
} else {
Start-Process -FilePath $program -ArgumentList $arguments -WorkingDirectory $folder -WindowStyle Minimized
}

# The installer has its own window to finish; it doesn't wait for the service to answer.
if ($Msi) {
Write-Host "Tokenmeter's service is started$(if ($made) { ' by the scheduled task' } else { ' and has a Startup shortcut' })."
exit 0
}

# Wait for it to answer.
$answer = $null
for ($try = 0; $try -lt 20 -and -not $answer; $try++) {
Expand Down
Loading
Loading