Enhance user interaction with new dialog features and improve default browser handling

This commit is contained in:
Arne Moerman
2026-05-08 14:03:56 +02:00
parent 34ea1eb4b2
commit c26898d4d2
6 changed files with 498 additions and 38 deletions
+55 -8
View File
@@ -45,6 +45,7 @@ function Invoke-Feature {
if (-not $State) { $State = @{} }
if (-not $State.ContainsKey('lastShownDate')) { $State['lastShownDate'] = $null }
if (-not $State.ContainsKey('snoozeUntil')) { $State['snoozeUntil'] = $null }
$today = (Get-Date).ToString('yyyy-MM-dd')
@@ -54,6 +55,21 @@ function Invoke-Feature {
return $State
}
if ($State['snoozeUntil']) {
try {
$snoozeUntil = [datetime]::Parse($State['snoozeUntil'])
if ((Get-Date) -lt $snoozeUntil) {
Write-Log -Level Info `
-Message ("Snoozed until {0}, skipping." -f $snoozeUntil.ToString('HH:mm:ss')) `
-Feature 'SandwichReminder'
return $State
}
}
catch {
Write-Log -Level Warn -Message "Invalid snoozeUntil value '$($State['snoozeUntil'])', ignoring." -Feature 'SandwichReminder'
}
}
# Parse reminder time
try {
$targetTime = [datetime]::ParseExact($Config['reminderTime'], 'HH:mm', $null)
@@ -86,17 +102,48 @@ function Invoke-Feature {
return $State
}
Write-Log -Level Info -Message 'Showing sandwich reminder toast.' -Feature 'SandwichReminder'
Write-Log -Level Info -Message 'Showing sandwich reminder confirmation dialog.' -Feature 'SandwichReminder'
Show-ToastNotification `
-Title 'Sandwich Order' `
-Body 'Do you want to order a sandwich today?' `
-Buttons @(
@{ Label = 'Yes, order now!'; Action = $Config['url'] },
@{ Label = 'No thanks'; Action = 'dismiss' }
$decision = Show-MultiChoiceDialog `
-Title 'Sandwich Order' `
-Message 'Do you want to order a sandwich today?' `
-Feature 'SandwichReminder' `
-DefaultValue 'snooze15' `
-Choices @(
@{ Label = 'Order now'; Value = 'order' },
@{ Label = 'Snooze 15 min'; Value = 'snooze15' },
@{ Label = 'Snooze 1h'; Value = 'snooze60' },
@{ Label = 'No'; Value = 'no' }
)
$State['lastShownDate'] = $today
if ($decision -eq 'order') {
try {
Start-Process $Config['url']
Write-Log -Level Info -Message "Opened sandwich order URL: $($Config['url'])" -Feature 'SandwichReminder'
}
catch {
Write-Log -Level Error -Message "Failed to open sandwich order URL '$($Config['url'])': $_" -Feature 'SandwichReminder'
}
$State['lastShownDate'] = $today
$State['snoozeUntil'] = $null
}
elseif ($decision -eq 'snooze60') {
$until = (Get-Date).AddHours(1)
$State['snoozeUntil'] = $until.ToString('o')
Write-Log -Level Info -Message ("User snoozed sandwich reminder for 1 hour (until {0})." -f $until.ToString('HH:mm:ss')) -Feature 'SandwichReminder'
}
elseif ($decision -eq 'no') {
$State['lastShownDate'] = $today
$State['snoozeUntil'] = $null
Write-Log -Level Info -Message 'User selected No for sandwich reminder; skipping for rest of day.' -Feature 'SandwichReminder'
}
else {
$until = (Get-Date).AddMinutes(15)
$State['snoozeUntil'] = $until.ToString('o')
Write-Log -Level Info -Message ("User snoozed sandwich reminder for 15 minutes (until {0})." -f $until.ToString('HH:mm:ss')) -Feature 'SandwichReminder'
}
return $State
}