33 Builds and launches the WinUI tray app for local development.
44
55. DESCRIPTION
6- Uses `winapp run` with the app package manifest so local launches match the
7- Windows App SDK activation path used during validation. Do not launch the
8- generated OpenClaw.Tray.WinUI.exe directly; direct EXE startup bypasses the
9- manifest/package identity path and can hide launch-time issues.
6+ Builds the tray app, then launches the unpackaged WinUI executable directly
7+ for the common local-development path.
8+
9+ Use -UseWinApp when you specifically want Microsoft WinAppCLI (`winapp run`)
10+ to launch with Package.appxmanifest for packaged/MSIX-adjacent validation.
11+
12+ Use -Isolated (or -DataDir) to run multiple worktrees side-by-side without
13+ sharing settings, logs, run markers, device identities, or mutex names.
1014
1115 By default this helper refuses to run outside `master` to avoid accidentally
1216 launching a stale or experimental worktree. Use -AllowNonMaster when you
2125. PARAMETER AllowNonMaster
2226 Allow launching from a branch other than master.
2327
28+ . PARAMETER Isolated
29+ Set OPENCLAW_TRAY_DATA_DIR to a stable temp directory unique to this worktree
30+ and branch so multiple local launches can run side-by-side.
31+
32+ . PARAMETER DataDir
33+ Set OPENCLAW_TRAY_DATA_DIR to an explicit directory for this launch.
34+
35+ . PARAMETER UpdateChannel
36+ Set OPENCLAW_UPDATE_CHANNEL for this launch. Use alpha for prerelease update
37+ testing after building a lower-version Release baseline.
38+
39+ . PARAMETER UseWinApp
40+ Launch through Microsoft WinAppCLI (`winapp run`) with Package.appxmanifest
41+ instead of directly starting the unpackaged executable.
42+
43+ . PARAMETER NoDebugOutput
44+ With -UseWinApp, launch without winapp --debug-output.
45+
46+ . PARAMETER Wait
47+ Wait for the launched process to exit. Direct launches return immediately by
48+ default after printing the PID.
49+
50+ . PARAMETER DryRun
51+ Print the launch command and environment without starting the app.
52+
2453. EXAMPLE
2554 .\run-app-local.ps1
2655
2756. EXAMPLE
2857 .\run-app-local.ps1 -NoBuild
2958
3059. EXAMPLE
31- .\run-app-local.ps1 -AllowNonMaster
60+ .\run-app-local.ps1 -Isolated
61+
62+ . EXAMPLE
63+ .\run-app-local.ps1 -Configuration Release -Isolated -UpdateChannel alpha -AllowNonMaster
64+
65+ . EXAMPLE
66+ .\run-app-local.ps1 -UseWinApp -NoBuild
3267#>
3368[CmdletBinding ()]
3469param (
@@ -37,15 +72,61 @@ param(
3772 [ValidateSet (" Debug" , " Release" )]
3873 [string ]$Configuration = " Debug" ,
3974
40- [switch ]$AllowNonMaster
75+ [switch ]$AllowNonMaster ,
76+
77+ [switch ]$Isolated ,
78+
79+ [string ]$DataDir ,
80+
81+ [ValidateSet (" stable" , " alpha" , " prerelease" )]
82+ [string ]$UpdateChannel ,
83+
84+ [switch ]$UseWinApp ,
85+
86+ [switch ]$NoDebugOutput ,
87+
88+ [switch ]$Wait ,
89+
90+ [switch ]$DryRun
4191)
4292
4393$ErrorActionPreference = " Stop"
4494
4595$repoRoot = Split-Path - Parent $MyInvocation.MyCommand.Path
4696Set-Location $repoRoot
4797
48- $branch = (git rev- parse -- abbrev- ref HEAD).Trim()
98+ function Resolve-FullPath {
99+ param ([Parameter (Mandatory = $true )][string ]$Path )
100+
101+ $expanded = [Environment ]::ExpandEnvironmentVariables($Path )
102+ if ([System.IO.Path ]::IsPathRooted($expanded )) {
103+ return [System.IO.Path ]::GetFullPath($expanded )
104+ }
105+
106+ return [System.IO.Path ]::GetFullPath((Join-Path $repoRoot $expanded ))
107+ }
108+
109+ function Get-SafePathSegment {
110+ param ([Parameter (Mandatory = $true )][string ]$Value )
111+
112+ $safe = [regex ]::Replace($Value , " [^A-Za-z0-9._-]+" , " -" ).Trim(" -" )
113+ if ($safe ) { return $safe }
114+ return " default"
115+ }
116+
117+ function Get-ShortHash {
118+ param ([Parameter (Mandatory = $true )][string ]$Value )
119+
120+ $sha = [System.Security.Cryptography.SHA256 ]::Create()
121+ try {
122+ $bytes = $sha.ComputeHash ([System.Text.Encoding ]::UTF8.GetBytes($Value.ToLowerInvariant ()))
123+ return -join ($bytes [0 .. 3 ] | ForEach-Object { $_.ToString (" x2" ) })
124+ } finally {
125+ $sha.Dispose ()
126+ }
127+ }
128+
129+ $branch = (git - C $repoRoot rev- parse -- abbrev- ref HEAD).Trim()
49130if ($branch -ne " master" -and -not $AllowNonMaster ) {
50131 throw " Refusing to run: current branch is '$branch ', expected 'master'. Use -AllowNonMaster to preview this branch intentionally."
51132}
@@ -57,11 +138,6 @@ if (-not $NoBuild) {
57138 }
58139}
59140
60- $winapp = Get-Command winapp - ErrorAction SilentlyContinue
61- if (-not $winapp ) {
62- throw " winapp CLI was not found. Install Microsoft WinAppCLI or run this from an environment where winapp is on PATH."
63- }
64-
65141$projectPath = Join-Path $repoRoot " src\OpenClaw.Tray.WinUI\OpenClaw.Tray.WinUI.csproj"
66142$manifestPath = Join-Path $repoRoot " src\OpenClaw.Tray.WinUI\Package.appxmanifest"
67143[xml ]$projectXml = Get-Content - LiteralPath $projectPath - Raw - Encoding UTF8
@@ -73,14 +149,95 @@ if (-not $targetFramework) {
73149$architecture = [System.Runtime.InteropServices.RuntimeInformation ]::OSArchitecture
74150$runtimeIdentifier = if ($architecture -eq [System.Runtime.InteropServices.Architecture ]::Arm64) { " win-arm64" } else { " win-x64" }
75151$outputDir = Join-Path $repoRoot " src\OpenClaw.Tray.WinUI\bin\$Configuration \$targetFramework \$runtimeIdentifier "
152+ $exePath = Join-Path $outputDir " OpenClaw.Tray.WinUI.exe"
76153
77154if (-not (Test-Path $outputDir )) {
78155 throw " Build output folder not found: $outputDir . Run without -NoBuild first."
79156}
80- if (-not (Test-Path $manifestPath )) {
157+ if (-not (Test-Path $exePath )) {
158+ throw " Tray executable not found: $exePath . Run without -NoBuild first."
159+ }
160+
161+ $winapp = $null
162+ if ($UseWinApp ) {
163+ $winapp = Get-Command winapp - ErrorAction SilentlyContinue
164+ if (-not $winapp ) {
165+ throw " winapp CLI was not found. Install Microsoft WinAppCLI (winget install Microsoft.WinAppCLI) or run /winui-setup."
166+ }
167+ }
168+
169+ if ($UseWinApp -and -not (Test-Path $manifestPath )) {
81170 throw " Manifest not found: $manifestPath ."
82171}
83172
84- Write-Host " Launching OpenClaw Tray with winapp ($runtimeIdentifier , $Configuration )..."
85- & $winapp.Source run $outputDir -- manifest $manifestPath -- debug-output
86- exit $LASTEXITCODE
173+ $previousDataDir = $env: OPENCLAW_TRAY_DATA_DIR
174+ $previousUpdateChannel = $env: OPENCLAW_UPDATE_CHANNEL
175+ $exitCode = 0
176+
177+ try {
178+ $effectiveDataDir = $null
179+ if ($DataDir ) {
180+ $effectiveDataDir = Resolve-FullPath $DataDir
181+ } elseif ($Isolated ) {
182+ $repoName = Get-SafePathSegment (Split-Path - Leaf $repoRoot )
183+ $safeBranch = Get-SafePathSegment $branch
184+ $repoHash = Get-ShortHash $repoRoot
185+ $effectiveDataDir = Join-Path $env: TEMP " OpenClawTray\$repoName -$safeBranch -$repoHash "
186+ }
187+
188+ if ($effectiveDataDir ) {
189+ New-Item - ItemType Directory - Path $effectiveDataDir - Force | Out-Null
190+ $env: OPENCLAW_TRAY_DATA_DIR = $effectiveDataDir
191+ }
192+
193+ if ($UpdateChannel ) {
194+ $env: OPENCLAW_UPDATE_CHANNEL = $UpdateChannel
195+ }
196+
197+ if ($UseWinApp ) {
198+ $winappArgs = @ (" run" , $outputDir , " --manifest" , $manifestPath , " --executable" , " OpenClaw.Tray.WinUI.exe" )
199+ if (-not $NoDebugOutput ) {
200+ $winappArgs += " --debug-output"
201+ }
202+ }
203+
204+ Write-Host " Launching OpenClaw Tray" - ForegroundColor Cyan
205+ Write-Host " Branch: $branch "
206+ Write-Host " Configuration: $Configuration "
207+ Write-Host " Runtime: $runtimeIdentifier "
208+ Write-Host " Output: $outputDir "
209+ Write-Host " Mode: $ ( if ($UseWinApp ) { ' WinAppCLI manifest activation' } else { ' Direct unpackaged executable' }) "
210+ if ($env: OPENCLAW_TRAY_DATA_DIR ) {
211+ Write-Host " Data dir: $env: OPENCLAW_TRAY_DATA_DIR "
212+ }
213+ if ($env: OPENCLAW_UPDATE_CHANNEL ) {
214+ Write-Host " Update channel: $env: OPENCLAW_UPDATE_CHANNEL "
215+ }
216+ if ($UseWinApp ) {
217+ Write-Host " Launcher: $ ( $winapp.Source ) "
218+ Write-Host " Command: winapp $ ( $winappArgs -join ' ' ) "
219+ } else {
220+ Write-Host " Launcher: $exePath "
221+ }
222+
223+ if ($DryRun ) {
224+ return
225+ }
226+
227+ if ($UseWinApp ) {
228+ & $winapp.Source @winappArgs
229+ $exitCode = $LASTEXITCODE
230+ } elseif ($Wait ) {
231+ $process = Start-Process - FilePath $exePath - WorkingDirectory $outputDir - Wait - PassThru
232+ $exitCode = $process.ExitCode
233+ } else {
234+ $process = Start-Process - FilePath $exePath - WorkingDirectory $outputDir - PassThru
235+ Write-Host " Started OpenClaw Tray (PID: $ ( $process.Id ) )" - ForegroundColor Green
236+ $exitCode = 0
237+ }
238+ } finally {
239+ $env: OPENCLAW_TRAY_DATA_DIR = $previousDataDir
240+ $env: OPENCLAW_UPDATE_CHANNEL = $previousUpdateChannel
241+ }
242+
243+ exit $exitCode
0 commit comments