From 8d4447f55afe22bcf188af789f6d9704a3796489 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 17:20:48 +0000 Subject: [PATCH 1/2] Windows MSI installer, built on Windows, uploaded by release.sh (0.9.15) Windows\build.ps1 -Msi (or Windows\package.ps1 after a build) packs the service as dist\Tokenmeter--windows-x64.msi with WiX Toolset 5: a per-user MSI into %LOCALAPPDATA%\Tokenmeter with tokenmeter.exe, the build's DLLs, the Swift runtime and the MSVC C++ runtime. install.ps1 -Msi, installed beside it, sets up the logon task (or Startup shortcut) and starts the service; on uninstall it stops it and removes the start at login. Fixed UpgradeCode, version from App/StatusJSON.swift, LOCALONLY=1 for -LocalOnly. scripts/release.sh lists the MSI as missing when absent (it already uploads Tokenmeter--* files). Docs: Windows.md, Development.md, README. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EE8zWAHw1r9vF2poUMU2hD Co-Authored-By: tokenmeter1 <358883051+tokenmeter1@users.noreply.github.com> --- Android/build.sh | 2 +- App/StatusJSON.swift | 2 +- Linux/kde/app/AppVersion.js | 2 +- Linux/kde/mock/machines.json | 2 +- Linux/kde/mock/settings.json | 2 +- Linux/kde/plasmoid/metadata.json | 2 +- README.md | 2 +- Windows/Tokenmeter.wxs | 80 ++++++++++++++++ Windows/build.ps1 | 10 ++ Windows/install.ps1 | 48 +++++++--- Windows/package.ps1 | 160 +++++++++++++++++++++++++++++++ build-library-app.sh | 2 +- docs/wiki/Development.md | 4 +- docs/wiki/Windows.md | 31 +++++- scripts/package-flatpak.sh | 2 +- scripts/package-linux.sh | 2 +- scripts/package-service.sh | 2 +- scripts/package.sh | 2 +- scripts/release.sh | 3 + 19 files changed, 333 insertions(+), 27 deletions(-) create mode 100644 Windows/Tokenmeter.wxs create mode 100644 Windows/package.ps1 diff --git a/Android/build.sh b/Android/build.sh index 76d8a966..4e142d10 100755 --- a/Android/build.sh +++ b/Android/build.sh @@ -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.15} IFS=. read -r major minor patch <<<"$version.0.0" code=$((major * 10000 + minor * 100 + ${patch%%[^0-9]*})) diff --git a/App/StatusJSON.swift b/App/StatusJSON.swift index 1d45e6b6..ae5ff2e1 100644 --- a/App/StatusJSON.swift +++ b/App/StatusJSON.swift @@ -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.15" static var appVersion: String { Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? releaseVersion } diff --git a/Linux/kde/app/AppVersion.js b/Linux/kde/app/AppVersion.js index 1d09cd58..171afd28 100644 --- a/Linux/kde/app/AppVersion.js +++ b/Linux/kde/app/AppVersion.js @@ -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.15" diff --git a/Linux/kde/mock/machines.json b/Linux/kde/mock/machines.json index af14fa11..6ea44471 100644 --- a/Linux/kde/mock/machines.json +++ b/Linux/kde/mock/machines.json @@ -7,7 +7,7 @@ "report": { "schema": 1, "app": "Tokenmeter", - "version": "0.9.14", + "version": "0.9.15", "host": "studio", "chip": "Apple M3 Ultra", "time": "2026-11-13T19:00:00Z", diff --git a/Linux/kde/mock/settings.json b/Linux/kde/mock/settings.json index db3cba17..a9e8e599 100644 --- a/Linux/kde/mock/settings.json +++ b/Linux/kde/mock/settings.json @@ -15,7 +15,7 @@ "addresses": [ "192.168.1.20" ], - "version": "0.9.14", + "version": "0.9.15", "shareHistory": false, "footprint": { "cpuPercent": 0.4, diff --git a/Linux/kde/plasmoid/metadata.json b/Linux/kde/plasmoid/metadata.json index 8a841141..947738b6 100644 --- a/Linux/kde/plasmoid/metadata.json +++ b/Linux/kde/plasmoid/metadata.json @@ -7,7 +7,7 @@ "Icon": "tokenmeter", "Category": "System Information", "License": "Apache-2.0", - "Version": "0.9.14", + "Version": "0.9.15", "Website": "https://github.com/tokenmeter1/Tokenmeter" }, "X-Plasma-API-Minimum-Version": "6.0", diff --git a/README.md b/README.md index 294b5950..b88d3eae 100644 --- a/README.md +++ b/README.md @@ -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--windows-x64.msi` installer that `Windows\build.ps1 -Msi` makes, which releases carry from 0.9.15), 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--android.apk` on the release page: copy it to the phone and open it ([Android/](Android/README.md)). diff --git a/Windows/Tokenmeter.wxs b/Windows/Tokenmeter.wxs new file mode 100644 index 00000000..d8a9c97f --- /dev/null +++ b/Windows/Tokenmeter.wxs @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Windows/build.ps1 b/Windows/build.ps1 index e9bff788..7dbbacec 100644 --- a/Windows/build.ps1 +++ b/Windows/build.ps1 @@ -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--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 @@ -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 } diff --git a/Windows/install.ps1 b/Windows/install.ps1 index 474dd026..96cd6033 100644 --- a/Windows/install.ps1 +++ b/Windows/install.ps1 @@ -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" @@ -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" } @@ -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++) { diff --git a/Windows/package.ps1 b/Windows/package.ps1 new file mode 100644 index 00000000..f6e24ae5 --- /dev/null +++ b/Windows/package.ps1 @@ -0,0 +1,160 @@ +# Packs the service that Windows\build.ps1 built into a Windows installer, for a release: +# +# powershell -ExecutionPolicy Bypass -File Windows\package.ps1 (or Windows\build.ps1 -Msi, which builds first) +# +# It writes dist\Tokenmeter--windows-x64.msi (-arm64 on an Arm PC). Copy that file into the dist folder +# that scripts/release.sh uploads from. The MSI installs for the user who runs it, without administrator rights, +# and does what Windows\install.ps1 does (Windows\Tokenmeter.wxs says how). +# +# It holds tokenmeter.exe, the libraries the build left beside it, Swift's runtime libraries and Microsoft's C++ +# runtime, so the PC it is installed on needs neither Swift nor Visual Studio. +# +# It needs WiX Toolset 5, a .NET tool, installed once: +# winget install Microsoft.DotNet.SDK.8 +# dotnet tool install --global wix --version 5.0.2 +# (the Util extension it also needs is added the first time this runs). +# +# -Version 0.9.15 the version written into the MSI and its name (default: App\StatusJSON.swift's, which is the +# version the service itself reports) +# -Out where the MSI goes (default: dist) +param([string]$Version, [string]$Out) +$ErrorActionPreference = "Stop" +$project = Split-Path -Parent $PSScriptRoot +Set-Location $project +$wixVersion = "5.0.2" + +$program = Join-Path $project ".build\release\tokenmeter.exe" +if (-not (Test-Path $program)) { + Write-Host "There is no service to pack. Build it first: powershell -ExecutionPolicy Bypass -File Windows\build.ps1" + exit 1 +} + +if (-not $Version) { + $line = Select-String -Path (Join-Path $project "App\StatusJSON.swift") -Pattern 'static let releaseVersion = "([0-9.]+)"' | Select-Object -First 1 + if (-not $line) { Write-Host "App\StatusJSON.swift says no releaseVersion: give one with -Version."; exit 1 } + $Version = $line.Matches[0].Groups[1].Value +} +$Version = $Version.TrimStart("v") +if ($Version -notmatch '^\d+\.\d+\.\d+$') { Write-Host "$Version isn't a version such as 0.9.15."; exit 1 } + +if (-not (Get-Command wix -ErrorAction SilentlyContinue)) { + Write-Host "WiX Toolset isn't installed, or isn't in PATH. Install it once with:" + Write-Host " winget install Microsoft.DotNet.SDK.8" + Write-Host " dotnet tool install --global wix --version $wixVersion" + Write-Host "Then open a new terminal and run this again." + exit 1 +} +$ErrorActionPreference = "Continue" +$extensions = (& wix extension list -g 2>&1 | ForEach-Object { "$_" }) -join "`n" +if ($extensions -notmatch "WixToolset.Util.wixext") { + & wix extension add -g "WixToolset.Util.wixext/$wixVersion" + if ($LASTEXITCODE -ne 0) { Write-Host "WiX's Util extension couldn't be added."; exit 1 } +} +$ErrorActionPreference = "Stop" + +# x64, or arm64 on an Arm PC (the build is for the PC it ran on). +$arch = if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "x64" } + +# Everything to install, in one folder. +$work = Join-Path $project ".build\msi" +$stage = Join-Path $work "stage" +Remove-Item $work -Recurse -Force -ErrorAction SilentlyContinue +New-Item -ItemType Directory -Force -Path $stage | Out-Null +Copy-Item $program $stage +Copy-Item (Join-Path $PSScriptRoot "install.ps1") $stage +Get-ChildItem (Split-Path -Parent $program) -Filter *.dll -ErrorAction SilentlyContinue | Copy-Item -Destination $stage + +# Swift's runtime: the folder of swiftCore.dll that this PC's Swift uses (it is in PATH), else the newest one +# installed. Every library there goes in; the build's own copies, taken above, are kept. +# (Windows PowerShell takes a program's error output for a failure, so this part doesn't stop on it.) +$ErrorActionPreference = "Continue" +$runtime = $null +$found = & where.exe swiftCore.dll 2>$null | Select-Object -First 1 +if ($found) { $runtime = Split-Path -Parent $found } +if (-not $runtime) { + $runtime = @("$env:LOCALAPPDATA\Programs\Swift\Runtimes", "$env:ProgramFiles\Swift\Runtimes") | + ForEach-Object { Get-ChildItem $_ -Directory -ErrorAction SilentlyContinue } | + Sort-Object { try { [version]$_.Name } catch { [version]"0.0" } } -Descending | + ForEach-Object { Join-Path $_.FullName "usr\bin" } | + Where-Object { Test-Path (Join-Path $_ "swiftCore.dll") } | Select-Object -First 1 +} +if (-not $runtime) { + Write-Host "Swift's runtime (swiftCore.dll) wasn't found: is the Swift toolchain installed?" + exit 1 +} +Get-ChildItem $runtime -Filter *.dll | Where-Object { -not (Test-Path (Join-Path $stage $_.Name)) } | Copy-Item -Destination $stage +Write-Host "Swift's runtime from $runtime" + +# Microsoft's C++ runtime (vcruntime140.dll and the others), which Swift's libraries need. Most PCs have it, but +# not every one: it comes from the Visual Studio build tools that Swift installed, which may give it away with a +# program (app-local). +$crt = $null +$vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe" +if (Test-Path $vswhere) { + $studio = & $vswhere -latest -products * -property installationPath | Select-Object -First 1 + if ($studio) { + $crt = Get-ChildItem (Join-Path $studio "VC\Redist\MSVC") -Directory -ErrorAction SilentlyContinue | + Sort-Object { try { [version]$_.Name } catch { [version]"0.0" } } -Descending | + ForEach-Object { Get-ChildItem (Join-Path $_.FullName $arch) -Directory -Filter "Microsoft.VC*.CRT" -ErrorAction SilentlyContinue } | + Select-Object -First 1 + } +} +$ErrorActionPreference = "Stop" +if ($crt) { + Get-ChildItem $crt.FullName -Filter *.dll | Where-Object { -not (Test-Path (Join-Path $stage $_.Name)) } | Copy-Item -Destination $stage + Write-Host "C++ runtime from $($crt.FullName)" +} else { + Write-Host "Microsoft's C++ runtime wasn't found beside Visual Studio: the MSI is made without it, and a PC that" + Write-Host "lacks it needs the Visual C++ Redistributable (https://aka.ms/vs/17/release/vc_redist.$arch.exe)." +} + +# The list of files for Tokenmeter.wxs. One component holds them all, kept by a value under HKCU as a per-user +# install must be; a new version replaces the whole of the old one (MajorUpgrade), so the list may change freely. +function Escape([string]$text) { [Security.SecurityElement]::Escape($text) } +$entries = New-Object System.Collections.Generic.List[string] +$index = 0 +foreach ($file in Get-ChildItem $stage -File | Sort-Object Name) { + $index++ + $id = if ($file.Name -eq "tokenmeter.exe") { "TokenmeterExe" } else { "File$index" } + $entries.Add(" ") +} +$files = @" + + + + + + + + +$($entries -join "`n") + + + + +"@ +$filesWxs = Join-Path $work "files.wxs" +Set-Content -Path $filesWxs -Value $files -Encoding UTF8 + +if (-not $Out) { $Out = Join-Path $project "dist" } +New-Item -ItemType Directory -Force -Path $Out | Out-Null +$msi = Join-Path (Resolve-Path $Out) "Tokenmeter-$Version-windows-$arch.msi" +Remove-Item $msi -ErrorAction SilentlyContinue + +$ErrorActionPreference = "Continue" +& wix build -arch $arch -ext WixToolset.Util.wixext -d "Version=$Version" -o $msi (Join-Path $PSScriptRoot "Tokenmeter.wxs") $filesWxs 2>&1 | ForEach-Object { "$_" } +$code = $LASTEXITCODE +$ErrorActionPreference = "Stop" +if ($code -ne 0 -or -not (Test-Path $msi)) { + Write-Host "" + Write-Host "WiX couldn't make the MSI (above is what it said)." + exit 1 +} +# wix leaves its debug symbols beside the MSI; the release doesn't carry them. +Remove-Item ([IO.Path]::ChangeExtension($msi, ".wixpdb")) -ErrorAction SilentlyContinue + +$size = "{0:N1} MB" -f ((Get-Item $msi).Length / 1MB) +Write-Host "" +Write-Host "Made: $msi ($size, $($entries.Count) files)" +Write-Host "Try it here with: msiexec /i `"$msi`" /l*v `"$work\install.log`"" +Write-Host "For a release, copy it into the dist folder you give scripts/release.sh." diff --git a/build-library-app.sh b/build-library-app.sh index 00b486a0..d2809eb8 100755 --- a/build-library-app.sh +++ b/build-library-app.sh @@ -18,7 +18,7 @@ for word in "$@"; do esac done app="$project_dir/Tokenmeter.app" -version=${APP_VERSION:-0.9.14} +version=${APP_VERSION:-0.9.15} build=${APP_BUILD:-1} # SwiftUI's @State is a compiler macro in the macOS 26 SDK. The Command Line Tools ship that SDK without diff --git a/docs/wiki/Development.md b/docs/wiki/Development.md index 8efc1cdf..766e949c 100644 --- a/docs/wiki/Development.md +++ b/docs/wiki/Development.md @@ -141,6 +141,8 @@ scripts/package-flatpak.sh # on Linux: the Flatpak Android/build.sh # with the Android SDK: the Android app, signed with your kept key ``` +On Windows, `Windows\build.ps1 -Msi` makes `dist\Tokenmeter--windows-x64.msi` (it needs WiX Toolset 5: [Windows](Windows.md#make-the-msi-for-a-release)). Copy it into the `dist` folder of the machine you release from. + Then `scripts/release.sh` makes the tag and the release on GitHub and uploads the files. It builds nothing: ```sh @@ -149,7 +151,7 @@ scripts/release.sh dist # tag v, publish, upload scripts/release.sh ~/mac-dist ~/linux-dist # packages gathered from several machines ``` -It takes the version from the file names, checks each service package against its `.sha256` (and makes the checksum file where one is missing), lists what a whole release would also carry (the Android app among them, `Tokenmeter--android.apk`), and asks before it publishes. Run it again from another machine to add that machine's packages to the same release: files the release already has are left alone (`--replace` uploads them again). `--draft` leaves the release for you to look at first; a draft is offered to nobody. The tag points at the commit checked out where you run it (`--commit` names another), which must be pushed. It needs GitHub's `gh` tool, signed in once with `gh auth login`. `scripts/release.sh --help` lists the rest. +It takes the version from the file names, checks each service package against its `.sha256` (and makes the checksum file where one is missing), lists what a whole release would also carry (the Android app among them, `Tokenmeter--android.apk`, and the Windows installer, `Tokenmeter--windows-x64.msi`), and asks before it publishes. Run it again from another machine to add that machine's packages to the same release: files the release already has are left alone (`--replace` uploads them again). `--draft` leaves the release for you to look at first; a draft is offered to nobody. The tag points at the commit checked out where you run it (`--commit` names another), which must be pushed. It needs GitHub's `gh` tool, signed in once with `gh auth login`. `scripts/release.sh --help` lists the rest. **By a tag**, when GitHub Actions is available: pushing a tag such as `v0.7.0` runs the release workflow, which tests, builds that version, and publishes a GitHub release with an ad-hoc signed DMG, the Linux tarballs (x86_64, and aarch64 built under QEMU) and the Flatpak. It leaves out the Android app, which would be signed with a key made for that run and so couldn't update the app on a phone: add it with `scripts/release.sh dist` after `Android/build.sh`. One or the other for a version: a release made by `release.sh` makes the tag too, which starts this workflow where Actions runs; it then stops at its publish step because the release is already there, and changes nothing. diff --git a/docs/wiki/Windows.md b/docs/wiki/Windows.md index af38b24a..9e3bb037 100644 --- a/docs/wiki/Windows.md +++ b/docs/wiki/Windows.md @@ -4,6 +4,18 @@ Tokenmeter's **service** runs on Windows 10 and 11. There is no Tokenmeter windo > This is new and has been compiled on very few machines. The service was written on Linux, where the parts that read Windows' own commands are tested, but the calls into Windows itself can only be checked by building on Windows. If the build fails, [open an issue](https://github.com/tokenmeter1/Tokenmeter/issues) with the file `Windows\build.ps1` writes. +## Install it from a release + +From 0.9.15 a release can carry `Tokenmeter--windows-x64.msi`. Open it, or run `msiexec /i Tokenmeter--windows-x64.msi`. It installs for your account only and asks for no administrator rights: the service, Swift's runtime libraries and Microsoft's C++ runtime go to `%LOCALAPPDATA%\Tokenmeter`, and it starts the service and makes it start when you log in, just as `Windows\install.ps1` does (below). Nothing else needs to be installed on the PC. + +- `msiexec /i Tokenmeter--windows-x64.msi LOCALONLY=1` keeps the service to the PC (as `-LocalOnly` does). Give it again with each new version, or the new one lets other machines read it again. +- A newer MSI installs over the old one, and over a service that `install.ps1` installed. +- Uninstall it from **Settings > Apps** (it is listed as **Tokenmeter Service**). The usage history is kept. +- The MSI isn't signed, so Windows SmartScreen may warn the first time: choose **More info**, then **Run anyway**. +- When something goes wrong, `msiexec /i Tokenmeter--windows-x64.msi /l*v install.log` writes what happened to `install.log`. + +Then [add it to your mesh](#3-add-it-to-your-mesh). + ## 1. Build it You need the [Swift toolchain for Windows](https://www.swift.org/install/windows) (`winget install --id Swift.Toolchain -e`, which brings Visual Studio's build tools and the Windows SDK) and Git. In a new terminal: @@ -28,7 +40,22 @@ This copies the service to `%LOCALAPPDATA%\Tokenmeter`, starts it, and makes it - `-Uninstall` removes the service and keeps the usage history. - Check it with `%LOCALAPPDATA%\Tokenmeter\tokenmeter.exe status`. -The PC that built the service has Swift's own libraries. To run it on another PC, install the Swift toolchain there too, or copy the Swift runtime's DLLs beside `tokenmeter.exe`. +The PC that built the service has Swift's own libraries. To run it on another PC, install the MSI there (next section), or install the Swift toolchain there too, or copy the Swift runtime's DLLs beside `tokenmeter.exe`. + +## Make the MSI (for a release) + +`Windows\build.ps1 -Msi` builds the service and packs it as `dist\Tokenmeter--windows-x64.msi` (`-arm64` on an Arm PC); `Windows\package.ps1` packs a service that is already built. The version is the one the service reports (`App\StatusJSON.swift`), or give another with `Windows\package.ps1 -Version 0.9.15`. It needs WiX Toolset 5, a .NET tool, installed once: + +```powershell +winget install Microsoft.DotNet.SDK.8 +dotnet tool install --global wix --version 5.0.2 +``` + +The script adds WiX's Util extension itself the first time. The MSI holds `tokenmeter.exe`, any DLLs the build left beside it, every DLL of the Swift runtime the build used (the folder of `swiftCore.dll` in `PATH`) and Microsoft's C++ runtime from the Visual Studio build tools that Swift installed. What it installs and runs is in `Windows\Tokenmeter.wxs`; the start at login is `install.ps1 -Msi`, installed beside the service. + +Copy the MSI into the `dist` folder on the machine you release from, and `scripts/release.sh dist` uploads it with the other packages ([Releases](Development.md#releases)). + +Signing is optional. With a code-signing certificate, sign the MSI before it is uploaded (`signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /f cert.pfx /p Tokenmeter--windows-x64.msi`), and SmartScreen stops warning once the certificate has a reputation. ## 3. Add it to your mesh @@ -45,4 +72,4 @@ On your Mac or Linux desktop the PC shows up on the **Mesh** page by itself when | Processes and ports | Which program listens on which port and how much memory it uses, from `tasklist` and `netstat`. | | Engine Proxy, MCP Proxy, agents' reports, the mesh, alerts | As on Linux. | -Not read yet on Windows: AMD and Intel graphics cards, load of each core, temperatures other than the NVIDIA cards', traffic of disks and network cards, the processor's own watts, and how much of the processor each program uses. A Windows PC can't yet be updated or installed from another machine of the mesh: run `Windows\build.ps1` and `Windows\install.ps1` again for a new version. +Not read yet on Windows: AMD and Intel graphics cards, load of each core, temperatures other than the NVIDIA cards', traffic of disks and network cards, the processor's own watts, and how much of the processor each program uses. A Windows PC can't yet be updated or installed from another machine of the mesh: install the new version's MSI, or run `Windows\build.ps1` and `Windows\install.ps1` again. diff --git a/scripts/package-flatpak.sh b/scripts/package-flatpak.sh index 35ab0f6f..765cbc36 100755 --- a/scripts/package-flatpak.sh +++ b/scripts/package-flatpak.sh @@ -7,7 +7,7 @@ # Needs flatpak and flatpak-builder; the KDE runtime and SDK are fetched from Flathub. set -eu project_dir=$(cd "$(dirname "$0")/.." && pwd) -version=${APP_VERSION:-0.9.14} +version=${APP_VERSION:-0.9.15} arch=$(uname -m) id=io.github.tokenmeter1.tokenmeter name="Tokenmeter-$version-linux-$arch" diff --git a/scripts/package-linux.sh b/scripts/package-linux.sh index d1f72f1c..2b763281 100755 --- a/scripts/package-linux.sh +++ b/scripts/package-linux.sh @@ -4,7 +4,7 @@ # and install.sh. Needs the Swift toolchain; run it on Linux. set -eu project_dir=$(cd "$(dirname "$0")/.." && pwd) -version=${APP_VERSION:-0.9.14} +version=${APP_VERSION:-0.9.15} arch=$(uname -m) name="Tokenmeter-$version-linux-$arch" diff --git a/scripts/package-service.sh b/scripts/package-service.sh index 70427745..49b04cf7 100755 --- a/scripts/package-service.sh +++ b/scripts/package-service.sh @@ -18,7 +18,7 @@ # On a Mac, SIGN_IDENTITY signs the program with a Developer ID; without it the program is ad-hoc signed. set -eu project_dir=$(cd "$(dirname "$0")/.." && pwd) -version=${APP_VERSION:-0.9.14} +version=${APP_VERSION:-0.9.15} case "$(uname -s)" in Darwin) os=macos ;; Linux) os=linux ;; diff --git a/scripts/package.sh b/scripts/package.sh index d5af922a..faa91b62 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -16,7 +16,7 @@ set -euo pipefail project_dir=${0:A:h:h} app="$project_dir/Tokenmeter.app" dist="$project_dir/dist" -export APP_VERSION=${APP_VERSION:-0.9.14} +export APP_VERSION=${APP_VERSION:-0.9.15} identity=${SIGN_IDENTITY:-} profile=${NOTARY_PROFILE:-} diff --git a/scripts/release.sh b/scripts/release.sh index 91ad5fe9..9ac15224 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -16,6 +16,7 @@ # Tokenmeter--linux-.tar.gz and .flatpak scripts/package-linux.sh, scripts/package-flatpak.sh # tokenmeter-service--.tar.gz + .sha256 scripts/package-service.sh (the Mac one comes with package.sh) # Tokenmeter--android.apk Android/build.sh (signed with your kept key) +# Tokenmeter--windows-x64.msi Windows/build.ps1 -Msi, on Windows (copy it here) # The service packages are what the machines of a mesh download when they update: each is checked against its # .sha256 first, and gets one written when it has none. # @@ -154,6 +155,8 @@ for arch in x86_64 aarch64; do done has "^Tokenmeter-$version-linux-x86_64\.flatpak$" || missing="$missing the Flatpak (Tokenmeter-$version-linux-x86_64.flatpak, from scripts/package-flatpak.sh)" +has "^Tokenmeter-$version-windows-(x64|arm64)\.msi$" || missing="$missing + the Windows installer (Tokenmeter-$version-windows-x64.msi, from Windows/build.ps1 -Msi on Windows: copy it into this folder)" if ! has "^Tokenmeter-$version-android\.apk$"; then missing="$missing the Android app (Tokenmeter-$version-android.apk, from Android/build.sh, which writes it to dist/)" From f7299e5cf066bb52797f3b8420a55f59add52dd8 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 17:22:00 +0000 Subject: [PATCH 2/2] Version 0.9.16 (0.9.15 is taken by #157) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EE8zWAHw1r9vF2poUMU2hD Co-Authored-By: tokenmeter1 <358883051+tokenmeter1@users.noreply.github.com> --- Android/build.sh | 2 +- App/StatusJSON.swift | 2 +- Linux/kde/app/AppVersion.js | 2 +- Linux/kde/mock/machines.json | 2 +- Linux/kde/mock/settings.json | 2 +- Linux/kde/plasmoid/metadata.json | 2 +- README.md | 2 +- Windows/package.ps1 | 4 ++-- build-library-app.sh | 2 +- docs/wiki/Windows.md | 4 ++-- scripts/package-flatpak.sh | 2 +- scripts/package-linux.sh | 2 +- scripts/package-service.sh | 2 +- scripts/package.sh | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Android/build.sh b/Android/build.sh index 4e142d10..06a38431 100755 --- a/Android/build.sh +++ b/Android/build.sh @@ -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.15} +version=${APP_VERSION:-0.9.16} IFS=. read -r major minor patch <<<"$version.0.0" code=$((major * 10000 + minor * 100 + ${patch%%[^0-9]*})) diff --git a/App/StatusJSON.swift b/App/StatusJSON.swift index ae5ff2e1..44110f53 100644 --- a/App/StatusJSON.swift +++ b/App/StatusJSON.swift @@ -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.15" + static let releaseVersion = "0.9.16" static var appVersion: String { Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? releaseVersion } diff --git a/Linux/kde/app/AppVersion.js b/Linux/kde/app/AppVersion.js index 171afd28..c018644f 100644 --- a/Linux/kde/app/AppVersion.js +++ b/Linux/kde/app/AppVersion.js @@ -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.15" +var version = "0.9.16" diff --git a/Linux/kde/mock/machines.json b/Linux/kde/mock/machines.json index 6ea44471..7a99bb8b 100644 --- a/Linux/kde/mock/machines.json +++ b/Linux/kde/mock/machines.json @@ -7,7 +7,7 @@ "report": { "schema": 1, "app": "Tokenmeter", - "version": "0.9.15", + "version": "0.9.16", "host": "studio", "chip": "Apple M3 Ultra", "time": "2026-11-13T19:00:00Z", diff --git a/Linux/kde/mock/settings.json b/Linux/kde/mock/settings.json index a9e8e599..8210a229 100644 --- a/Linux/kde/mock/settings.json +++ b/Linux/kde/mock/settings.json @@ -15,7 +15,7 @@ "addresses": [ "192.168.1.20" ], - "version": "0.9.15", + "version": "0.9.16", "shareHistory": false, "footprint": { "cpuPercent": 0.4, diff --git a/Linux/kde/plasmoid/metadata.json b/Linux/kde/plasmoid/metadata.json index 947738b6..baf7f046 100644 --- a/Linux/kde/plasmoid/metadata.json +++ b/Linux/kde/plasmoid/metadata.json @@ -7,7 +7,7 @@ "Icon": "tokenmeter", "Category": "System Information", "License": "Apache-2.0", - "Version": "0.9.15", + "Version": "0.9.16", "Website": "https://github.com/tokenmeter1/Tokenmeter" }, "X-Plasma-API-Minimum-Version": "6.0", diff --git a/README.md b/README.md index b88d3eae..6fb921ae 100644 --- a/README.md +++ b/README.md @@ -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` (or by the `Tokenmeter--windows-x64.msi` installer that `Windows\build.ps1 -Msi` makes, which releases carry from 0.9.15), 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) +**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--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--android.apk` on the release page: copy it to the phone and open it ([Android/](Android/README.md)). diff --git a/Windows/package.ps1 b/Windows/package.ps1 index f6e24ae5..f4c16cb2 100644 --- a/Windows/package.ps1 +++ b/Windows/package.ps1 @@ -14,7 +14,7 @@ # dotnet tool install --global wix --version 5.0.2 # (the Util extension it also needs is added the first time this runs). # -# -Version 0.9.15 the version written into the MSI and its name (default: App\StatusJSON.swift's, which is the +# -Version 0.9.16 the version written into the MSI and its name (default: App\StatusJSON.swift's, which is the # version the service itself reports) # -Out where the MSI goes (default: dist) param([string]$Version, [string]$Out) @@ -35,7 +35,7 @@ if (-not $Version) { $Version = $line.Matches[0].Groups[1].Value } $Version = $Version.TrimStart("v") -if ($Version -notmatch '^\d+\.\d+\.\d+$') { Write-Host "$Version isn't a version such as 0.9.15."; exit 1 } +if ($Version -notmatch '^\d+\.\d+\.\d+$') { Write-Host "$Version isn't a version such as 0.9.16."; exit 1 } if (-not (Get-Command wix -ErrorAction SilentlyContinue)) { Write-Host "WiX Toolset isn't installed, or isn't in PATH. Install it once with:" diff --git a/build-library-app.sh b/build-library-app.sh index d2809eb8..3426d23e 100755 --- a/build-library-app.sh +++ b/build-library-app.sh @@ -18,7 +18,7 @@ for word in "$@"; do esac done app="$project_dir/Tokenmeter.app" -version=${APP_VERSION:-0.9.15} +version=${APP_VERSION:-0.9.16} build=${APP_BUILD:-1} # SwiftUI's @State is a compiler macro in the macOS 26 SDK. The Command Line Tools ship that SDK without diff --git a/docs/wiki/Windows.md b/docs/wiki/Windows.md index 9e3bb037..c688565d 100644 --- a/docs/wiki/Windows.md +++ b/docs/wiki/Windows.md @@ -6,7 +6,7 @@ Tokenmeter's **service** runs on Windows 10 and 11. There is no Tokenmeter windo ## Install it from a release -From 0.9.15 a release can carry `Tokenmeter--windows-x64.msi`. Open it, or run `msiexec /i Tokenmeter--windows-x64.msi`. It installs for your account only and asks for no administrator rights: the service, Swift's runtime libraries and Microsoft's C++ runtime go to `%LOCALAPPDATA%\Tokenmeter`, and it starts the service and makes it start when you log in, just as `Windows\install.ps1` does (below). Nothing else needs to be installed on the PC. +From 0.9.16 a release can carry `Tokenmeter--windows-x64.msi`. Open it, or run `msiexec /i Tokenmeter--windows-x64.msi`. It installs for your account only and asks for no administrator rights: the service, Swift's runtime libraries and Microsoft's C++ runtime go to `%LOCALAPPDATA%\Tokenmeter`, and it starts the service and makes it start when you log in, just as `Windows\install.ps1` does (below). Nothing else needs to be installed on the PC. - `msiexec /i Tokenmeter--windows-x64.msi LOCALONLY=1` keeps the service to the PC (as `-LocalOnly` does). Give it again with each new version, or the new one lets other machines read it again. - A newer MSI installs over the old one, and over a service that `install.ps1` installed. @@ -44,7 +44,7 @@ The PC that built the service has Swift's own libraries. To run it on another PC ## Make the MSI (for a release) -`Windows\build.ps1 -Msi` builds the service and packs it as `dist\Tokenmeter--windows-x64.msi` (`-arm64` on an Arm PC); `Windows\package.ps1` packs a service that is already built. The version is the one the service reports (`App\StatusJSON.swift`), or give another with `Windows\package.ps1 -Version 0.9.15`. It needs WiX Toolset 5, a .NET tool, installed once: +`Windows\build.ps1 -Msi` builds the service and packs it as `dist\Tokenmeter--windows-x64.msi` (`-arm64` on an Arm PC); `Windows\package.ps1` packs a service that is already built. The version is the one the service reports (`App\StatusJSON.swift`), or give another with `Windows\package.ps1 -Version 0.9.16`. It needs WiX Toolset 5, a .NET tool, installed once: ```powershell winget install Microsoft.DotNet.SDK.8 diff --git a/scripts/package-flatpak.sh b/scripts/package-flatpak.sh index 765cbc36..41d592df 100755 --- a/scripts/package-flatpak.sh +++ b/scripts/package-flatpak.sh @@ -7,7 +7,7 @@ # Needs flatpak and flatpak-builder; the KDE runtime and SDK are fetched from Flathub. set -eu project_dir=$(cd "$(dirname "$0")/.." && pwd) -version=${APP_VERSION:-0.9.15} +version=${APP_VERSION:-0.9.16} arch=$(uname -m) id=io.github.tokenmeter1.tokenmeter name="Tokenmeter-$version-linux-$arch" diff --git a/scripts/package-linux.sh b/scripts/package-linux.sh index 2b763281..1297f2fa 100755 --- a/scripts/package-linux.sh +++ b/scripts/package-linux.sh @@ -4,7 +4,7 @@ # and install.sh. Needs the Swift toolchain; run it on Linux. set -eu project_dir=$(cd "$(dirname "$0")/.." && pwd) -version=${APP_VERSION:-0.9.15} +version=${APP_VERSION:-0.9.16} arch=$(uname -m) name="Tokenmeter-$version-linux-$arch" diff --git a/scripts/package-service.sh b/scripts/package-service.sh index 49b04cf7..79231f6b 100755 --- a/scripts/package-service.sh +++ b/scripts/package-service.sh @@ -18,7 +18,7 @@ # On a Mac, SIGN_IDENTITY signs the program with a Developer ID; without it the program is ad-hoc signed. set -eu project_dir=$(cd "$(dirname "$0")/.." && pwd) -version=${APP_VERSION:-0.9.15} +version=${APP_VERSION:-0.9.16} case "$(uname -s)" in Darwin) os=macos ;; Linux) os=linux ;; diff --git a/scripts/package.sh b/scripts/package.sh index faa91b62..e2f6eead 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -16,7 +16,7 @@ set -euo pipefail project_dir=${0:A:h:h} app="$project_dir/Tokenmeter.app" dist="$project_dir/dist" -export APP_VERSION=${APP_VERSION:-0.9.15} +export APP_VERSION=${APP_VERSION:-0.9.16} identity=${SIGN_IDENTITY:-} profile=${NOTARY_PROFILE:-}