From 502d7216294726c92905d4c5660b26cdbc1c31aa Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sat, 13 Jul 2024 23:49:04 +0100 Subject: [PATCH] FBT: Close current app when flashing firmware --- CHANGELOG.md | 4 +++- scripts/selfupdate.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88cfbb45a..a63476d76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,9 @@ - JS: - Added ADC (analog voltage) support to gpio library (by @jamisonderek) - Support `subghz` custom modulation, support `transmitFile(path, repeats)`, new `end()` function (by @Willy-JL) -- FBT: New `SKIP_EXTERNAL` toggle and `EXTRA_EXT_APPS` config option (by @Willy-JL) +- FBT: + - New `SKIP_EXTERNAL` toggle and `EXTRA_EXT_APPS` config option (by @Willy-JL) + - Close current app when flashing firmware (by @Willy-JL) - GUI: Additional `menu_get_selected_item()` API (by @Willy-JL) - Desktop: - Added TV animation from OFW which was missing (internal on OFW) diff --git a/scripts/selfupdate.py b/scripts/selfupdate.py index d222bf249..e36bb5257 100755 --- a/scripts/selfupdate.py +++ b/scripts/selfupdate.py @@ -3,6 +3,7 @@ import logging import os import pathlib +import time from flipper.app import App from flipper.storage import FlipperStorage, FlipperStorageOperations @@ -10,6 +11,8 @@ from flipper.utils.cdc import resolve_port class Main(App): + APP_POST_CLOSE_DELAY_SEC = 0.2 + def init(self): self.parser.add_argument("-p", "--port", help="CDC Port", default="auto") @@ -48,6 +51,23 @@ class Main(App): flipper_update_path, manifest_path.parents[0] ) + self.logger.info("Closing current app, if any") + for _ in range(10): + storage.send_and_wait_eol("loader close\r") + result = storage.read.until(storage.CLI_EOL) + if b"was closed" in result: + self.logger.info("App closed") + storage.read.until(storage.CLI_EOL) + time.sleep(self.APP_POST_CLOSE_DELAY_SEC) + elif result.startswith(b"No application"): + storage.read.until(storage.CLI_EOL) + break + else: + self.logger.error( + f"Unexpected response: {result.decode('ascii')}" + ) + return 4 + storage.send_and_wait_eol( f"update install {flipper_update_path}/{manifest_name}\r" )