refactor: one runtime per process, owned by the process (notifications, Phase 2)
The database, repositories and the sync and notary engines move out of GizaNavHost's remember blocks into GizaRuntime, made by GizaApplication on Android, MainViewController on iOS and main() on desktop. Nothing changes about how they run; there is now one of each, and a process with no activity can reach them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be6e29b2c9
commit
1ac519059f
10 files changed
+299
-128
No files matched your search
@@ -8,6 +8,8 @@ import androidx.datastore.preferences.preferencesDataStore
|
||||
import fr.acinq.phoenix.PhoenixGlobal
|
||||
import fr.acinq.phoenix.utils.PlatformContext
|
||||
import fr.acinq.phoenix.utils.preferences.GlobalPrefs
|
||||
import mobi.giza.compose.GizaGlobal
|
||||
import mobi.giza.compose.GizaRuntime
|
||||
|
||||
/** This datastore persists preferences across node ids. */
|
||||
val Context.globalPrefs: DataStore<Preferences> by preferencesDataStore(name = "globalprefs")
|
||||
@@ -16,11 +18,29 @@ class GizaApplication: Application() {
|
||||
private lateinit var globalPrefs: GlobalPrefs
|
||||
private lateinit var phoenixGlobal: PhoenixGlobal
|
||||
|
||||
/**
|
||||
* The process's runtime. Here rather than in `MainActivity` because a process can start with
|
||||
* no activity -- a background sync, a notification's action -- and every one of those has to
|
||||
* find the same database and relay pool the screens use. Nothing in it starts until it is read.
|
||||
* docs/notifications-and-background-sync.md, D4.
|
||||
*/
|
||||
lateinit var runtime: GizaRuntime
|
||||
private set
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
phoenixGlobal = PhoenixGlobal(PlatformContext(applicationContext))
|
||||
globalPrefs = GlobalPrefs(applicationContext.globalPrefs)
|
||||
|
||||
runtime = GizaRuntime.getOrCreate {
|
||||
GizaRuntime(
|
||||
gizaGlobal = GizaGlobal(
|
||||
platformContext = mobi.giza.compose.PlatformContext(applicationContext = applicationContext)
|
||||
),
|
||||
phoenixGlobal = phoenixGlobal,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getGlobalPrefs(): GlobalPrefs {
|
||||
@@ -30,4 +50,4 @@ class GizaApplication: Application() {
|
||||
fun getPhoenixGlobal(): PhoenixGlobal {
|
||||
return phoenixGlobal
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,7 @@ import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import mobi.giza.compose.PlatformContext
|
||||
import mobi.giza.compose.GizaApp
|
||||
import mobi.giza.compose.GizaGlobal
|
||||
import fr.acinq.phoenix.PhoenixGlobal
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
@@ -16,22 +13,16 @@ class MainActivity : ComponentActivity() {
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// The application's runtime, not one of our own: an activity recreated over a living
|
||||
// process used to build a second set of repositories and a second PhoenixGlobal here.
|
||||
val runtime = (application as GizaApplication).runtime
|
||||
|
||||
setContent {
|
||||
val navController = rememberNavController()
|
||||
|
||||
GizaApp(
|
||||
navController = navController,
|
||||
gizaGlobal = GizaGlobal(
|
||||
platformContext = PlatformContext(
|
||||
applicationContext = applicationContext
|
||||
)
|
||||
),
|
||||
phoenixGlobal = PhoenixGlobal(
|
||||
ctx = fr.acinq.phoenix.utils.PlatformContext(
|
||||
applicationContext = applicationContext
|
||||
)
|
||||
)
|
||||
|
||||
runtime = runtime,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user