From 0e39616ce8cdd3b140b9653021145e8e95266ce6 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sat, 20 Dec 2025 23:12:00 -0500 Subject: [PATCH] Update samy.ps1 --- samy.ps1 | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/samy.ps1 b/samy.ps1 index da1e0e7..f759955 100644 --- a/samy.ps1 +++ b/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