Update samy.ps1
This commit is contained in:
54
samy.ps1
54
samy.ps1
@@ -674,7 +674,6 @@ function Get-RemoteText {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
function Get-SamyTasks {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
@@ -686,55 +685,49 @@ function Get-SamyTasks {
|
||||
$json = Get-RemoteText -Url $Url
|
||||
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." }
|
||||
|
||||
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
|
||||
if ($t.PSObject.Properties.Name -contains 'Tooltip') {
|
||||
$tooltipRaw = $t.Tooltip
|
||||
if ($task.PSObject.Properties.Name -contains '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]) {
|
||||
$tooltipRaw
|
||||
}
|
||||
elseif ($tooltipRaw -is [System.Collections.IEnumerable] -and -not ($tooltipRaw -is [string])) {
|
||||
$arr = @(
|
||||
$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
|
||||
}
|
||||
[string](@($tooltipRaw)[0])
|
||||
}
|
||||
else {
|
||||
[string]$tooltipRaw
|
||||
}
|
||||
|
||||
# DEBUG: inspect label type
|
||||
$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
|
||||
# --- Fallback to *this task's* label only ---
|
||||
if ([string]::IsNullOrWhiteSpace($tooltip)) {
|
||||
$tooltip = [string]$t.Label
|
||||
$tooltip = $label
|
||||
}
|
||||
|
||||
# Ensure property exists and is updated
|
||||
if ($t.PSObject.Properties.Name -contains 'Tooltip') {
|
||||
$t.Tooltip = $tooltip
|
||||
# --- Ensure Tooltip property exists and is updated ---
|
||||
if ($task.PSObject.Properties.Name -contains 'Tooltip') {
|
||||
$task.Tooltip = $tooltip
|
||||
}
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user