From a2e5d9563f9dec84907f4f2060af6dfad895c4ba Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Mon, 20 Mar 2023 22:15:33 -0400 Subject: [Feature] resume TSR plugins after interruption WIP save tsr plugin path for later resume tsr plugin when user stops the interrupting plugin expand return of tsr_exit function to allow continue, suspend, terminate tsr plugins check parameter at start to determine if the plugin is being resumed Change-Id: I6fc70de664c7771e7dbc9a1af7a831e7b50b1d15 --- apps/plugins/lastfm_scrobbler.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'apps/plugins/lastfm_scrobbler.c') diff --git a/apps/plugins/lastfm_scrobbler.c b/apps/plugins/lastfm_scrobbler.c index 5565eed4c5..dce6be0d1e 100644 --- a/apps/plugins/lastfm_scrobbler.c +++ b/apps/plugins/lastfm_scrobbler.c @@ -98,7 +98,7 @@ static struct bool force_flush; } gCache; -static struct +static struct lastfm_config { int savepct; int beeplvl; @@ -528,7 +528,7 @@ void thread_quit(void) } /* callback to end the TSR plugin, called before a new one gets loaded */ -static bool exit_tsr(bool reenter) +static int exit_tsr(bool reenter) { MENUITEM_STRINGLIST(menu, ID2P(LANG_AUDIOSCROBBLER), NULL, ID2P(LANG_SETTINGS), "Flush Cache", "Exit Plugin", ID2P(LANG_BACK)); @@ -556,19 +556,13 @@ static bool exit_tsr(bool reenter) case 2: /* exit plugin - quit */ if(rb->gui_syncyesno_run(&quit_prompt, NULL, NULL) == YESNO_YES) { + scrobbler_flush_cache(); thread_quit(); - if (reenter) - rb->plugin_tsr(NULL); /* remove TSR cb */ - return !reenter; + return (reenter ? PLUGIN_TSR_TERMINATE : PLUGIN_TSR_SUSPEND); } - - if(!reenter) - return false; - - break; - + /* Fall Through */ case 3: /* back to menu */ - return false; + return PLUGIN_TSR_CONTINUE; } } } @@ -576,7 +570,17 @@ static bool exit_tsr(bool reenter) /****************** main ******************/ static int plugin_main(const void* parameter) { - (void)parameter; + struct lastfm_config cfg; + rb->memcpy(&cfg, & gConfig, sizeof(struct lastfm_config)); + + /* Resume plugin ? */ + if (parameter == rb->plugin_tsr) + { + + gConfig.beeplvl = 0; + gConfig.playback = false; + gConfig.verbose = false; + } rb->memset(&gThread, 0, sizeof(gThread)); if (gConfig.verbose) @@ -586,9 +590,11 @@ static int plugin_main(const void* parameter) rb->plugin_tsr(exit_tsr); /* stay resident */ thread_create(); + rb->memcpy(&gConfig, &cfg, sizeof(struct lastfm_config)); if (gConfig.playback) return PLUGIN_GOTO_WPS; + return PLUGIN_OK; } -- cgit v1.2.3