feat: add remote sync capability - run upload on activity destroy

This commit is contained in:
Martin Filo 2023-05-08 14:52:13 +02:00
parent 78b0cad098
commit 842ac5fbe0
3 changed files with 8 additions and 2 deletions

View file

@ -55,6 +55,7 @@ import com.lagradost.cloudstream3.plugins.PluginManager
import com.lagradost.cloudstream3.plugins.PluginManager.loadAllOnlinePlugins import com.lagradost.cloudstream3.plugins.PluginManager.loadAllOnlinePlugins
import com.lagradost.cloudstream3.plugins.PluginManager.loadSinglePlugin import com.lagradost.cloudstream3.plugins.PluginManager.loadSinglePlugin
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver 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.OAuth2Apis
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appString import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appString
@ -612,6 +613,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java) broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java)
this.sendBroadcast(broadcastIntent) this.sendBroadcast(broadcastIntent)
afterPluginsLoadedEvent -= ::onAllPluginsLoaded afterPluginsLoadedEvent -= ::onAllPluginsLoaded
// run sync before app quits
BackupApis.forEach { it.addToQueueNow() }
super.onDestroy() super.onDestroy()
} }

View file

@ -102,12 +102,14 @@ interface BackupAPI<LOGIN_DATA> {
return return
} }
addToQueueNow()
}
fun addToQueueNow() {
if (uploadJob != null && uploadJob!!.isActive) { if (uploadJob != null && uploadJob!!.isActive) {
Log.d(LOG_KEY, "upload is canceled, scheduling new") Log.d(LOG_KEY, "upload is canceled, scheduling new")
uploadJob?.cancel() uploadJob?.cancel()
} }
// we should ensure job will before app is closed
uploadJob = ioScope.launchSafe { uploadJob = ioScope.launchSafe {
Log.d(LOG_KEY, "upload is running now") Log.d(LOG_KEY, "upload is running now")
uploadSyncData() uploadSyncData()

View file

@ -39,7 +39,7 @@ import java.util.Date
* *
* | State | Priority | Description * | 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 | 2 | Add button to manually trigger sync
* | Waiting | 3 | Move "https://chiff.github.io/cloudstream-sync/google-drive" * | Waiting | 3 | Move "https://chiff.github.io/cloudstream-sync/google-drive"
* | Waiting | 5 | Choose what should be synced and recheck `invalidKeys` in createBackupScheduler * | 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 | 2 | Restoring backup should update view models
* | Solved | 1 | Check if data was really changed when calling backupscheduler.work then * | Solved | 1 | Check if data was really changed when calling backupscheduler.work then
* | | | dont update sync meta if not needed * | | | dont update sync meta if not needed
* | Solved | 4 | Implement backup before user quits application
*/ */
class GoogleDriveApi(index: Int) : class GoogleDriveApi(index: Int) :
InAppOAuth2APIManager(index), InAppOAuth2APIManager(index),