Directly quit w/o showing RootView (if possible)

This commit is contained in:
SomeoneOnEarth
2023-12-12 21:42:02 +01:00
parent 3cc1dd88c3
commit 9aa32703cc
2 changed files with 16 additions and 6 deletions

View File

@ -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.

View File

@ -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());