From 9aa32703cc6ef2ab20212a4fc265b03ff34a5f87 Mon Sep 17 00:00:00 2001 From: SomeoneOnEarth Date: Tue, 12 Dec 2023 21:42:02 +0100 Subject: [PATCH] Directly quit w/o showing RootView (if possible) --- source/HomeAssistantApp.mc | 2 +- source/HomeAssistantView.mc | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/source/HomeAssistantApp.mc b/source/HomeAssistantApp.mc index 7c78723..49873c1 100644 --- a/source/HomeAssistantApp.mc +++ b/source/HomeAssistantApp.mc @@ -177,7 +177,7 @@ class HomeAssistantApp extends Application.AppBase { } function pushHomeAssistantMenuView() as Void{ - WatchUi.pushView(mHaMenu, new HomeAssistantViewDelegate(), WatchUi.SLIDE_IMMEDIATE); + WatchUi.pushView(mHaMenu, new HomeAssistantViewDelegate(true), WatchUi.SLIDE_IMMEDIATE); } // We need to spread out the API calls so as not to overload the results queue and cause Communications.BLE_QUEUE_FULL (-101) error. diff --git a/source/HomeAssistantView.mc b/source/HomeAssistantView.mc index 366dcac..c09a42e 100644 --- a/source/HomeAssistantView.mc +++ b/source/HomeAssistantView.mc @@ -21,6 +21,7 @@ using Toybox.Application; using Toybox.Lang; using Toybox.Graphics; +using Toybox.System; using Toybox.WatchUi; class HomeAssistantView extends WatchUi.Menu2 { @@ -103,12 +104,23 @@ class HomeAssistantView extends WatchUi.Menu2 { // class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate { - function initialize() { + private var mIsRootMenuView = false; + + function initialize(isRootMenuView as Lang.Boolean) { Menu2InputDelegate.initialize(); + mIsRootMenuView = isRootMenuView; } function onBack() { getApp().getQuitTimer().reset(); + + if (mIsRootMenuView){ + // If its started from glance or as an activity, directly exit the widget/app + // (on widgets without glance, this exit() won`t do anything, + // so the base view will be shown instead, through the popView below this "if body") + System.exit(); + } + WatchUi.popView(WatchUi.SLIDE_RIGHT); } @@ -147,15 +159,13 @@ class HomeAssistantViewDelegate extends WatchUi.Menu2InputDelegate { if (Globals.scDebug) { System.println("Menu: " + haMenuItem.getLabel() + " " + haMenuItem.getId()); } - // No delegate state to be amended, so re-use 'self'. - WatchUi.pushView(haMenuItem.getMenuView(), self, WatchUi.SLIDE_LEFT); + WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT); } else if (item instanceof HomeAssistantViewIconMenuItem) { var haMenuItem = item as HomeAssistantViewIconMenuItem; if (Globals.scDebug) { System.println("IconMenu: " + haMenuItem.getLabel() + " " + haMenuItem.getId()); } - // No delegate state to be amended, so re-use 'self'. - WatchUi.pushView(haMenuItem.getMenuView(), self, WatchUi.SLIDE_LEFT); + WatchUi.pushView(haMenuItem.getMenuView(), new HomeAssistantViewDelegate(false), WatchUi.SLIDE_LEFT); } else { if (Globals.scDebug) { System.println(item.getLabel() + " " + item.getId());