forked from Fei-Away/Codex-Dream-Skin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-dream-skin.ps1
More file actions
93 lines (85 loc) · 4.42 KB
/
Copy pathinstall-dream-skin.ps1
File metadata and controls
93 lines (85 loc) · 4.42 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
[CmdletBinding()]
param(
[int]$Port = 9335,
[switch]$NoShortcuts
)
$ErrorActionPreference = 'Stop'
$PortExplicit = $PSBoundParameters.ContainsKey('Port')
$SkillRoot = Split-Path -Parent $PSScriptRoot
. (Join-Path $PSScriptRoot 'common-windows.ps1')
. (Join-Path $PSScriptRoot 'theme-windows.ps1')
$operationLock = Enter-DreamSkinOperationLock
try {
Assert-DreamSkinPort -Port $Port
$null = Get-DreamSkinNodeRuntime
$registeredInstalls = @(Get-DreamSkinRegisteredCodexInstalls)
if ($registeredInstalls.Count -eq 0) {
throw 'The official OpenAI.Codex Store package is not installed or its identity cannot be validated.'
}
foreach ($registeredCodex in $registeredInstalls) {
if ((Get-DreamSkinCodexProcesses -Codex $registeredCodex).Count -gt 0) {
throw 'Close Codex before installing Dream Skin so config.toml cannot change during the transaction.'
}
}
$StateRoot = Join-Path $env:LOCALAPPDATA 'CodexDreamSkin'
$themePaths = Get-DreamSkinThemePaths -StateRoot $StateRoot
Ensure-DreamSkinManagedDirectory -Path $themePaths.Root -Root $themePaths.Root
$StatePath = Join-Path $StateRoot 'state.json'
$existingState = Read-DreamSkinState -Path $StatePath
$savedPathCandidate = Get-DreamSkinCodexStatePathCandidate -State $existingState
$savedCodex = Resolve-DreamSkinCodexInstallFromState -State $existingState -RegisteredInstalls $registeredInstalls
if ($null -ne $savedPathCandidate -and $null -eq $savedCodex -and
(Get-DreamSkinCodexProcesses -Codex $savedPathCandidate).Count -gt 0) {
throw 'The saved Codex path is still running but no longer matches a registered Store package. Close it manually before installing.'
}
if (Test-DreamSkinTrayActive) {
throw 'Exit the Codex Dream Skin tray before reinstalling so every shortcut can move to the new runtime safely.'
}
$engine = Install-DreamSkinRuntimeEngine -SkillRoot $SkillRoot -StateRoot $StateRoot
$null = Initialize-DreamSkinThemeStore -SkillRoot $engine.Root -StateRoot $StateRoot
$ConfigPath = Join-Path $HOME '.codex\config.toml'
$BackupPath = Join-Path $StateRoot 'config.before-dream-skin.toml'
Install-DreamSkinBaseTheme -ConfigPath $ConfigPath -BackupPath $BackupPath
if (-not $NoShortcuts) {
$shell = New-Object -ComObject WScript.Shell
$desktop = [Environment]::GetFolderPath('Desktop')
$startMenu = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs'
$powershell = (Get-Command powershell.exe -ErrorAction Stop).Source
$startScript = $engine.Start
$restoreScript = $engine.Restore
$trayScript = $engine.Tray
$portArgument = if ($PortExplicit) { " -Port $Port" } else { '' }
foreach ($folder in @($desktop, $startMenu)) {
$shortcut = $shell.CreateShortcut((Join-Path $folder 'Codex Dream Skin.lnk'))
$shortcut.TargetPath = $powershell
$shortcut.Arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$startScript`"$portArgument -PromptRestart"
$shortcut.WorkingDirectory = $engine.Root
$shortcut.Description = 'Launch the official Codex app with Codex Dream Skin'
$shortcut.Save()
}
$restore = $shell.CreateShortcut((Join-Path $desktop 'Codex Dream Skin - Restore.lnk'))
$restore.TargetPath = $powershell
$restore.Arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$restoreScript`"$portArgument -RestoreBaseTheme -PromptRestart"
$restore.WorkingDirectory = $engine.Root
$restore.Description = 'Restore the official Codex appearance and close the CDP session'
$restore.Save()
foreach ($folder in @($desktop, $startMenu)) {
$tray = $shell.CreateShortcut((Join-Path $folder 'Codex Dream Skin - Tray.lnk'))
$tray.TargetPath = $powershell
$tray.Arguments = "-NoProfile -STA -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$trayScript`"$portArgument"
$tray.WorkingDirectory = $engine.Root
$tray.Description = 'Open Codex Dream Skin status and theme controls in the system tray'
$tray.Save()
}
Start-Process -FilePath $powershell -ArgumentList `
"-NoProfile -STA -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$trayScript`"$portArgument" `
-WindowStyle Hidden | Out-Null
}
if ($NoShortcuts) {
Write-Host "Codex Dream Skin base theme installed at $($engine.Root). Run $($engine.Start) to launch it."
} else {
Write-Host 'Codex Dream Skin installed. The launch shortcut asks before restarting an open Codex window.'
}
} finally {
Exit-DreamSkinOperationLock -Mutex $operationLock
}