mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: Implement iOS support and unify Compose Multiplatform infrastructure (#4876)
This commit is contained in:
parent
f04924ded5
commit
d136b162a4
170 changed files with 2208 additions and 2432 deletions
|
|
@ -24,7 +24,7 @@ import androidx.room3.RoomDatabase
|
|||
import androidx.room3.TypeConverters
|
||||
import androidx.room3.migration.AutoMigrationSpec
|
||||
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import org.meshtastic.core.common.util.ioDispatcher
|
||||
import org.meshtastic.core.database.dao.DeviceHardwareDao
|
||||
import org.meshtastic.core.database.dao.FirmwareReleaseDao
|
||||
import org.meshtastic.core.database.dao.MeshLogDao
|
||||
|
|
@ -122,14 +122,15 @@ abstract class MeshtasticDatabase : RoomDatabase() {
|
|||
fun <T : RoomDatabase> RoomDatabase.Builder<T>.configureCommon(): RoomDatabase.Builder<T> =
|
||||
this.fallbackToDestructiveMigration(dropAllTables = false)
|
||||
.setDriver(BundledSQLiteDriver())
|
||||
.setQueryCoroutineContext(Dispatchers.IO)
|
||||
.setQueryCoroutineContext(ioDispatcher)
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteTable.Entries(DeleteTable(tableName = "NodeInfo"), DeleteTable(tableName = "MyNodeInfo"))
|
||||
@DeleteTable(tableName = "NodeInfo")
|
||||
@DeleteTable(tableName = "MyNodeInfo")
|
||||
class AutoMigration12to13 : AutoMigrationSpec
|
||||
|
||||
@DeleteColumn.Entries(DeleteColumn(tableName = "packet", columnName = "reply_id"))
|
||||
@DeleteColumn(tableName = "packet", columnName = "reply_id")
|
||||
class AutoMigration29to30 : AutoMigrationSpec
|
||||
|
||||
@DeleteColumn(tableName = "packet", columnName = "retry_count")
|
||||
|
|
|
|||
|
|
@ -17,11 +17,16 @@
|
|||
package org.meshtastic.core.database
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
|
||||
import androidx.datastore.core.DataStoreFactory
|
||||
import androidx.datastore.core.okio.OkioSerializer
|
||||
import androidx.datastore.core.okio.OkioStorage
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.emptyPreferences
|
||||
import androidx.room3.Room
|
||||
import androidx.room3.RoomDatabase
|
||||
import kotlinx.cinterop.ExperimentalForeignApi
|
||||
import okio.BufferedSink
|
||||
import okio.BufferedSource
|
||||
import okio.FileSystem
|
||||
import okio.Path
|
||||
import okio.Path.Companion.toPath
|
||||
|
|
@ -55,11 +60,32 @@ actual fun deleteDatabase(dbName: String) {
|
|||
/** Returns the system FileSystem for iOS. */
|
||||
actual fun getFileSystem(): FileSystem = FileSystem.SYSTEM
|
||||
|
||||
private object PreferencesSerializer : OkioSerializer<Preferences> {
|
||||
override val defaultValue: Preferences
|
||||
get() = emptyPreferences()
|
||||
|
||||
override suspend fun readFrom(source: BufferedSource): Preferences {
|
||||
// iOS stub: return an empty Preferences instance instead of crashing.
|
||||
return emptyPreferences()
|
||||
}
|
||||
|
||||
override suspend fun writeTo(t: Preferences, sink: BufferedSink) {
|
||||
// iOS stub: no-op to avoid crashing on write.
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates an iOS DataStore for database preferences. */
|
||||
actual fun createDatabaseDataStore(name: String): DataStore<Preferences> {
|
||||
val dir = documentDirectory() + "/datastore"
|
||||
NSFileManager.defaultManager.createDirectoryAtPath(dir, true, null, null)
|
||||
return PreferenceDataStoreFactory.create(produceFile = { (dir + "/$name.preferences_pb").toPath().toNioPath() })
|
||||
return DataStoreFactory.create(
|
||||
storage =
|
||||
OkioStorage(
|
||||
fileSystem = FileSystem.SYSTEM,
|
||||
serializer = PreferencesSerializer,
|
||||
producePath = { (dir + "/$name.preferences_pb").toPath() },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalForeignApi::class)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue