mirror of
https://github.com/tw93/Mole.git
synced 2026-03-24 19:15:07 +00:00
fix(windows): harden PowerShell startup fallbacks
This commit is contained in:
@@ -32,22 +32,24 @@ function Get-MoleDefaultColors {
|
|||||||
# Icon Definitions
|
# Icon Definitions
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
function Get-MoleDefaultIcons {
|
function Get-MoleDefaultIcons {
|
||||||
|
# Keep this block ASCII-only so Windows PowerShell 5.1 does not
|
||||||
|
# mis-parse BOM-less source files and collapse comment lines.
|
||||||
return @{
|
return @{
|
||||||
Confirm = [char]0x25CE # ◎
|
Confirm = [char]0x25CE # circle confirm marker
|
||||||
Admin = [char]0x2699 # ⚙
|
Admin = [char]0x2699 # admin/settings marker
|
||||||
Success = [char]0x2713 # ✓
|
Success = [char]0x2713 # success check
|
||||||
Error = [char]0x263B # ☻
|
Error = [char]0x263B # error marker
|
||||||
Warning = [char]0x25CF # ●
|
Warning = [char]0x25CF # warning dot
|
||||||
Empty = [char]0x25CB # ○
|
Empty = [char]0x25CB # empty circle
|
||||||
Solid = [char]0x25CF # ●
|
Solid = [char]0x25CF # solid dot
|
||||||
List = [char]0x2022 # •
|
List = [char]0x2022 # list bullet
|
||||||
Arrow = [char]0x27A4 # ➤
|
Arrow = [char]0x27A4 # navigation arrow
|
||||||
DryRun = [char]0x2192 # →
|
DryRun = [char]0x2192 # dry-run arrow
|
||||||
NavUp = [char]0x2191 # ↑
|
NavUp = [char]0x2191 # up arrow
|
||||||
NavDown = [char]0x2193 # ↓
|
NavDown = [char]0x2193 # down arrow
|
||||||
Folder = [char]0x25A0 # ■ (folder substitute)
|
Folder = [char]0x25A0 # folder substitute
|
||||||
File = [char]0x25A1 # □ (file substitute)
|
File = [char]0x25A1 # file substitute
|
||||||
Trash = [char]0x2718 # ✘ (trash substitute)
|
Trash = [char]0x2718 # trash substitute
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,12 +231,25 @@ function Get-WindowsVersion {
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Get Windows version information
|
Get Windows version information
|
||||||
#>
|
#>
|
||||||
$os = Get-WmiObject Win32_OperatingSystem
|
try {
|
||||||
return @{
|
$os = Get-WmiObject Win32_OperatingSystem -ErrorAction Stop
|
||||||
Name = $os.Caption
|
return @{
|
||||||
Version = $os.Version
|
Name = $os.Caption
|
||||||
Build = $os.BuildNumber
|
Version = $os.Version
|
||||||
Arch = $os.OSArchitecture
|
Build = $os.BuildNumber
|
||||||
|
Arch = $os.OSArchitecture
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$currentVersion = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -ErrorAction SilentlyContinue
|
||||||
|
$fallbackVersion = [System.Environment]::OSVersion.Version
|
||||||
|
|
||||||
|
return @{
|
||||||
|
Name = if ($currentVersion.ProductName) { $currentVersion.ProductName } else { "Windows" }
|
||||||
|
Version = if ($currentVersion.DisplayVersion) { $currentVersion.DisplayVersion } elseif ($currentVersion.CurrentVersion) { $currentVersion.CurrentVersion } else { $fallbackVersion.ToString() }
|
||||||
|
Build = if ($currentVersion.CurrentBuildNumber) { $currentVersion.CurrentBuildNumber } else { $fallbackVersion.Build.ToString() }
|
||||||
|
Arch = if ($env:PROCESSOR_ARCHITECTURE) { $env:PROCESSOR_ARCHITECTURE } else { "Unknown" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,18 @@ Describe "Base Module" {
|
|||||||
$script:Icons.Admin | Should -Not -BeNullOrEmpty
|
$script:Icons.Admin | Should -Not -BeNullOrEmpty
|
||||||
$script:Icons.Trash | Should -Not -BeNullOrEmpty
|
$script:Icons.Trash | Should -Not -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Should expose the full icon table in Windows PowerShell" {
|
||||||
|
$basePath = (Join-Path $script:LibDir "core\base.ps1").Replace("'", "''")
|
||||||
|
$psCommand = "& { . '$basePath'; `$icons = Get-MoleDefaultIcons; [pscustomobject]@{ Count = `$icons.Count; HasSolid = `$icons.ContainsKey('Solid'); HasAdmin = `$icons.ContainsKey('Admin'); HasSuccess = `$icons.ContainsKey('Success') } | ConvertTo-Json -Compress }"
|
||||||
|
$result = & powershell -NoProfile -ExecutionPolicy Bypass -Command $psCommand
|
||||||
|
$iconInfo = $result | ConvertFrom-Json
|
||||||
|
|
||||||
|
$iconInfo.Count | Should -Be 15
|
||||||
|
$iconInfo.HasSolid | Should -Be $true
|
||||||
|
$iconInfo.HasAdmin | Should -Be $true
|
||||||
|
$iconInfo.HasSuccess | Should -Be $true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "Visual Defaults Initialization" {
|
Context "Visual Defaults Initialization" {
|
||||||
|
|||||||
Reference in New Issue
Block a user