58 lines
1.7 KiB
PowerShell
58 lines
1.7 KiB
PowerShell
function Get-SamyTasks {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Url
|
|
)
|
|
|
|
try {
|
|
$json = Get-RemoteText -Url $Url
|
|
if ([string]::IsNullOrWhiteSpace($json)) { throw "Tasks JSON was empty." }
|
|
|
|
$parsed = $json | ConvertFrom-Json -ErrorAction Stop
|
|
$tasks = @($parsed)
|
|
|
|
if ($tasks.Count -eq 0) { throw "Tasks JSON parsed but contained no tasks." }
|
|
|
|
foreach ($task in $tasks) {
|
|
|
|
$labelRaw = $task.Label
|
|
if ($labelRaw -is [System.Collections.IEnumerable] -and -not ($labelRaw -is [string])) {
|
|
$labelRaw = @($labelRaw)[0]
|
|
}
|
|
$label = [string]$labelRaw
|
|
$task.Label = $label
|
|
|
|
$tooltipRaw = $null
|
|
if ($task.PSObject.Properties.Name -contains 'Tooltip') {
|
|
$tooltipRaw = $task.Tooltip
|
|
}
|
|
|
|
$tooltip = if ($tooltipRaw -is [string]) {
|
|
$tooltipRaw
|
|
}
|
|
elseif ($tooltipRaw -is [System.Collections.IEnumerable] -and -not ($tooltipRaw -is [string])) {
|
|
[string](@($tooltipRaw)[0])
|
|
}
|
|
else {
|
|
[string]$tooltipRaw
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($tooltip)) { $tooltip = $label }
|
|
|
|
if ($task.PSObject.Properties.Name -contains 'Tooltip') {
|
|
$task.Tooltip = $tooltip
|
|
}
|
|
else {
|
|
$task | Add-Member -NotePropertyName Tooltip -NotePropertyValue $tooltip -Force
|
|
}
|
|
}
|
|
|
|
return $tasks
|
|
}
|
|
catch {
|
|
Write-LogHybrid "Failed to load tasks from ${Url}: $($_.Exception.Message)" Error UI -LogToEvent
|
|
return $null
|
|
}
|
|
}
|