Kaynağa Gözat

Don't throw exception to stop restore job

arkon 4 yıl önce
ebeveyn
işleme
e4ea5d0344

+ 6 - 3
app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt

@@ -175,7 +175,9 @@ class BackupRestoreService : Service() {
             stopSelf(startId)
         }
         job = GlobalScope.launch(handler) {
-            restoreBackup(uri)
+            if (!restoreBackup(uri)) {
+                notifier.showRestoreError(getString(R.string.restoring_backup_canceled))
+            }
         }
         job?.invokeOnCompletion {
             stopSelf(startId)
@@ -189,7 +191,7 @@ class BackupRestoreService : Service() {
      *
      * @param uri backup file to restore
      */
-    private fun restoreBackup(uri: Uri) {
+    private fun restoreBackup(uri: Uri): Boolean {
         val startTime = System.currentTimeMillis()
 
         val reader = JsonReader(contentResolver.openInputStream(uri)!!.bufferedReader())
@@ -213,7 +215,7 @@ class BackupRestoreService : Service() {
         // Restore individual manga
         mangasJson.forEach {
             if (job?.isActive != true) {
-                throw Exception(getString(R.string.restoring_backup_canceled))
+                return false
             }
 
             restoreManga(it.asJsonObject)
@@ -225,6 +227,7 @@ class BackupRestoreService : Service() {
         val logFile = writeErrorLog()
 
         notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name)
+        return true
     }
 
     private fun restoreCategories(categoriesJson: JsonElement) {