diff --git a/manager/src/main/kotlin/roro/stellar/manager/db/AppDatabase.kt b/manager/src/main/kotlin/roro/stellar/manager/db/AppDatabase.kt index a2bb775..701030e 100644 --- a/manager/src/main/kotlin/roro/stellar/manager/db/AppDatabase.kt +++ b/manager/src/main/kotlin/roro/stellar/manager/db/AppDatabase.kt @@ -15,9 +15,13 @@ abstract class AppDatabase : RoomDatabase() { @Volatile private var instance: AppDatabase? = null fun get(context: Context): AppDatabase = instance ?: synchronized(this) { - instance ?: Room.databaseBuilder(context, AppDatabase::class.java, "stellar.db") + val deviceContext = context.applicationContext.createDeviceProtectedStorageContext() + runCatching { deviceContext.moveDatabaseFrom(context.applicationContext, DATABASE_NAME) } + instance ?: Room.databaseBuilder(deviceContext, AppDatabase::class.java, DATABASE_NAME) .fallbackToDestructiveMigration() .build().also { instance = it } } + + private const val DATABASE_NAME = "stellar.db" } } diff --git a/server/src/main/kotlin/roro/stellar/server/ConfigManager.kt b/server/src/main/kotlin/roro/stellar/server/ConfigManager.kt index 5ff9792..2526588 100644 --- a/server/src/main/kotlin/roro/stellar/server/ConfigManager.kt +++ b/server/src/main/kotlin/roro/stellar/server/ConfigManager.kt @@ -342,7 +342,11 @@ class ConfigManager { fun loadFromManagerWithStatus(): Pair { return try { val reply = callProvider("loadConfig", null) - val json = reply?.getString("configJson") + if (reply == null) { + LOGGER.w("从 manager 加载配置失败: 返回 null,使用默认值并跳过初始化写入") + return Pair(StellarConfig(), false) + } + val json = reply.getString("configJson") if (json != null) { val config = GSON_IN.fromJson(json, StellarConfig::class.java) ?: StellarConfig() Pair(config, true)