Repository navigation
Expand file tree
/
Copy pathrun-app-local.ps1
More file actions
321 lines (255 loc) · 11.4 KB
/
Copy pathrun-app-local.ps1
File metadata and controls
321 lines (255 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<#
.SYNOPSIS
Builds and launches the WinUI tray app for local development.
.DESCRIPTION
Builds only the WinUI tray project graph with one incremental dotnet build,
then launches the unpackaged WinUI executable directly. It does not run
build.ps1's prerequisite checks, documentation validation, or CLI builds;
run .\build.ps1 for the full closeout gate.
Use -UseWinApp when you specifically want Microsoft WinAppCLI (`winapp run`)
to launch with Package.appxmanifest for packaged/MSIX-adjacent validation.
Use -Isolated (or -DataDir) to avoid sharing settings, logs, run markers,
and device identities. Use -Dev to opt into the side-by-side dev app
identity with separate mutex, protocol, gateway distro, and gateway port.
Native development uses an isolated npm-latest MSIX Gateway by default.
-GatewayChannel Packaged selects a published packaging release instead. Both use the same
Companion source. An explicit OPENCLAW_NATIVE_GATEWAY_DEV_PATCH is reused
without rebuilding. Use -UseStoreGateway for the installed Store runtime.
.PARAMETER NoBuild
Skip the build step and launch the existing Debug output.
.PARAMETER Configuration
Build/output configuration to use. Defaults to Debug.
.PARAMETER RuntimeIdentifier
Runtime to build and launch. When omitted, the current PowerShell process
architecture selects the RID.
.PARAMETER Dev
Build and launch with the side-by-side dev app identity. Defaults off so
release identity remains the default local-launch behavior.
.PARAMETER Isolated
Set OPENCLAW_TRAY_DATA_DIR to a stable temp directory unique to this worktree
and branch so multiple local launches can run side-by-side.
.PARAMETER DataDir
Set OPENCLAW_TRAY_DATA_DIR to an explicit directory for this launch.
.PARAMETER UpdateChannel
Set OPENCLAW_UPDATE_CHANNEL for this launch. Use alpha for prerelease update
testing after building a lower-version Release baseline.
.PARAMETER UseWinApp
Launch through Microsoft WinAppCLI (`winapp run`) with Package.appxmanifest
instead of directly starting the unpackaged executable.
.PARAMETER NoDebugOutput
With -UseWinApp, launch without winapp --debug-output.
.PARAMETER Wait
Wait for the launched process to exit. Direct launches return immediately by
default after printing the PID.
.PARAMETER DryRun
Print the launch command and environment without starting the app.
.PARAMETER GatewayChannel
Latest (default) builds/registers npm latest as npm-latest.
Packaged uses the published MSIX application payload as the packaged patch.
.PARAMETER PackagingRelease
Exact packaging release tag. Requires -GatewayChannel Packaged.
Omit to use the latest published GitHub packaging release.
.PARAMETER UseStoreGateway
Skip development Gateway packaging and use the installed Store Gateway.
.EXAMPLE
.\run-app-local.ps1
.EXAMPLE
.\run-app-local.ps1 -NoBuild
.EXAMPLE
.\run-app-local.ps1 -Isolated
.EXAMPLE
.\run-app-local.ps1 -Dev -Isolated
.EXAMPLE
.\run-app-local.ps1 -Configuration Release -Isolated -UpdateChannel alpha
.EXAMPLE
.\run-app-local.ps1 -UseWinApp -NoBuild
#>
[CmdletBinding()]
param(
[switch]$NoBuild,
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug",
[ValidateSet("win-x64", "win-arm64")]
[string]$RuntimeIdentifier,
[switch]$Dev,
[switch]$Isolated,
[string]$DataDir,
[ValidateSet("stable", "alpha", "prerelease")]
[string]$UpdateChannel,
[switch]$UseWinApp,
[switch]$NoDebugOutput,
[switch]$Wait,
[switch]$DryRun,
[ValidateSet('Latest', 'Packaged')]
[string]$GatewayChannel,
[ValidatePattern('\Av\d{4}\.\d{1,2}\.\d+(?:-\d+)?-msix\.\d+\z')]
[string]$PackagingRelease,
[switch]$UseStoreGateway
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $repoRoot
function Resolve-FullPath {
param([Parameter(Mandatory = $true)][string]$Path)
$expanded = [Environment]::ExpandEnvironmentVariables($Path)
if ([System.IO.Path]::IsPathRooted($expanded)) {
return [System.IO.Path]::GetFullPath($expanded)
}
return [System.IO.Path]::GetFullPath((Join-Path $repoRoot $expanded))
}
function Get-SafePathSegment {
param([Parameter(Mandatory = $true)][string]$Value)
$safe = [regex]::Replace($Value, "[^A-Za-z0-9._-]+", "-").Trim("-")
if ($safe) { return $safe }
return "default"
}
function Get-ShortHash {
param([Parameter(Mandatory = $true)][string]$Value)
$sha = [System.Security.Cryptography.SHA256]::Create()
try {
$bytes = $sha.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($Value.ToLowerInvariant()))
return -join ($bytes[0..3] | ForEach-Object { $_.ToString("x2") })
} finally {
$sha.Dispose()
}
}
$branch = (git -C $repoRoot rev-parse --abbrev-ref HEAD).Trim()
Import-Module (Join-Path $repoRoot 'scripts\GatewayNpmRelease.psm1') -Force
$gatewayArguments = @{}
if ($PSBoundParameters.ContainsKey('GatewayChannel')) { $gatewayArguments.GatewayChannel = $GatewayChannel }
if ($PSBoundParameters.ContainsKey('PackagingRelease')) { $gatewayArguments.PackagingRelease = $PackagingRelease }
$gatewayInput = Resolve-GatewayLaunchInput -UseStoreGateway:$UseStoreGateway @gatewayArguments `
-ExistingPatch $env:OPENCLAW_NATIVE_GATEWAY_DEV_PATCH
$buildGateway = $gatewayInput.Build
$gatewayPatch = $gatewayInput.Patch
$projectPath = Join-Path $repoRoot "src\OpenClaw.Tray.WinUI\OpenClaw.Tray.WinUI.csproj"
$manifestPath = Join-Path $repoRoot "src\OpenClaw.Tray.WinUI\Package.appxmanifest"
# Without an explicit RID, pick the RID from the current process architecture, matching build.ps1.
if ([string]::IsNullOrWhiteSpace($RuntimeIdentifier)) {
$architecture = $env:PROCESSOR_ARCHITECTURE
$RuntimeIdentifier = switch ($architecture) {
"ARM64" { "win-arm64" }
default { "win-x64" }
}
}
Write-Host "Selected runtime: $RuntimeIdentifier"
if (-not $NoBuild) {
& (Join-Path $repoRoot "scripts\Initialize-ReactorPackages.ps1")
$dotnetArgs = @("build", $projectPath, "-c", $Configuration, "-r", $RuntimeIdentifier)
if ($Dev) {
$dotnetArgs += "-p:DevBuild=true"
}
Write-Host "Building OpenClaw Tray: dotnet $($dotnetArgs -join ' ')" -ForegroundColor Cyan
& dotnet @dotnetArgs
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed. Close any running OpenClaw Tray that locks the output, or run .\build.ps1 to check prerequisites and trust the repo for GitVersion (.\scripts\setup-dev.ps1 -CheckOnly for setup diagnostics)." -ForegroundColor Yellow
exit $LASTEXITCODE
}
}
[xml]$projectXml = Get-Content -LiteralPath $projectPath -Raw -Encoding UTF8
$targetFramework = ($projectXml.Project.PropertyGroup | Where-Object { $_.TargetFramework } | Select-Object -First 1).TargetFramework
if (-not $targetFramework) {
throw "Unable to determine TargetFramework from $projectPath."
}
$outputDir = Join-Path $repoRoot "src\OpenClaw.Tray.WinUI\bin\$Configuration\$targetFramework\$RuntimeIdentifier"
$exePath = Join-Path $outputDir "OpenClaw.Tray.WinUI.exe"
$identityMarkerPath = Join-Path $outputDir "app-identity.txt"
if (-not (Test-Path $outputDir)) {
throw "Build output folder not found: $outputDir. Run without -NoBuild first."
}
if (-not (Test-Path $exePath)) {
throw "Tray executable not found: $exePath. Run without -NoBuild first."
}
if (-not (Test-Path $identityMarkerPath)) {
throw "App identity marker not found: $identityMarkerPath. Run without -NoBuild first."
}
$expectedIdentity = if ($Dev) { "dev" } else { "release" }
$actualIdentity = (Get-Content -LiteralPath $identityMarkerPath -Raw -Encoding UTF8).Trim()
if ($actualIdentity -ne $expectedIdentity) {
throw "Build output identity '$actualIdentity' does not match requested '$expectedIdentity'. Run without -NoBuild or choose the matching -Dev option."
}
$winapp = $null
if ($UseWinApp) {
$winapp = Get-Command winapp -ErrorAction SilentlyContinue
if (-not $winapp) {
throw "winapp CLI was not found. Install Microsoft WinAppCLI (winget install Microsoft.WinAppCLI) or run /winui-setup."
}
}
if ($UseWinApp -and -not (Test-Path $manifestPath)) {
throw "Manifest not found: $manifestPath."
}
$previousDataDir = $env:OPENCLAW_TRAY_DATA_DIR
$previousUpdateChannel = $env:OPENCLAW_UPDATE_CHANNEL
$previousGatewayPatch = $env:OPENCLAW_NATIVE_GATEWAY_DEV_PATCH
$exitCode = 0
try {
$env:OPENCLAW_NATIVE_GATEWAY_DEV_PATCH = $gatewayPatch
$effectiveDataDir = $null
if ($DataDir) {
$effectiveDataDir = Resolve-FullPath $DataDir
} elseif ($Isolated -or $gatewayPatch) {
$repoName = Get-SafePathSegment (Split-Path -Leaf $repoRoot)
$safeBranch = Get-SafePathSegment $branch
$repoHash = Get-ShortHash $repoRoot
$effectiveDataDir = Join-Path $env:TEMP "OpenClawTray\$repoName-$safeBranch-$repoHash"
if ($gatewayPatch) {
$effectiveDataDir += "-" + (Get-SafePathSegment $gatewayPatch)
}
}
if ($effectiveDataDir) {
New-Item -ItemType Directory -Path $effectiveDataDir -Force | Out-Null
$env:OPENCLAW_TRAY_DATA_DIR = $effectiveDataDir
}
if ($UpdateChannel) {
$env:OPENCLAW_UPDATE_CHANNEL = $UpdateChannel
}
if ($UseWinApp) {
$winappArgs = @("run", $outputDir, "--manifest", $manifestPath, "--executable", "OpenClaw.Tray.WinUI.exe")
if (-not $NoDebugOutput) {
$winappArgs += "--debug-output"
}
}
Write-Host "Launching OpenClaw Tray" -ForegroundColor Cyan
Write-Host " Branch: $branch"
Write-Host " Configuration: $Configuration"
Write-Host " Identity: $(if ($actualIdentity -eq 'dev') { 'Dev (opt-in)' } else { 'Release (default)' })"
Write-Host " Runtime: $RuntimeIdentifier"
Write-Host " Gateway: $(if ($gatewayPatch) { $gatewayPatch } else { 'Microsoft Store' })"
Write-Host " Output: $outputDir"
Write-Host " Mode: $(if ($UseWinApp) { 'WinAppCLI manifest activation' } else { 'Direct unpackaged executable' })"
if ($env:OPENCLAW_TRAY_DATA_DIR) {
Write-Host " Data dir: $env:OPENCLAW_TRAY_DATA_DIR"
}
if ($env:OPENCLAW_UPDATE_CHANNEL) {
Write-Host " Update channel: $env:OPENCLAW_UPDATE_CHANNEL"
}
if ($UseWinApp) {
Write-Host " Launcher: $($winapp.Source)"
Write-Host " Command: winapp $($winappArgs -join ' ')"
} else {
Write-Host " Launcher: $exePath"
}
if ($DryRun) {
return
}
if ($buildGateway) {
& "$repoRoot\scripts\Build-NativeGatewayFromSource.ps1" @gatewayArguments -Patch $gatewayPatch
}
if ($UseWinApp) {
& $winapp.Source @winappArgs
$exitCode = $LASTEXITCODE
} elseif ($Wait) {
$process = Start-Process -FilePath $exePath -WorkingDirectory $outputDir -Wait -PassThru
$exitCode = $process.ExitCode
} else {
$process = Start-Process -FilePath $exePath -WorkingDirectory $outputDir -PassThru
Write-Host "Started OpenClaw Tray (PID: $($process.Id))" -ForegroundColor Green
Write-Host "Hint: Look for the 🦞 OpenClaw tray icon in the system tray (bottom-right). It may be hidden under the ^ button." -ForegroundColor Cyan
$exitCode = 0
}
} finally {
$env:OPENCLAW_TRAY_DATA_DIR = $previousDataDir
$env:OPENCLAW_UPDATE_CHANNEL = $previousUpdateChannel
$env:OPENCLAW_NATIVE_GATEWAY_DEV_PATCH = $previousGatewayPatch
}
exit $exitCode