Add profile sharing

This commit is contained in:
世界
2023-07-30 21:16:05 +08:00
parent 9575764f40
commit fe0b3fdce3
22 changed files with 302 additions and 87 deletions

View File

@@ -5,9 +5,7 @@ import android.content.Context
import android.content.Intent
import android.util.Log
import io.nekohasekai.sfa.database.Settings
import io.nekohasekai.sfa.ui.configoverride.PerAppProxyActivity
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import io.nekohasekai.sfa.ui.profileoverride.PerAppProxyActivity
class AppChangeReceiver : BroadcastReceiver() {

View File

@@ -20,7 +20,7 @@ import io.nekohasekai.sfa.Application
import io.nekohasekai.sfa.constant.Action
import io.nekohasekai.sfa.constant.Alert
import io.nekohasekai.sfa.constant.Status
import io.nekohasekai.sfa.database.Profiles
import io.nekohasekai.sfa.database.ProfileManager
import io.nekohasekai.sfa.database.Settings
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
@@ -92,6 +92,7 @@ class BoxService(
Action.SERVICE_CLOSE -> {
stopService()
}
Action.SERVICE_RELOAD -> {
serviceReload()
}
@@ -114,7 +115,7 @@ class BoxService(
return
}
val profile = Profiles.get(selectedProfileId)
val profile = ProfileManager.get(selectedProfileId)
if (profile == null) {
stopAndAlert(Alert.EmptyConfiguration)
return

View File

@@ -10,7 +10,7 @@ import androidx.work.WorkManager
import androidx.work.WorkerParameters
import io.nekohasekai.libbox.Libbox
import io.nekohasekai.sfa.Application
import io.nekohasekai.sfa.database.Profiles
import io.nekohasekai.sfa.database.ProfileManager
import io.nekohasekai.sfa.database.TypedProfile
import io.nekohasekai.sfa.utils.HTTPClient
import java.io.File
@@ -33,7 +33,7 @@ class UpdateProfileWork {
private suspend fun reconfigureUpdater0() {
WorkManager.getInstance(Application.application).cancelUniqueWork(WORK_NAME)
val remoteProfiles = Profiles.list()
val remoteProfiles = ProfileManager.list()
.filter { it.typed.type == TypedProfile.Type.Remote && it.typed.autoUpdate }
if (remoteProfiles.isEmpty()) return
@@ -62,7 +62,7 @@ class UpdateProfileWork {
appContext: Context, params: WorkerParameters
) : CoroutineWorker(appContext, params) {
override suspend fun doWork(): Result {
val remoteProfiles = Profiles.list()
val remoteProfiles = ProfileManager.list()
.filter { it.typed.type == TypedProfile.Type.Remote && it.typed.autoUpdate }
if (remoteProfiles.isEmpty()) return Result.success()
val httpClient = HTTPClient()
@@ -73,7 +73,7 @@ class UpdateProfileWork {
Libbox.checkConfig(content)
File(profile.typed.path).writeText(content)
profile.typed.lastUpdated = Date()
Profiles.update(profile)
ProfileManager.update(profile)
} catch (e: Exception) {
Log.e("UpdateProfileWork", "error when updating profile ${profile.name}", e)
success = false