diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 4dc939d6..2bf843f1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -55,6 +55,7 @@ import com.lagradost.cloudstream3.plugins.PluginManager import com.lagradost.cloudstream3.plugins.PluginManager.loadAllOnlinePlugins import com.lagradost.cloudstream3.plugins.PluginManager.loadSinglePlugin import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver +import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.BackupApis import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appString @@ -612,6 +613,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java) this.sendBroadcast(broadcastIntent) afterPluginsLoadedEvent -= ::onAllPluginsLoaded + // run sync before app quits + BackupApis.forEach { it.addToQueueNow() } super.onDestroy() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/BackupAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/BackupAPI.kt index c391e059..72feefae 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/BackupAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/BackupAPI.kt @@ -102,12 +102,14 @@ interface BackupAPI { return } + addToQueueNow() + } + fun addToQueueNow() { if (uploadJob != null && uploadJob!!.isActive) { Log.d(LOG_KEY, "upload is canceled, scheduling new") uploadJob?.cancel() } - // we should ensure job will before app is closed uploadJob = ioScope.launchSafe { Log.d(LOG_KEY, "upload is running now") uploadSyncData() diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GoogleDriveApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GoogleDriveApi.kt index 66287a72..b53284db 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GoogleDriveApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GoogleDriveApi.kt @@ -39,7 +39,7 @@ import java.util.Date * * | State | Priority | Description * |---------:|:--------:|--------------------------------------------------------------------- - * | Progress | 4 | Implement backup before user quits application + * | Progress | 1 | Do not write sync meta when user is not syncing data * | Waiting | 2 | Add button to manually trigger sync * | Waiting | 3 | Move "https://chiff.github.io/cloudstream-sync/google-drive" * | Waiting | 5 | Choose what should be synced and recheck `invalidKeys` in createBackupScheduler @@ -49,6 +49,7 @@ import java.util.Date * | Solved | 2 | Restoring backup should update view models * | Solved | 1 | Check if data was really changed when calling backupscheduler.work then * | | | dont update sync meta if not needed + * | Solved | 4 | Implement backup before user quits application */ class GoogleDriveApi(index: Int) : InAppOAuth2APIManager(index),