Offlin33er commited on
Commit
4a794be
·
verified ·
1 Parent(s): b967b78

M1: tray integration, session restore, VIEW intents, persist on stop

Browse files
app/src/main/java/dev/nova/browser/BrowserActivity.kt CHANGED
@@ -1,5 +1,6 @@
1
  package dev.nova.browser
2
 
 
3
  import android.os.Bundle
4
  import android.util.Log
5
  import androidx.activity.ComponentActivity
@@ -37,7 +38,7 @@ class BrowserActivity : ComponentActivity() {
37
  // GeckoRuntimeSettings.setRemoteDebuggingEnabled(boolean).
38
  runtime!!.settings.setRemoteDebuggingEnabled(true)
39
  }
40
- tabManager = TabManager(runtime!!)
41
 
42
  installDevConsoleExtension()
43
 
@@ -55,7 +56,24 @@ class BrowserActivity : ComponentActivity() {
55
 
56
  setContent { NovaUI() }
57
 
58
- tabManager.open("https://example.com")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  }
60
 
61
  /**
@@ -90,11 +108,12 @@ class BrowserActivity : ComponentActivity() {
90
  }
91
 
92
  // ------------------------------------------------------------------
93
- // UI (Compose shell — M0 scope; toolbar/tabs polish are later milestones)
94
  // ------------------------------------------------------------------
95
  @Composable
96
  private fun NovaUI() {
97
  var urlInput by remember { mutableStateOf("https://example.com") }
 
98
  val geckoView = remember { GeckoView(this) }
99
  val activeId by tabManager.activeTabId
100
  val canGoBack by remember {
@@ -106,6 +125,21 @@ class BrowserActivity : ComponentActivity() {
106
  val id = activeId ?: return@LaunchedEffect
107
  val tab = tabManager.tabs.firstOrNull { t -> t.id == id } ?: return@LaunchedEffect
108
  geckoView.setSession(tab.session)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  }
110
 
111
  Column(Modifier.fillMaxSize()) {
@@ -125,6 +159,7 @@ class BrowserActivity : ComponentActivity() {
125
  TextButton(onClick = { tabManager.activeSession()?.reload() }) { Text("⟳") }
126
  TextButton(onClick = { tabManager.activeSession()?.loadUri(normalize(urlInput)) }) { Text("Go") }
127
  TextButton(onClick = { tabManager.open("about:blank") }) { Text("+") }
 
128
  }
129
 
130
  // Tab strip
 
1
  package dev.nova.browser
2
 
3
+ import android.content.Intent
4
  import android.os.Bundle
5
  import android.util.Log
6
  import androidx.activity.ComponentActivity
 
38
  // GeckoRuntimeSettings.setRemoteDebuggingEnabled(boolean).
39
  runtime!!.settings.setRemoteDebuggingEnabled(true)
40
  }
41
+ tabManager = TabManager(runtime!!, this)
42
 
43
  installDevConsoleExtension()
44
 
 
56
 
57
  setContent { NovaUI() }
58
 
59
+ // Cold start: restore persisted tabs; a VIEW intent takes priority as
60
+ // an additional new tab.
61
+ val restored = tabManager.restoreSession()
62
+ val launchUrl = intent?.data?.toString()
63
+ when {
64
+ launchUrl != null -> tabManager.open(launchUrl)
65
+ restored == 0 -> tabManager.open("https://example.com")
66
+ }
67
+ }
68
+
69
+ override fun onNewIntent(intent: Intent) {
70
+ super.onNewIntent(intent)
71
+ intent.data?.let { tabManager.open(it.toString()) }
72
+ }
73
+
74
+ override fun onStop() {
75
+ super.onStop()
76
+ tabManager.persistSession()
77
  }
78
 
79
  /**
 
108
  }
109
 
110
  // ------------------------------------------------------------------
111
+ // UI (M1: shell + tab tray; toolbar polish remains an M2 milestone)
112
  // ------------------------------------------------------------------
113
  @Composable
114
  private fun NovaUI() {
115
  var urlInput by remember { mutableStateOf("https://example.com") }
116
+ var trayOpen by remember { mutableStateOf(false) }
117
  val geckoView = remember { GeckoView(this) }
118
  val activeId by tabManager.activeTabId
119
  val canGoBack by remember {
 
125
  val id = activeId ?: return@LaunchedEffect
126
  val tab = tabManager.tabs.firstOrNull { t -> t.id == id } ?: return@LaunchedEffect
127
  geckoView.setSession(tab.session)
128
+ // Sync the URL bar with the tab we just activated.
129
+ tabManager.lastUrls[id]?.let { urlInput = it }
130
+ }
131
+
132
+ if (trayOpen) {
133
+ TabTray(
134
+ tabs = tabManager.tabs.toList(),
135
+ activeId = activeId,
136
+ lastUrls = tabManager.lastUrls,
137
+ onActivate = { tabManager.activate(it) },
138
+ onClose = { tabManager.close(it) },
139
+ onNewTab = { tabManager.open("about:blank") },
140
+ onDismiss = { trayOpen = false },
141
+ )
142
+ return
143
  }
144
 
145
  Column(Modifier.fillMaxSize()) {
 
159
  TextButton(onClick = { tabManager.activeSession()?.reload() }) { Text("⟳") }
160
  TextButton(onClick = { tabManager.activeSession()?.loadUri(normalize(urlInput)) }) { Text("Go") }
161
  TextButton(onClick = { tabManager.open("about:blank") }) { Text("+") }
162
+ TextButton(onClick = { trayOpen = true }) { Text("Tabs ${tabManager.tabs.size}") }
163
  }
164
 
165
  // Tab strip