mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-03 14:50:49 +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.appcompat.app.AppCompatActivity
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.states.StateSync
|
import com.futo.platformplayer.states.StateSync
|
||||||
|
@ -29,6 +30,16 @@ class SyncHomeActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
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)
|
setContentView(R.layout.activity_sync_home)
|
||||||
setNavigationBarColorAndIcons()
|
setNavigationBarColorAndIcons()
|
||||||
|
|
||||||
|
|
|
@ -530,10 +530,17 @@ class StateApp {
|
||||||
|
|
||||||
//Migration
|
//Migration
|
||||||
Logger.i(TAG, "MainApp Started: Check [Migrations]");
|
Logger.i(TAG, "MainApp Started: Check [Migrations]");
|
||||||
|
|
||||||
|
scopeOrNull?.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
migrateStores(context, listOf(
|
migrateStores(context, listOf(
|
||||||
StateSubscriptions.instance.toMigrateCheck(),
|
StateSubscriptions.instance.toMigrateCheck(),
|
||||||
StatePlaylists.instance.toMigrateCheck()
|
StatePlaylists.instance.toMigrateCheck()
|
||||||
).flatten(), 0);
|
).flatten(), 0)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.e(TAG, "Failed to migrate stores")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(Settings.instance.subscriptions.fetchOnAppBoot) {
|
if(Settings.instance.subscriptions.fetchOnAppBoot) {
|
||||||
scope.launch(Dispatchers.IO) {
|
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)
|
if(managedStores.size <= index)
|
||||||
return;
|
return;
|
||||||
val store = managedStores[index];
|
val store = managedStores[index];
|
||||||
if(store.hasMissingReconstructions())
|
if(store.hasMissingReconstructions()) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
try {
|
||||||
UIDialogs.showMigrateDialog(context, store) {
|
UIDialogs.showMigrateDialog(context, store) {
|
||||||
|
scopeOrNull?.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
migrateStores(context, managedStores, index + 1);
|
migrateStores(context, managedStores, index + 1);
|
||||||
};
|
} catch (e: Throwable) {
|
||||||
else
|
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);
|
migrateStores(context, managedStores, index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -401,12 +401,15 @@ class StatePlaylists {
|
||||||
companion object {
|
companion object {
|
||||||
val TAG = "StatePlaylists";
|
val TAG = "StatePlaylists";
|
||||||
private var _instance : StatePlaylists? = null;
|
private var _instance : StatePlaylists? = null;
|
||||||
|
private var _lockObject = Object()
|
||||||
val instance : StatePlaylists
|
val instance : StatePlaylists
|
||||||
get() {
|
get() {
|
||||||
|
synchronized(_lockObject) {
|
||||||
if (_instance == null)
|
if (_instance == null)
|
||||||
_instance = StatePlaylists();
|
_instance = StatePlaylists();
|
||||||
return _instance!!;
|
return _instance!!;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun finish() {
|
fun finish() {
|
||||||
_instance?.let {
|
_instance?.let {
|
||||||
|
|
|
@ -57,6 +57,7 @@ import kotlinx.coroutines.withContext
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.net.ServerSocket
|
import java.net.ServerSocket
|
||||||
|
@ -438,7 +439,7 @@ class StateSync {
|
||||||
Logger.v(TAG, "Received ${connectionInfos.size} devices connection information")
|
Logger.v(TAG, "Received ${connectionInfos.size} devices connection information")
|
||||||
|
|
||||||
for ((targetKey, connectionInfo) in connectionInfos) {
|
for ((targetKey, connectionInfo) in connectionInfos) {
|
||||||
val potentialLocalAddresses = connectionInfo.ipv4Addresses.union(connectionInfo.ipv6Addresses)
|
val potentialLocalAddresses = connectionInfo.ipv4Addresses
|
||||||
.filter { it != connectionInfo.remoteIp }
|
.filter { it != connectionInfo.remoteIp }
|
||||||
if (connectionInfo.allowLocalDirect && Settings.instance.synchronization.connectLocalDirectThroughRelay) {
|
if (connectionInfo.allowLocalDirect && Settings.instance.synchronization.connectLocalDirectThroughRelay) {
|
||||||
Thread {
|
Thread {
|
||||||
|
|
|
@ -124,14 +124,9 @@ class FragmentedStorage {
|
||||||
return loadFile(storageFile, storageBakFile);
|
return loadFile(storageFile, storageBakFile);
|
||||||
}
|
}
|
||||||
inline fun <reified T> load(fileName: String): T where T : FragmentedStorageFile {
|
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) {
|
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");
|
val storageFile = File(_filesDir, "${fileName}.json");
|
||||||
val storageBakFile = File(_filesDir, "${fileName}.json.bak");
|
val storageBakFile = File(_filesDir, "${fileName}.json.bak");
|
||||||
|
|
|
@ -316,7 +316,7 @@ class SyncSocketSession {
|
||||||
val appId = messageBuffer.int.toUInt()
|
val appId = messageBuffer.int.toUInt()
|
||||||
val pairingMessageLength = messageBuffer.int
|
val pairingMessageLength = messageBuffer.int
|
||||||
val pairingMessage = if (pairingMessageLength > 0) ByteArray(pairingMessageLength).also { messageBuffer.get(it) } else byteArrayOf()
|
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) }
|
val mainMessage = ByteArray(mainLength).also { messageBuffer.get(it) }
|
||||||
|
|
||||||
var pairingCode: String? = null
|
var pairingCode: String? = null
|
||||||
|
@ -333,7 +333,7 @@ class SyncSocketSession {
|
||||||
responder.readMessage(mainMessage, 0, mainLength, plaintext, 0)
|
responder.readMessage(mainMessage, 0, mainLength, plaintext, 0)
|
||||||
val remoteKeyBytes = ByteArray(responder.remotePublicKey.publicKeyLength)
|
val remoteKeyBytes = ByteArray(responder.remotePublicKey.publicKeyLength)
|
||||||
responder.remotePublicKey.getPublicKey(remoteKeyBytes, 0)
|
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)
|
val isAllowedToConnect = remotePublicKey != _localPublicKey && (_isHandshakeAllowed?.invoke(LinkType.Direct, this, remotePublicKey, pairingCode, appId) ?: true)
|
||||||
if (!isAllowedToConnect) {
|
if (!isAllowedToConnect) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue