Catch WorkManager crash.

This commit is contained in:
Koen J 2024-09-04 14:24:11 +02:00
commit eb6e79b055
2 changed files with 26 additions and 18 deletions

View file

@ -235,6 +235,7 @@ class SettingsDev : FragmentedStorageFileJson() {
R.string.test_background_worker_description, 4) R.string.test_background_worker_description, 4)
fun triggerBackgroundUpdate() { fun triggerBackgroundUpdate() {
val act = SettingsActivity.getActivity()!!; val act = SettingsActivity.getActivity()!!;
try {
UIDialogs.toast(SettingsActivity.getActivity()!!, "Starting test background worker"); UIDialogs.toast(SettingsActivity.getActivity()!!, "Starting test background worker");
val wm = WorkManager.getInstance(act); val wm = WorkManager.getInstance(act);
@ -242,6 +243,9 @@ class SettingsDev : FragmentedStorageFileJson() {
.setInputData(Data.Builder().putBoolean("bypassMainCheck", true).build()) .setInputData(Data.Builder().putBoolean("bypassMainCheck", true).build())
.build(); .build();
wm.enqueue(req); wm.enqueue(req);
} catch (e: Throwable) {
UIDialogs.showGeneralErrorDialog(act, "Failed to trigger background update", e)
}
} }
@FormField(R.string.clear_channel_cache, FieldForm.BUTTON, @FormField(R.string.clear_channel_cache, FieldForm.BUTTON,
R.string.test_background_worker_description, 4) R.string.test_background_worker_description, 4)

View file

@ -627,6 +627,7 @@ class StateApp {
fun scheduleBackgroundWork(context: Context, active: Boolean = true, intervalMinutes: Int = 60 * 12) { fun scheduleBackgroundWork(context: Context, active: Boolean = true, intervalMinutes: Int = 60 * 12) {
try {
val wm = WorkManager.getInstance(context); val wm = WorkManager.getInstance(context);
if(active) { if(active) {
@ -642,6 +643,9 @@ class StateApp {
} }
else else
wm.cancelAllWork(); wm.cancelAllWork();
} catch (e: Throwable) {
Logger.e(TAG, "Failed to schedule background subscription updates.", e)
}
} }