mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-02 14:19:56 +00:00
Various fixes.
This commit is contained in:
parent
5052bad824
commit
48a67e51a6
6 changed files with 53 additions and 24 deletions
|
@ -9,6 +9,7 @@ import android.widget.LinearLayout
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.futo.platformplayer.R
|
||||
import com.futo.platformplayer.logging.Logger
|
||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||
import com.futo.platformplayer.states.StateApp
|
||||
import com.futo.platformplayer.states.StateSync
|
||||
|
@ -29,6 +30,16 @@ class SyncHomeActivity : AppCompatActivity() {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
if (StateApp.instance.contextOrNull == null) {
|
||||
Logger.w(TAG, "No main activity, restarting main.")
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_sync_home)
|
||||
setNavigationBarColorAndIcons()
|
||||
|
||||
|
|
|
@ -530,10 +530,17 @@ class StateApp {
|
|||
|
||||
//Migration
|
||||
Logger.i(TAG, "MainApp Started: Check [Migrations]");
|
||||
migrateStores(context, listOf(
|
||||
StateSubscriptions.instance.toMigrateCheck(),
|
||||
StatePlaylists.instance.toMigrateCheck()
|
||||
).flatten(), 0);
|
||||
|
||||
scopeOrNull?.launch(Dispatchers.IO) {
|
||||
try {
|
||||
migrateStores(context, listOf(
|
||||
StateSubscriptions.instance.toMigrateCheck(),
|
||||
StatePlaylists.instance.toMigrateCheck()
|
||||
).flatten(), 0)
|
||||
} catch (e: Throwable) {
|
||||
Logger.e(TAG, "Failed to migrate stores")
|
||||
}
|
||||
}
|
||||
|
||||
if(Settings.instance.subscriptions.fetchOnAppBoot) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
|
@ -700,15 +707,27 @@ class StateApp {
|
|||
}
|
||||
|
||||
|
||||
private fun migrateStores(context: Context, managedStores: List<ManagedStore<*>>, index: Int) {
|
||||
private suspend fun migrateStores(context: Context, managedStores: List<ManagedStore<*>>, index: Int) {
|
||||
if(managedStores.size <= index)
|
||||
return;
|
||||
val store = managedStores[index];
|
||||
if(store.hasMissingReconstructions())
|
||||
UIDialogs.showMigrateDialog(context, store) {
|
||||
migrateStores(context, managedStores, index + 1);
|
||||
};
|
||||
else
|
||||
if(store.hasMissingReconstructions()) {
|
||||
withContext(Dispatchers.Main) {
|
||||
try {
|
||||
UIDialogs.showMigrateDialog(context, store) {
|
||||
scopeOrNull?.launch(Dispatchers.IO) {
|
||||
try {
|
||||
migrateStores(context, managedStores, index + 1);
|
||||
} catch (e: Throwable) {
|
||||
Logger.e(TAG, "Failed to migrate store", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Logger.e(TAG, "Failed to migrate stores", e)
|
||||
}
|
||||
}
|
||||
} else
|
||||
migrateStores(context, managedStores, index + 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -401,12 +401,15 @@ class StatePlaylists {
|
|||
companion object {
|
||||
val TAG = "StatePlaylists";
|
||||
private var _instance : StatePlaylists? = null;
|
||||
private var _lockObject = Object()
|
||||
val instance : StatePlaylists
|
||||
get(){
|
||||
if(_instance == null)
|
||||
_instance = StatePlaylists();
|
||||
return _instance!!;
|
||||
};
|
||||
get() {
|
||||
synchronized(_lockObject) {
|
||||
if (_instance == null)
|
||||
_instance = StatePlaylists();
|
||||
return _instance!!;
|
||||
}
|
||||
}
|
||||
|
||||
fun finish() {
|
||||
_instance?.let {
|
||||
|
|
|
@ -57,6 +57,7 @@ import kotlinx.coroutines.withContext
|
|||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.net.Inet4Address
|
||||
import java.net.InetAddress
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.ServerSocket
|
||||
|
@ -438,7 +439,7 @@ class StateSync {
|
|||
Logger.v(TAG, "Received ${connectionInfos.size} devices connection information")
|
||||
|
||||
for ((targetKey, connectionInfo) in connectionInfos) {
|
||||
val potentialLocalAddresses = connectionInfo.ipv4Addresses.union(connectionInfo.ipv6Addresses)
|
||||
val potentialLocalAddresses = connectionInfo.ipv4Addresses
|
||||
.filter { it != connectionInfo.remoteIp }
|
||||
if (connectionInfo.allowLocalDirect && Settings.instance.synchronization.connectLocalDirectThroughRelay) {
|
||||
Thread {
|
||||
|
|
|
@ -125,12 +125,7 @@ class FragmentedStorage {
|
|||
}
|
||||
inline fun <reified T> load(fileName: String): T where T : FragmentedStorageFile {
|
||||
if (_filesDir == null) {
|
||||
if(StateApp.instance.contextOrNull == null)
|
||||
StateApp.instance.initializeFiles();
|
||||
|
||||
if (_filesDir == null) {
|
||||
throw Exception("Files dir should be initialized before loading a file.")
|
||||
}
|
||||
throw Exception("Files dir should be initialized before loading a file.")
|
||||
}
|
||||
|
||||
val storageFile = File(_filesDir, "${fileName}.json");
|
||||
|
|
|
@ -316,7 +316,7 @@ class SyncSocketSession {
|
|||
val appId = messageBuffer.int.toUInt()
|
||||
val pairingMessageLength = messageBuffer.int
|
||||
val pairingMessage = if (pairingMessageLength > 0) ByteArray(pairingMessageLength).also { messageBuffer.get(it) } else byteArrayOf()
|
||||
val mainLength = messageSize - 4 - 4 - pairingMessageLength
|
||||
val mainLength = messageBuffer.remaining()
|
||||
val mainMessage = ByteArray(mainLength).also { messageBuffer.get(it) }
|
||||
|
||||
var pairingCode: String? = null
|
||||
|
@ -333,7 +333,7 @@ class SyncSocketSession {
|
|||
responder.readMessage(mainMessage, 0, mainLength, plaintext, 0)
|
||||
val remoteKeyBytes = ByteArray(responder.remotePublicKey.publicKeyLength)
|
||||
responder.remotePublicKey.getPublicKey(remoteKeyBytes, 0)
|
||||
val remotePublicKey = Base64.getEncoder().encodeToString(remoteKeyBytes)
|
||||
val remotePublicKey = remoteKeyBytes.toBase64()
|
||||
|
||||
val isAllowedToConnect = remotePublicKey != _localPublicKey && (_isHandshakeAllowed?.invoke(LinkType.Direct, this, remotePublicKey, pairingCode, appId) ?: true)
|
||||
if (!isAllowedToConnect) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue