mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
feat(backup): Add information on when was the last time backup automatically created
This commit is contained in:
parent
6d60177a09
commit
951773053b
4 changed files with 22 additions and 10 deletions
|
@ -11,6 +11,7 @@
|
|||
-->
|
||||
## Additions
|
||||
- Add missing "Max automatic backups" option on experimental Data and Storage setting menu
|
||||
- Add information on when was the last time backup automatically created
|
||||
|
||||
## Changes
|
||||
- Add more info to WorkerInfo page
|
||||
|
@ -21,6 +22,7 @@
|
|||
- `manhua` tag no longer cause reading mode to switch to LTR
|
||||
- Local source manga's cover now being invalidated on refresh
|
||||
- You can now create a backup without any entries using experimental Data and Storage setting menu
|
||||
- Increased default maximum automatic backup files to 5
|
||||
|
||||
## Fixes
|
||||
- Fixed auto backup, auto extension update, and app update checker stop working
|
||||
|
|
|
@ -24,6 +24,7 @@ import yokai.domain.storage.StorageManager
|
|||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import java.io.FileOutputStream
|
||||
import java.time.Instant
|
||||
|
||||
class BackupCreator(
|
||||
val context: Context,
|
||||
|
@ -35,7 +36,7 @@ class BackupCreator(
|
|||
|
||||
val parser = ProtoBuf
|
||||
private val db: DatabaseHelper = Injekt.get()
|
||||
private val preferences: BackupPreferences = Injekt.get()
|
||||
private val backupPreferences: BackupPreferences = Injekt.get()
|
||||
private val storageManager: StorageManager by injectLazy()
|
||||
|
||||
@Suppress("RedundantSuspendModifier")
|
||||
|
@ -62,7 +63,7 @@ class BackupCreator(
|
|||
val dir = storageManager.getAutomaticBackupsDirectory()
|
||||
|
||||
// Delete older backups
|
||||
val numberOfBackups = preferences.numberOfBackups().get()
|
||||
val numberOfBackups = backupPreferences.numberOfBackups().get()
|
||||
dir?.listFiles { _, filename -> Backup.filenameRegex.matches(filename) }
|
||||
.orEmpty()
|
||||
.sortedByDescending { it.name }
|
||||
|
@ -103,6 +104,10 @@ class BackupCreator(
|
|||
// Make sure it's a valid backup file
|
||||
BackupFileValidator().validate(context, fileUri)
|
||||
|
||||
if (isAutoBackup) {
|
||||
backupPreferences.lastAutoBackupTimestamp().set(Instant.now().toEpochMilli())
|
||||
}
|
||||
|
||||
return fileUri.toString()
|
||||
} catch (e: Exception) {
|
||||
Logger.e(e)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package yokai.domain.backup
|
||||
|
||||
import eu.kanade.tachiyomi.core.preference.Preference
|
||||
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
|
||||
|
||||
|
@ -8,4 +9,6 @@ class BackupPreferences(private val preferenceStore: PreferenceStore) {
|
|||
fun numberOfBackups() = preferenceStore.getInt(PreferenceKeys.numberOfBackups, 5)
|
||||
|
||||
fun backupInterval() = preferenceStore.getInt(PreferenceKeys.backupInterval, 0)
|
||||
|
||||
fun lastAutoBackupTimestamp() = preferenceStore.getLong(Preference.appStateKey("last_auto_backup_timestamp"), 0L)
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import eu.kanade.tachiyomi.data.cache.CoverCache
|
|||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||
import eu.kanade.tachiyomi.util.compose.LocalAlertDialog
|
||||
import eu.kanade.tachiyomi.util.compose.currentOrThrow
|
||||
import eu.kanade.tachiyomi.util.relativeTimeSpanString
|
||||
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
||||
import eu.kanade.tachiyomi.util.system.e
|
||||
import eu.kanade.tachiyomi.util.system.launchNonCancellableIO
|
||||
|
@ -69,11 +70,11 @@ object SettingsDataScreen : ComposableSettings {
|
|||
@Composable
|
||||
override fun getPreferences(): List<Preference> {
|
||||
val storagePreferences: StoragePreferences by injectLazy()
|
||||
val preferences: BackupPreferences by injectLazy()
|
||||
val backupPreferences: BackupPreferences by injectLazy()
|
||||
|
||||
return persistentListOf(
|
||||
getStorageLocationPreference(storagePreferences = storagePreferences),
|
||||
getBackupAndRestoreGroup(preferences = preferences),
|
||||
getBackupAndRestoreGroup(backupPreferences = backupPreferences),
|
||||
getDataGroup(),
|
||||
)
|
||||
}
|
||||
|
@ -97,7 +98,7 @@ object SettingsDataScreen : ComposableSettings {
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun getBackupAndRestoreGroup(preferences: BackupPreferences): Preference.PreferenceGroup {
|
||||
private fun getBackupAndRestoreGroup(backupPreferences: BackupPreferences): Preference.PreferenceGroup {
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
val alertDialog = LocalAlertDialog.currentOrThrow
|
||||
|
@ -133,7 +134,8 @@ object SettingsDataScreen : ComposableSettings {
|
|||
}
|
||||
}
|
||||
|
||||
val backupInterval by preferences.backupInterval().collectAsState()
|
||||
val backupInterval by backupPreferences.backupInterval().collectAsState()
|
||||
val lastAutoBackup by backupPreferences.lastAutoBackupTimestamp().collectAsState()
|
||||
|
||||
return Preference.PreferenceGroup(
|
||||
title = stringResource(MR.strings.backup_and_restore),
|
||||
|
@ -205,7 +207,7 @@ object SettingsDataScreen : ComposableSettings {
|
|||
|
||||
// Automatic backups
|
||||
Preference.PreferenceItem.ListPreference(
|
||||
pref = preferences.backupInterval(),
|
||||
pref = backupPreferences.backupInterval(),
|
||||
title = stringResource(MR.strings.backup_frequency),
|
||||
entries = persistentMapOf(
|
||||
0 to stringResource(MR.strings.manual),
|
||||
|
@ -221,14 +223,14 @@ object SettingsDataScreen : ComposableSettings {
|
|||
},
|
||||
),
|
||||
Preference.PreferenceItem.ListPreference(
|
||||
pref = preferences.numberOfBackups(),
|
||||
pref = backupPreferences.numberOfBackups(),
|
||||
title = stringResource(MR.strings.max_auto_backups),
|
||||
entries = (1..5).associateWith { it.toString() }.toImmutableMap(),
|
||||
enabled = backupInterval > 0,
|
||||
),
|
||||
Preference.PreferenceItem.InfoPreference(
|
||||
stringResource(MR.strings.backup_info)
|
||||
/*+ "\n\n" + stringResource(MR.strings.last_auto_backup_info, relativeTimeSpanString(lastAutoBackup))*/,
|
||||
stringResource(MR.strings.backup_info) +
|
||||
"\n\n" + stringResource(MR.strings.last_auto_backup_info, relativeTimeSpanString(lastAutoBackup)),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue