Add SandwichReminder-AutoOrder feature for automated sandwich ordering and enhance SandwichReminder logic
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
$FeatureMeta = @{
|
||||
Name = 'SandwichReminder-AutoOrder'
|
||||
Description = 'Personal automation settings for sandwich auto-order browser flow'
|
||||
Settings = @(
|
||||
@{
|
||||
Key = 'baseUrl'
|
||||
Label = 'Base URL'
|
||||
Type = 'string'
|
||||
Default = 'https://ylos-kitchen.unipage.eu'
|
||||
Description = 'Base URL of the ordering website'
|
||||
},
|
||||
@{
|
||||
Key = 'itemId'
|
||||
Label = 'Item ID'
|
||||
Type = 'string'
|
||||
Default = 'dmwmo3'
|
||||
Description = 'Item ID for direct item modal URL (default = Smoske)'
|
||||
},
|
||||
@{
|
||||
Key = 'windowTitleHint'
|
||||
Label = 'Browser Window Title Hint'
|
||||
Type = 'string'
|
||||
Default = "YLO'S Kitchen"
|
||||
Description = 'Used to bring browser window to foreground before sending keys'
|
||||
},
|
||||
@{
|
||||
Key = 'defaultItemRemark'
|
||||
Label = 'Default Item Remark'
|
||||
Type = 'string'
|
||||
Default = 'zonder tomaat aub'
|
||||
Description = 'For next step (checkout automation)'
|
||||
},
|
||||
@{
|
||||
Key = 'defaultOrderRemark'
|
||||
Label = 'Default Order Remark'
|
||||
Type = 'string'
|
||||
Default = 'levering in Sioen Bistro'
|
||||
Description = 'For next step (checkout automation)'
|
||||
},
|
||||
@{
|
||||
Key = 'initialDelayMs'
|
||||
Label = 'Initial Delay (ms)'
|
||||
Type = 'int'
|
||||
Default = 2500
|
||||
Description = 'Wait time after opening browser before key automation starts'
|
||||
},
|
||||
@{
|
||||
Key = 'activationTimeoutMs'
|
||||
Label = 'Activation Timeout (ms)'
|
||||
Type = 'int'
|
||||
Default = 10000
|
||||
Description = 'How long to retry foregrounding the browser window'
|
||||
},
|
||||
@{
|
||||
Key = 'stepDelayMs'
|
||||
Label = 'Key Step Delay (ms)'
|
||||
Type = 'int'
|
||||
Default = 120
|
||||
Description = 'Delay between keyboard steps'
|
||||
},
|
||||
@{
|
||||
Key = 'optionToggleKey'
|
||||
Label = 'Option Toggle Key'
|
||||
Type = 'string'
|
||||
Default = 'SPACE'
|
||||
Description = 'Key used to toggle option checkbox: SPACE or ENTER'
|
||||
},
|
||||
@{
|
||||
Key = 'calibrationOnly'
|
||||
Label = 'Calibration Only'
|
||||
Type = 'bool'
|
||||
Default = $false
|
||||
Description = 'If enabled, only tabs through the modal and stops (no clicks/add)'
|
||||
},
|
||||
@{
|
||||
Key = 'calibrationTabs'
|
||||
Label = 'Calibration Tabs'
|
||||
Type = 'int'
|
||||
Default = 0
|
||||
Description = 'Number of tabs to send in calibration mode before stopping'
|
||||
},
|
||||
@{
|
||||
Key = 'tabsToOption1'
|
||||
Label = 'Tabs To Option 1'
|
||||
Type = 'int'
|
||||
Default = 7
|
||||
Description = 'Tab count from modal start to first option checkbox'
|
||||
},
|
||||
@{
|
||||
Key = 'tabsBetweenOptions'
|
||||
Label = 'Tabs Between Options'
|
||||
Type = 'int'
|
||||
Default = 2
|
||||
Description = 'Tab count from first checkbox to second checkbox'
|
||||
},
|
||||
@{
|
||||
Key = 'tabsToAddButton'
|
||||
Label = 'Tabs To Add Button'
|
||||
Type = 'int'
|
||||
Default = 6
|
||||
Description = 'Tab count from second checkbox to add-to-cart button'
|
||||
},
|
||||
@{
|
||||
Key = 'openCartPopupAfterAdd'
|
||||
Label = 'Open Cart Popup After Add'
|
||||
Type = 'bool'
|
||||
Default = $true
|
||||
Description = 'Open mini-cart after adding item'
|
||||
},
|
||||
@{
|
||||
Key = 'refreshBeforeCart'
|
||||
Label = 'Refresh Before Cart'
|
||||
Type = 'bool'
|
||||
Default = $true
|
||||
Description = 'Refresh the page after add-to-cart to reset focus to page start before tabbing to mini-cart'
|
||||
},
|
||||
@{
|
||||
Key = 'postRefreshDelayMs'
|
||||
Label = 'Post-Refresh Delay (ms)'
|
||||
Type = 'int'
|
||||
Default = 2500
|
||||
Description = 'Wait time after F5 refresh before tabbing to mini-cart'
|
||||
},
|
||||
@{
|
||||
Key = 'tabsToCartButton'
|
||||
Label = 'Tabs To Cart Button'
|
||||
Type = 'int'
|
||||
Default = 5
|
||||
Description = 'Tab count from page start (after refresh) to mini-cart button'
|
||||
},
|
||||
@{
|
||||
Key = 'tabsToConfirmButton'
|
||||
Label = 'Tabs To Confirm Button'
|
||||
Type = 'int'
|
||||
Default = 3
|
||||
Description = 'Tab count from mini-cart button to confirm order button (opens delivery popup)'
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function Invoke-Feature {
|
||||
param(
|
||||
[hashtable]$Config,
|
||||
[hashtable]$State
|
||||
)
|
||||
|
||||
if (-not $State) { $State = @{} }
|
||||
return $State
|
||||
}
|
||||
@@ -118,8 +118,21 @@ function Invoke-Feature {
|
||||
|
||||
if ($decision -eq 'order') {
|
||||
try {
|
||||
Start-Process $Config['url']
|
||||
Write-Log -Level Info -Message "Opened sandwich order URL: $($Config['url'])" -Feature 'SandwichReminder'
|
||||
$rootConfig = Get-Config
|
||||
$autoOrderConfig = $null
|
||||
|
||||
if ($rootConfig.features.ContainsKey('SandwichReminder-AutoOrder')) {
|
||||
$autoOrderConfig = $rootConfig.features['SandwichReminder-AutoOrder']
|
||||
}
|
||||
|
||||
if ($autoOrderConfig -and $autoOrderConfig['enabled']) {
|
||||
Write-Log -Level Info -Message 'SandwichReminder-AutoOrder is enabled; running auto-order flow.' -Feature 'SandwichReminder'
|
||||
[void](Invoke-SandwichAutoOrderFlow -AutoOrderConfig $autoOrderConfig -FallbackUrl $Config['url'])
|
||||
}
|
||||
else {
|
||||
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'
|
||||
|
||||
Reference in New Issue
Block a user