Update samy.ps1
This commit is contained in:
54
samy.ps1
54
samy.ps1
@@ -674,7 +674,6 @@ function Get-RemoteText {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-SamyTasks {
|
function Get-SamyTasks {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
@@ -686,55 +685,49 @@ function Get-SamyTasks {
|
|||||||
$json = Get-RemoteText -Url $Url
|
$json = Get-RemoteText -Url $Url
|
||||||
if ([string]::IsNullOrWhiteSpace($json)) { throw "Tasks JSON was empty." }
|
if ([string]::IsNullOrWhiteSpace($json)) { throw "Tasks JSON was empty." }
|
||||||
|
|
||||||
$tasks = @($json | ConvertFrom-Json -ErrorAction Stop)
|
$parsed = $json | ConvertFrom-Json -ErrorAction Stop
|
||||||
|
$tasks = @($parsed)
|
||||||
|
|
||||||
if ($tasks.Count -eq 0) { throw "Tasks JSON parsed but contained no tasks." }
|
if ($tasks.Count -eq 0) { throw "Tasks JSON parsed but contained no tasks." }
|
||||||
|
|
||||||
foreach ($t in $tasks) {
|
foreach ($task in $tasks) {
|
||||||
|
|
||||||
|
# --- Normalize Label to a safe scalar string (never join arrays) ---
|
||||||
|
$labelRaw = $task.Label
|
||||||
|
if ($labelRaw -is [System.Collections.IEnumerable] -and -not ($labelRaw -is [string])) {
|
||||||
|
$labelRaw = @($labelRaw)[0]
|
||||||
|
}
|
||||||
|
$label = [string]$labelRaw
|
||||||
|
$task.Label = $label
|
||||||
|
|
||||||
|
# --- Read Tooltip if present ---
|
||||||
$tooltipRaw = $null
|
$tooltipRaw = $null
|
||||||
if ($t.PSObject.Properties.Name -contains 'Tooltip') {
|
if ($task.PSObject.Properties.Name -contains 'Tooltip') {
|
||||||
$tooltipRaw = $t.Tooltip
|
$tooltipRaw = $task.Tooltip
|
||||||
}
|
}
|
||||||
|
|
||||||
# Normalize tooltip to a single string
|
# --- Normalize Tooltip to a safe scalar string (never join arrays) ---
|
||||||
$tooltip = if ($tooltipRaw -is [string]) {
|
$tooltip = if ($tooltipRaw -is [string]) {
|
||||||
$tooltipRaw
|
$tooltipRaw
|
||||||
}
|
}
|
||||||
elseif ($tooltipRaw -is [System.Collections.IEnumerable] -and -not ($tooltipRaw -is [string])) {
|
elseif ($tooltipRaw -is [System.Collections.IEnumerable] -and -not ($tooltipRaw -is [string])) {
|
||||||
$arr = @(
|
[string](@($tooltipRaw)[0])
|
||||||
$tooltipRaw |
|
|
||||||
ForEach-Object { [string]$_ } |
|
|
||||||
Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
|
|
||||||
)
|
|
||||||
|
|
||||||
if ($arr.Count -eq 1) {
|
|
||||||
$arr[0] # single tooltip item
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[string]$t.Label # array or multiple items => treat as bad data, fallback to label
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
[string]$tooltipRaw
|
[string]$tooltipRaw
|
||||||
}
|
}
|
||||||
|
|
||||||
# DEBUG: inspect label type
|
# --- Fallback to *this task's* label only ---
|
||||||
$lbl = $t.Label
|
|
||||||
if ($lbl -is [System.Collections.IEnumerable] -and -not ($lbl -is [string])) {
|
|
||||||
Write-LogHybrid "LABEL IS ARRAY?! Id=$($t.Id) Type=$($lbl.GetType().FullName) Count=$(@($lbl).Count)" Warning UI -LogToEvent
|
|
||||||
}
|
|
||||||
|
|
||||||
# Fallback: tooltip defaults to label
|
|
||||||
if ([string]::IsNullOrWhiteSpace($tooltip)) {
|
if ([string]::IsNullOrWhiteSpace($tooltip)) {
|
||||||
$tooltip = [string]$t.Label
|
$tooltip = $label
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ensure property exists and is updated
|
# --- Ensure Tooltip property exists and is updated ---
|
||||||
if ($t.PSObject.Properties.Name -contains 'Tooltip') {
|
if ($task.PSObject.Properties.Name -contains 'Tooltip') {
|
||||||
$t.Tooltip = $tooltip
|
$task.Tooltip = $tooltip
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$t | Add-Member -NotePropertyName Tooltip -NotePropertyValue $tooltip -Force
|
$task | Add-Member -NotePropertyName Tooltip -NotePropertyValue $tooltip -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,6 +742,7 @@ function Get-SamyTasks {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion Remote Assets + Task Loading
|
#endregion Remote Assets + Task Loading
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user