- Notifications
You must be signed in to change notification settings - Fork0
A background loader for Flipper Zero Apps
License
twisted-pear/bgloader
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a plugin for the Flipper Zero that allows compatible apps to be loadedand to remain running in the background.
Once started the plugin will display a file browser that allows you to selectan application's FAP file. If the application is not already running, it willbe loaded. The application then has the choice of terminating normally, inwhich case the loader will unload the application as normal, or to relinquishcontrol of the GUI and to keep active in the background, in which case theloader will not unload the application.
If an already running application is selected, the loader will inform theapplication that it can reassert control over the GUI and continue in theforeground. Once again, the reattached application can chose to terminatenormally or to keep active in the background.
Make sure you only select compatible applications (see below) and that younever start an application more than once at the same time (by launching it inthe background and then selecting it in the Flipper's apps menu).
This plugin is in the early stages of development. It will inevitably havebugs. You have been warned.
An application needs to be compatible with this loader. Compatible apps mustcheck their startup parameters to determine if they have been launched via thebackground loader. If so, they must inform the loader when they wish to keeprunning in the background. If they decide to keep running in the background,they must listen for the loader's signal that they are being reopened and thusallowed to use the GUI again.
The loader's API can be found inbgloader_api.h. In the simplest case, theapp will need to do the following:
- Check for the loader's special parameter. The parameter will have the form
run_in_background:<path to the app's FAP file>. - Retrieve the FAP file path from the parameter and use it to access the
BGLoaderAppstructure. This can be done by callingfuri_record_open(<FAP file path>). - Once the app is ready to go into the background it needs to detach from theGUI and send a
BGLoaderMessagewith typeBGLoaderMessageType_LoaderBackgroundto theto_loaderqueue in theBGLoaderAppstructure. - While in the background the app need to check the
to_appqueue in theBGLoaderAppstructure for a message of the typeBGLoaderMessageType_AppReattached. This message informs the app that it isbeing reattached and can attach itself to the GUI again. - To terminate, the app just exits normally.
An example of what a compatible app might look like is given below:
static const char *get_bgloader_app_path(const char *args){size_t base_args_len = strlen(APP_BASE_ARGS);return (args + base_args_len + 1);}static bool run_with_bgloader(const char *args){size_t base_args_len = strlen(APP_BASE_ARGS);if (args == NULL) {return false;}if (strncmp(args, APP_BASE_ARGS, base_args_len) != 0) {return false;}if (strlen(args) < base_args_len + 2) {return false;}if (args[base_args_len] != ':') {return false;}const char *app_path = get_bgloader_app_path(args);return furi_record_exists(app_path);}static void bgloader_loop(AppState *state, const char *bg_app_path){while (true) {view_dispatcher_run(state->view_dispatcher);// 2.BGLoaderApp *bg_app = furi_record_open(bg_app_path);// exit_for_real is set elsewhere to indicate the app is ready// to terminateif (state->exit_for_real) {// 5.// exit normallyfuri_record_close(bg_app_path);break;}// 3.// signal loader that we're ready to go to backgroundBGLoaderMessage msg;msg.type = BGLoaderMessageType_LoaderBackground;furi_check(furi_message_queue_put(bg_app->to_loader, &msg,FuriWaitForever) == FuriStatusOk);detach_from_gui(state);// 4.// wait for loader to wake us up againfuri_check(furi_message_queue_get(bg_app->to_app, &msg,FuriWaitForever) == FuriStatusOk);switch(msg.type) {case BGLoaderMessageType_AppReattached:break;default:furi_check(0);}furi_record_close(bg_app_path);attach_to_gui(state);}}int32_t app_entry_point(const char *args){...// regular setup...// 1.bool run_with_bgl = run_with_bgloader(args);...if (run_with_bgl) {const char *bg_app_path = get_bgloader_app_path(args);bgloader_loop(state, bg_app_path);} else {// regular main loop (e.g. view_dispatcher_run())}...// regular teardown...}For examples of compatible apps check outf0forth orESubGhz Chat.
Thanks toWilly-JL for coming up with an ideafor how to store the pointers to an application's data structures and for howto signal an application's thread to terminate.
The app icon was made byxMasterX.
About
A background loader for Flipper Zero Apps
Resources
License
Uh oh!
There was an error while loading.Please reload this page.