浏览代码

Don't throw exception to stop restore job

arkon 4 年之前
父节点
当前提交
e4ea5d0344
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestoreService.kt

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

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