1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-23 15:20:06 +00:00

fix(windows): initialize visual defaults safely

This commit is contained in:
Tw93
2026-03-23 20:07:22 +08:00
parent 1f0b470c7c
commit 4a41d56955
3 changed files with 63 additions and 13 deletions

View File

@@ -47,24 +47,36 @@ $script:DefaultIcons = @{
Trash = [char]0x2718 # ✘ (trash substitute)
}
function Initialize-MoleVisualDefaults {
if (-not ($script:Colors -is [hashtable])) {
$script:Colors = @{}
function Get-OrCreateScriptHashtable {
param(
[Parameter(Mandatory)]
[string]$Name
)
$existing = Get-Variable -Name $Name -Scope Script -ErrorAction SilentlyContinue
if ($existing -and $existing.Value -is [hashtable]) {
return $existing.Value
}
$table = @{}
Set-Variable -Name $Name -Scope Script -Value $table
return $table
}
function Initialize-MoleVisualDefaults {
$colors = Get-OrCreateScriptHashtable -Name "Colors"
foreach ($entry in $script:DefaultColors.GetEnumerator()) {
if (-not $script:Colors.ContainsKey($entry.Key)) {
$script:Colors[$entry.Key] = $entry.Value
if (-not $colors.ContainsKey($entry.Key)) {
$colors[$entry.Key] = $entry.Value
}
}
if (-not ($script:Icons -is [hashtable])) {
$script:Icons = @{}
}
$icons = Get-OrCreateScriptHashtable -Name "Icons"
foreach ($entry in $script:DefaultIcons.GetEnumerator()) {
if (-not $script:Icons.ContainsKey($entry.Key)) {
$script:Icons[$entry.Key] = $entry.Value
if (-not $icons.ContainsKey($entry.Key)) {
$icons[$entry.Key] = $entry.Value
}
}
}