Removed timer based update mechanism

Instead chaining calls from the previous update is a slightly close coupled way that might need to be refined.
This commit is contained in:
Philip Abbey
2023-11-11 20:00:26 +00:00
parent fde270ff34
commit 765d7f7f50
40 changed files with 79 additions and 58 deletions

View File

@ -23,9 +23,7 @@ using Toybox.Lang;
class Globals {
// Enable printing of messages to the debug console (don't make this a Property
// as the messages can't be read from a watch!)
static const scDebug = false;
// There's a danger this time is device sensitive.
static const scMenuItemUpdateInterval = 100; // ms, 100 ms seems okay for Venu2
static const scAlertTimeout = 2000; // ms
static const scTapTimeout = 1000; // ms
static const scDebug = false;
static const scAlertTimeout = 2000; // ms
static const scTapTimeout = 1000; // ms
}

View File

@ -32,7 +32,6 @@ class HomeAssistantApp extends Application.AppBase {
hidden var strNoInternet as Lang.String;
hidden var strNoMenu as Lang.String;
hidden var strApiFlood as Lang.String;
hidden var mTimer as Timer.Timer;
hidden var mItemsToUpdate; // Array initialised by onReturnFetchMenuConfig()
hidden var mNextItemToUpdate = 0; // Index into the above array
@ -44,7 +43,6 @@ class HomeAssistantApp extends Application.AppBase {
strNoInternet = WatchUi.loadResource($.Rez.Strings.NoInternet);
strNoMenu = WatchUi.loadResource($.Rez.Strings.NoMenu);
strApiFlood = WatchUi.loadResource($.Rez.Strings.ApiFlood);
mTimer = new Timer.Timer();
}
// onStart() is called on application start up
@ -52,11 +50,7 @@ class HomeAssistantApp extends Application.AppBase {
}
// onStop() is called when your application is exiting
function onStop(state as Lang.Dictionary?) as Void {
if (mTimer != null) {
mTimer.stop();
}
}
function onStop(state as Lang.Dictionary?) as Void {}
// Return the initial view of your application here
function getInitialView() as Lang.Array<WatchUi.Views or WatchUi.InputDelegates>? {
@ -106,11 +100,9 @@ class HomeAssistantApp extends Application.AppBase {
mHaMenu = new HomeAssistantView(data, null);
WatchUi.switchToView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE);
mItemsToUpdate = mHaMenu.getItemsToUpdate();
mTimer.start(
method(:updateNextMenuItem),
Globals.scMenuItemUpdateInterval,
true
);
// Start the continuous update process that continues for as long as the application is running.
// The chain of functions from 'updateNextMenuItem()' calls 'updateNextMenuItem()' on completion.
updateNextMenuItem();
} else if (responseCode == -300) {
if (Globals.scDebug) {
System.println("HomeAssistantApp Note - onReturnFetchMenuConfig(): Network request timeout.");

View File

@ -85,6 +85,8 @@ class HomeAssistantToggleMenuItem extends WatchUi.ToggleMenuItem {
}
setUiToggle(state);
}
// Now this feels very "closely coupled" to the application, but it is the most reliable method instead of using a timer.
getApp().updateNextMenuItem();
}
function getState() as Void {