Enhance SandwichReminder-AutoOrder feature with direct checkout navigation and improved logic

- Added new configuration options for direct checkout navigation, including `useDirectCheckoutNavigation`, `checkoutPath`, and `checkoutOpenDelayMs`.
- Updated the auto-order flow to navigate directly to the checkout page, skipping the mini-cart and date/time steps.
- Improved keyboard automation logic for item remark and order confirmation processes.
- Removed the old SandwichAutoOrder.ps1 file as its functionality has been integrated into SandwichReminder-AutoOrder.ps1.
- Introduced a new runner-launcher.vbs to start the runner.ps1 without a visible console window, ensuring WinForms dialogs can appear.
- Implemented a mutex mechanism in runner.ps1 to prevent concurrent execution of the same feature.
This commit is contained in:
Arne Moerman
2026-05-11 13:59:22 +02:00
parent 2592c0145f
commit 6c10d359d2
7 changed files with 525 additions and 205 deletions
+42 -12
View File
@@ -11,7 +11,7 @@ $ErrorActionPreference = 'Continue'
$script:InternalRoot = Join-Path $PSScriptRoot 'internal'
$script:TaskName = 'PSAutomation-Runner'
$script:TaskPath = '\'
$script:TaskPath = '\PowerShell Automation\'
$script:RunnerIntervalMinutes = 2
$script:ConfigureScriptPath = if ($PSCommandPath) { $PSCommandPath } else { $MyInvocation.MyCommand.Path }
$script:RegisterResultPath = Join-Path $script:InternalRoot 'data\logs\last-register-result.json'
@@ -394,6 +394,7 @@ function Show-RegistrationState {
}
$runnerPath = Join-Path $script:InternalRoot 'runner.ps1'
$runnerLauncherPath = Join-Path $script:InternalRoot 'runner-launcher.vbs'
Write-Host ''
Write-Host " Runner: $runnerPath" -ForegroundColor DarkGray
Write-Log -Level Info -Message ("Task found at path '{0}' with state '{1}'." -f $task.TaskPath, $task.State) -Feature 'Configure'
@@ -415,6 +416,7 @@ function Register-Runner {
Write-Log -Level Info -Message 'Register-Runner invoked.' -Feature 'Configure'
$runnerPath = Join-Path $script:InternalRoot 'runner.ps1'
$runnerLauncherPath = Join-Path $script:InternalRoot 'runner-launcher.vbs'
# Request elevation only for this operation, when needed.
if (-not (Test-Administrator)) {
@@ -474,6 +476,14 @@ function Register-Runner {
return
}
if (-not (Test-Path $runnerLauncherPath)) {
Write-Host " ERROR: runner-launcher.vbs not found at: $runnerLauncherPath" -ForegroundColor Red
Write-Log -Level Error -Message "runner-launcher.vbs missing at '$runnerLauncherPath'." -Feature 'Configure'
Write-OperationResult -Path $script:RegisterResultPath -Success $false -Message "runner-launcher.vbs missing at '$runnerLauncherPath'."
if (-not $NoPause) { Pause-ForKey }
return
}
$existing = Get-RunnerTask
if ($existing) {
Write-Host " Task '$($script:TaskName)' already exists (state: $($existing.State))." -ForegroundColor Yellow
@@ -504,8 +514,8 @@ function Register-Runner {
try {
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$action = New-ScheduledTaskAction `
-Execute 'powershell.exe' `
-Argument "-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -File `"$runnerPath`""
-Execute 'wscript.exe' `
-Argument "//B //Nologo `"$runnerLauncherPath`" `"$runnerPath`""
# Logon trigger — copy Repetition from a -Once trigger (reliable workaround)
$logonTrigger = New-ScheduledTaskTrigger -AtLogOn
@@ -766,9 +776,21 @@ function Initialize-FeatureCache {
# ═════════════════════════════════════════════════════════════════════════════
function Invoke-RunnerNow {
$runnerPath = Join-Path $script:InternalRoot 'runner.ps1'
$runnerLauncherPath = Join-Path $script:InternalRoot 'runner-launcher.vbs'
$task = Get-RunnerTask
if (-not $task) {
Write-Host " ERROR: Task is not registered. Use option 2 to register first." -ForegroundColor Red
if (-not (Test-Path $runnerPath)) {
Write-Host " ERROR: runner.ps1 not found at: $runnerPath" -ForegroundColor Red
Write-Log -Level Error -Message "runner.ps1 missing at '$runnerPath'." -Feature 'Configure'
Write-Host ''
Pause-ForKey
return
}
if (-not (Test-Path $runnerLauncherPath)) {
Write-Host " ERROR: runner-launcher.vbs not found at: $runnerLauncherPath" -ForegroundColor Red
Write-Log -Level Error -Message "runner-launcher.vbs missing at '$runnerLauncherPath'." -Feature 'Configure'
Write-Host ''
Pause-ForKey
return
@@ -776,15 +798,23 @@ function Invoke-RunnerNow {
try {
Write-Host ''
Write-Host " Executing runner task now..." -ForegroundColor Cyan
Start-ScheduledTask -TaskName $script:TaskName -TaskPath $script:TaskPath -ErrorAction Stop
Write-Host " Task execution started (runs async). Check logs in a moment." -ForegroundColor Green
Write-Hint " Note: The 2-minute repetition timer only starts on next logon/restart."
Write-Log -Level Info -Message "Runner task invoked manually from configure menu." -Feature 'Configure'
if ($task) {
Write-Host " Executing registered runner task now..." -ForegroundColor Cyan
Start-ScheduledTask -TaskName $task.TaskName -TaskPath $task.TaskPath -ErrorAction Stop
Write-Host " Task execution started (runs async). Check logs in a moment." -ForegroundColor Green
Write-Hint " Note: The 2-minute repetition timer only starts on next logon/restart."
Write-Log -Level Info -Message "Runner task invoked manually from configure menu." -Feature 'Configure'
}
else {
Write-Host " Task not registered; executing runner directly (hidden)..." -ForegroundColor Yellow
Start-Process -FilePath 'wscript.exe' -ArgumentList "//B //Nologo `"$runnerLauncherPath`" `"$runnerPath`"" -WindowStyle Hidden
Write-Host " Runner launch started (runs async). Check logs in a moment." -ForegroundColor Green
Write-Log -Level Info -Message "Runner invoked manually from configure menu via hidden launcher (task absent)." -Feature 'Configure'
}
}
catch {
Write-Host " ERROR: Failed to start task: $_" -ForegroundColor Red
Write-Log -Level Error -Message "Failed to start runner task manually: $_" -Feature 'Configure'
Write-Host " ERROR: Failed to start runner: $_" -ForegroundColor Red
Write-Log -Level Error -Message "Failed to start runner manually: $_" -Feature 'Configure'
}
Write-Host ''