fix startup

This commit is contained in:
callebtc
2025-07-12 15:42:37 +02:00
parent 4545afb0c4
commit 035273011f
5 changed files with 325 additions and 82 deletions
@@ -19,13 +19,13 @@ import kotlin.random.Random
* Refactored ChatViewModel - Main coordinator for bitchat functionality
* Delegates specific responsibilities to specialized managers while maintaining 100% iOS compatibility
*/
class ChatViewModel(application: Application) : AndroidViewModel(application), BluetoothMeshDelegate {
class ChatViewModel(
application: Application,
val meshService: BluetoothMeshService
) : AndroidViewModel(application), BluetoothMeshDelegate {
private val context: Context = application.applicationContext
// Core services
val meshService = BluetoothMeshService(context)
// State management
private val state = ChatState()
@@ -72,7 +72,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), B
val favoritePeers: LiveData<Set<String>> = state.favoritePeers
init {
meshService.delegate = this
// Note: Mesh service delegate is now set by MainActivity
loadAndInitialize()
}
@@ -100,8 +100,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), B
state.setFavoritePeers(dataManager.favoritePeers)
dataManager.loadBlockedUsers()
// Start mesh service
meshService.startServices()
// Note: Mesh service is now started by MainActivity
// Show welcome message if no peers after delay
viewModelScope.launch {
@@ -120,7 +119,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), B
override fun onCleared() {
super.onCleared()
meshService.stopServices()
// Note: Mesh service lifecycle is now managed by MainActivity
}
// MARK: - Nickname Management
@@ -259,18 +258,10 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), B
return meshService.getDebugStatus()
}
fun restartMeshServices() {
viewModelScope.launch {
meshService.stopServices()
delay(1000)
meshService.startServices()
}
}
// Note: Mesh service restart is now handled by MainActivity
// This function is no longer needed
fun setAppBackgroundState(inBackground: Boolean) {
// Forward to connection manager for power optimization
meshService.connectionManager.setAppBackgroundState(inBackground)
// Forward to notification manager for notification logic
notificationManager.setAppBackgroundState(inBackground)
}
@@ -355,13 +346,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), B
state.setNickname(newNickname)
dataManager.saveNickname(newNickname)
// Disconnect from mesh
meshService.stopServices()
// Restart services with new identity
viewModelScope.launch {
delay(500)
meshService.startServices()
}
// Note: Mesh service restart is now handled by MainActivity
// This method now only clears data, not mesh service lifecycle
}
}