mirror of
				https://github.com/house-of-abbey/GarminHomeAssistant.git
				synced 2025-10-31 15:48:13 +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:
		| @@ -30,6 +30,12 @@ | |||||||
|   --> |   --> | ||||||
|   <property id="app_timeout" type="number">0</property> |   <property id="app_timeout" type="number">0</property> | ||||||
|  |  | ||||||
|  |   <!-- | ||||||
|  |     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. | ||||||
|  |   --> | ||||||
|  |   <property id="confirm_timeout" type="number">3</property> | ||||||
|  |  | ||||||
|   <property id="types_representation" type="boolean"></property> |   <property id="types_representation" type="boolean"></property> | ||||||
|  |  | ||||||
|   <property id="menu_alignment" type="boolean"></property> |   <property id="menu_alignment" type="boolean"></property> | ||||||
|   | |||||||
| @@ -53,6 +53,16 @@ | |||||||
|     /> |     /> | ||||||
|   </setting> |   </setting> | ||||||
|  |  | ||||||
|  |   <setting | ||||||
|  |     propertyKey="@Properties.confirm_timeout" | ||||||
|  |     title="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." | ||||||
|  |   > | ||||||
|  |     <settingConfig | ||||||
|  |       type="numeric" | ||||||
|  |       min="0" | ||||||
|  |     /> | ||||||
|  |   </setting> | ||||||
|  |  | ||||||
|   <setting |   <setting | ||||||
|     propertyKey="@Properties.types_representation" |     propertyKey="@Properties.types_representation" | ||||||
|     title="Representing types with icons (off) or with labels (on)" |     title="Representing types with icons (off) or with labels (on)" | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ using Toybox.Lang; | |||||||
| typedef Method as Toybox.Lang.Method; | typedef Method as Toybox.Lang.Method; | ||||||
| using Toybox.WatchUi; | using Toybox.WatchUi; | ||||||
| using Toybox.Timer; | using Toybox.Timer; | ||||||
|  | using Toybox.Application.Properties; | ||||||
|  |  | ||||||
| class HomeAssistantConfirmation extends WatchUi.Confirmation { | class HomeAssistantConfirmation extends WatchUi.Confirmation { | ||||||
|     function initialize() { |     function initialize() { | ||||||
| @@ -38,13 +39,18 @@ class HomeAssistantConfirmationDelegate extends WatchUi.ConfirmationDelegate { | |||||||
|     function initialize(callback as Method() as Void) { |     function initialize(callback as Method() as Void) { | ||||||
|         WatchUi.ConfirmationDelegate.initialize(); |         WatchUi.ConfirmationDelegate.initialize(); | ||||||
|         confirmMethod = callback; |         confirmMethod = callback; | ||||||
|  |         var timeoutSeconds = Properties.getValue("confirm_timeout") as Lang.Number;  | ||||||
|  |         if (timeoutSeconds > 0) { | ||||||
|             timeout = new Timer.Timer(); |             timeout = new Timer.Timer(); | ||||||
|         timeout.start(method(:onTimeout), 3000, true); |             timeout.start(method(:onTimeout), timeoutSeconds * 1000, true); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function onResponse(response) as Lang.Boolean { |     function onResponse(response) as Lang.Boolean { | ||||||
|         getApp().getQuitTimer().reset(); |         getApp().getQuitTimer().reset(); | ||||||
|  |         if (timeout) { | ||||||
|             timeout.stop(); |             timeout.stop(); | ||||||
|  |         } | ||||||
|         if (response == WatchUi.CONFIRM_YES) { |         if (response == WatchUi.CONFIRM_YES) { | ||||||
|             confirmMethod.invoke(); |             confirmMethod.invoke(); | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user