Always attempt automatic backup creation

- Defaults to every 12 hours
- Minimum number of backups is now 2, just to offer some level of redundancy in case something happens
- If it's missing storage permissions, it'll fail but that's the user's loss if they somehow haven't granted that permission yet
This commit is contained in:
arkon 2022-09-15 22:53:46 -04:00
parent 9d28def387
commit 829aadd0bd
6 changed files with 21 additions and 10 deletions

View File

@ -27,7 +27,7 @@ android {
applicationId = "eu.kanade.tachiyomi" applicationId = "eu.kanade.tachiyomi"
minSdk = AndroidConfig.minSdk minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk targetSdk = AndroidConfig.targetSdk
versionCode = 83 versionCode = 84
versionName = "0.13.6" versionName = "0.13.6"
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")

View File

@ -284,6 +284,15 @@ object Migrations {
remove("library_sorting_ascending") remove("library_sorting_ascending")
} }
} }
if (oldVersion < 84) {
if (preferences.numberOfBackups().get() == 1) {
preferences.numberOfBackups().set(2)
}
if (preferences.backupInterval().get() == 0) {
preferences.backupInterval().set(12)
BackupCreatorJob.setupTask(context)
}
}
return true return true
} }

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.data.backup package eu.kanade.tachiyomi.data.backup
import android.Manifest
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
@ -34,6 +35,7 @@ import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.copyFrom import eu.kanade.tachiyomi.source.model.copyFrom
import eu.kanade.tachiyomi.util.system.hasPermission
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
import eu.kanade.tachiyomi.util.system.toLong import eu.kanade.tachiyomi.util.system.toLong
import kotlinx.serialization.protobuf.ProtoBuf import kotlinx.serialization.protobuf.ProtoBuf
@ -68,6 +70,10 @@ class BackupManager(
*/ */
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
suspend fun createBackup(uri: Uri, flags: Int, isAutoBackup: Boolean): String { suspend fun createBackup(uri: Uri, flags: Int, isAutoBackup: Boolean): String {
if (!context.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
throw IllegalStateException(context.getString(R.string.missing_storage_permission))
}
val databaseManga = getFavorites.await() val databaseManga = getFavorites.await()
val backup = Backup( val backup = Backup(
backupMangas(databaseManga, flags), backupMangas(databaseManga, flags),

View File

@ -214,7 +214,7 @@ class PreferencesHelper(val context: Context) {
fun numberOfBackups() = flowPrefs.getInt("backup_slots", 2) fun numberOfBackups() = flowPrefs.getInt("backup_slots", 2)
fun backupInterval() = flowPrefs.getInt("backup_interval", 0) fun backupInterval() = flowPrefs.getInt("backup_interval", 12)
fun removeAfterReadSlots() = prefs.getInt(Keys.removeAfterReadSlots, -1) fun removeAfterReadSlots() = prefs.getInt(Keys.removeAfterReadSlots, -1)

View File

@ -108,14 +108,13 @@ class SettingsBackupController : SettingsController() {
bindTo(preferences.backupInterval()) bindTo(preferences.backupInterval())
titleRes = R.string.pref_backup_interval titleRes = R.string.pref_backup_interval
entriesRes = arrayOf( entriesRes = arrayOf(
R.string.update_never,
R.string.update_6hour, R.string.update_6hour,
R.string.update_12hour, R.string.update_12hour,
R.string.update_24hour, R.string.update_24hour,
R.string.update_48hour, R.string.update_48hour,
R.string.update_weekly, R.string.update_weekly,
) )
entryValues = arrayOf("0", "6", "12", "24", "48", "168") entryValues = arrayOf("6", "12", "24", "48", "168")
summary = "%s" summary = "%s"
onChange { newValue -> onChange { newValue ->
@ -137,8 +136,6 @@ class SettingsBackupController : SettingsController() {
} }
} }
visibleIf(preferences.backupInterval()) { it > 0 }
preferences.backupsDirectory().asFlow() preferences.backupsDirectory().asFlow()
.onEach { path -> .onEach { path ->
val dir = UniFile.fromUri(context, path.toUri()) val dir = UniFile.fromUri(context, path.toUri())
@ -149,11 +146,9 @@ class SettingsBackupController : SettingsController() {
intListPreference { intListPreference {
bindTo(preferences.numberOfBackups()) bindTo(preferences.numberOfBackups())
titleRes = R.string.pref_backup_slots titleRes = R.string.pref_backup_slots
entries = arrayOf("1", "2", "3", "4", "5") entries = arrayOf("2", "3", "4", "5")
entryValues = entries entryValues = entries
summary = "%s" summary = "%s"
visibleIf(preferences.backupInterval()) { it > 0 }
} }
} }

View File

@ -471,13 +471,14 @@
<string name="backup_choice">What do you want to backup?</string> <string name="backup_choice">What do you want to backup?</string>
<string name="creating_backup">Creating backup</string> <string name="creating_backup">Creating backup</string>
<string name="creating_backup_error">Backup failed</string> <string name="creating_backup_error">Backup failed</string>
<string name="missing_storage_permission">Storage permissions not granted</string>
<string name="empty_backup_error">No library entries to back up</string> <string name="empty_backup_error">No library entries to back up</string>
<string name="restore_miui_warning">Backup/restore may not function properly if MIUI Optimization is disabled.</string> <string name="restore_miui_warning">Backup/restore may not function properly if MIUI Optimization is disabled.</string>
<string name="restore_in_progress">Restore is already in progress</string> <string name="restore_in_progress">Restore is already in progress</string>
<string name="restoring_backup">Restoring backup</string> <string name="restoring_backup">Restoring backup</string>
<string name="restoring_backup_error">Restoring backup failed</string> <string name="restoring_backup_error">Restoring backup failed</string>
<string name="restoring_backup_canceled">Canceled restore</string> <string name="restoring_backup_canceled">Canceled restore</string>
<string name="backup_info">Automatic backups are highly recommended. You should keep copies in other places as well.</string> <string name="backup_info">You should keep copies of backups in other places as well.</string>
<!-- Advanced section --> <!-- Advanced section -->
<string name="label_network">Network</string> <string name="label_network">Network</string>