mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-06-16 11:28:40 +00:00
Add application property "confirm_timeout"
After this time (in seconds), a confirmation dialog for an action is automatically closed and the action is cancelled. Set to 0 to disable the timeout. The default value is 3 seconds.
This commit is contained in:
@ -23,6 +23,7 @@ using Toybox.Lang;
|
||||
typedef Method as Toybox.Lang.Method;
|
||||
using Toybox.WatchUi;
|
||||
using Toybox.Timer;
|
||||
using Toybox.Application.Properties;
|
||||
|
||||
class HomeAssistantConfirmation extends WatchUi.Confirmation {
|
||||
function initialize() {
|
||||
@ -38,13 +39,18 @@ class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate {
|
||||
function initialize(callback as Method() as Void) {
|
||||
WatchUi.ConfirmationDelegate.initialize();
|
||||
confirmMethod = callback;
|
||||
timeout = new Timer.Timer();
|
||||
timeout.start(method(:onTimeout), 3000, true);
|
||||
var timeoutSeconds = Properties.getValue("confirm_timeout") as Lang.Number;
|
||||
if (timeoutSeconds > 0) {
|
||||
timeout = new Timer.Timer();
|
||||
timeout.start(method(:onTimeout), timeoutSeconds * 1000, true);
|
||||
}
|
||||
}
|
||||
|
||||
function onResponse(response) as Lang.Boolean {
|
||||
getApp().getQuitTimer().reset();
|
||||
timeout.stop();
|
||||
if (timeout) {
|
||||
timeout.stop();
|
||||
}
|
||||
if (response == WatchUi.CONFIRM_YES) {
|
||||
confirmMethod.invoke();
|
||||
}
|
||||
|
Reference in New Issue
Block a user