FBT: Close current app when flashing firmware

This commit is contained in:
Willy-JL
2024-07-13 23:49:04 +01:00
parent 233d215040
commit 502d721629
2 changed files with 23 additions and 1 deletions
+20
View File
@@ -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"
)