1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-12 04:41:26 +04:00

[FL-3847, FL-3513] Thread Signals (#3730)

* Add signal API
* Add signal support to loader
* Add signal support to ViewDispatcher
* Remove extra signal definitions
* Fix typos
  Co-authored-by: Silent <CookiePLMonster@users.noreply.github.com>
* scripts: runfap: close current app pre-launch
* loader: enable backlight when starting an app
* scripts: removed distfap.py
* Do not expose signal API via ViewDispatcher
* scripts: runfap: iterative retry to launch
* Add a loader signal subcommand
* Furi, Gui: move signal handling from View Dispatcher to Event Loop

Co-authored-by: Silent <CookiePLMonster@users.noreply.github.com>
Co-authored-by: hedger <hedger@nanode.su>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Georgii Surkov
2024-06-21 23:44:36 +03:00
committed by GitHub
parent a0036d10fc
commit 4cf98867a0
16 changed files with 291 additions and 109 deletions

View File

@@ -1,69 +0,0 @@
#!/usr/bin/env python3
import os
import posixpath
from flipper.app import App
from flipper.storage import FlipperStorage, FlipperStorageOperations
from flipper.utils.cdc import resolve_port
class Main(App):
def init(self):
self.parser.add_argument("-p", "--port", help="CDC Port", default="auto")
self.parser.add_argument(
"-n",
"--no-launch",
dest="launch_app",
action="store_false",
help="Don't launch app",
)
self.parser.add_argument("fap_src_path", help="App file to upload")
self.parser.add_argument(
"--fap_dst_dir", help="Upload path", default="/ext/apps", required=False
)
self.parser.set_defaults(func=self.install)
def install(self):
if not (port := resolve_port(self.logger, self.args.port)):
return 1
try:
with FlipperStorage(port) as storage:
storage_ops = FlipperStorageOperations(storage)
fap_local_path = self.args.fap_src_path
self.args.fap_dst_dir = self.args.fap_dst_dir.rstrip("/\\")
if not os.path.isfile(fap_local_path):
self.logger.error(
f"Error: source .fap ({fap_local_path}) not found"
)
return 2
fap_dst_path = posixpath.join(
self.args.fap_dst_dir, os.path.basename(fap_local_path)
)
self.logger.info(f'Installing "{fap_local_path}" to {fap_dst_path}')
storage_ops.recursive_send(fap_dst_path, fap_local_path, False)
if not self.args.launch_app:
return 0
storage.send_and_wait_eol(f"loader open {fap_dst_path}\r")
if len(result := storage.read.until(storage.CLI_EOL)):
self.logger.error(f"Unexpected response: {result.decode('ascii')}")
return 3
return 0
except Exception as e:
self.logger.error(f"Error: {e}")
# raise
return 4
if __name__ == "__main__":
Main()()

View File

@@ -2,6 +2,7 @@
import operator
from functools import reduce
import time
from flipper.app import App
from flipper.storage import FlipperStorage, FlipperStorageOperations
@@ -9,6 +10,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")
self.parser.add_argument(
@@ -67,6 +70,23 @@ class Main(App):
if self.args.host_app:
startup_command = self.args.host_app
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
self.logger.info(f"Launching app: {startup_command}")
storage.send_and_wait_eol(f"loader open {startup_command}\r")