Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
Expand All @@ -24,12 +26,12 @@ import dev.zacsweers.metro.createGraph
import kotlinx.coroutines.launch
import java.awt.Desktop
import java.net.URI
import java.util.UUID

fun main() {
configurePlatformAppearance()
val appGraph = createGraph<AppGraph>()
application {
val windowState = rememberPersistedWindowState()
val windows = remember { mutableStateListOf(createInspectorWindow()) }
val updateController = remember {
UpdateController(
checker = UpdateChecker(),
Expand All @@ -47,21 +49,40 @@ fun main() {
AutoCheckDecision.Disabled -> Unit
}
}
Window(
onCloseRequest = ::exitApplication,
title = "Snap-O Network Inspector",
state = windowState,
) {
SnapOMenuBar(
controller = updateController,
onCheckForUpdates = {
scope.launch {
updateController.checkForUpdates(UpdateCheckSource.Manual)
}
},
onCloseRequest = ::exitApplication,
)
App(appGraph)

fun openNewWindow() {
windows.add(createInspectorWindow())
}

fun closeWindow(window: InspectorWindow) {
window.graph.store.stop()
windows.remove(window)
if (windows.isEmpty()) {
exitApplication()
}
}

windows.forEach { window ->
key(window.id) {
val windowState = rememberPersistedWindowState()
Window(
Comment on lines +66 to +68

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Give each window its own persisted state

rememberPersistedWindowState() reads/writes a single preference node (WindowPreferences.kt uses a fixed WindowPrefNode), so every new window loads the exact same position/size. With multi-window support, this means “New Window” opens directly on top of the existing window (often appearing like nothing happened) and resizing/moving one window overwrites the persisted state for all others. This is user-visible whenever more than one window is open; consider using a per-window key or offsetting new windows to avoid overlap.

Useful? React with 👍 / 👎.

onCloseRequest = { closeWindow(window) },
title = "Snap-O Network Inspector",
state = windowState,
) {
SnapOMenuBar(
controller = updateController,
onNewWindow = ::openNewWindow,
onCheckForUpdates = {
scope.launch {
updateController.checkForUpdates(UpdateCheckSource.Manual)
}
},
onCloseRequest = { closeWindow(window) },
)
App(window.graph)
}
}
}
}
}
Expand Down Expand Up @@ -93,3 +114,12 @@ private fun openSnapOUpdate() {
}
}
}

private data class InspectorWindow(
val id: String = UUID.randomUUID().toString(),
val graph: AppGraph,
)

private fun createInspectorWindow(): InspectorWindow {
return InspectorWindow(graph = createGraph<AppGraph>())
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.zacsweers.metro.SingleIn
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand Down Expand Up @@ -73,6 +74,11 @@ class NetworkInspectorStore(
}
}

fun stop() {
service.stop()
scope.cancel()
}

fun notifyFeatureOpened(feature: String, serverId: SnapOLinkServerId?) {
service.sendFeatureOpened(feature, serverId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import androidx.compose.ui.window.MenuBar
@Composable
internal fun FrameWindowScope.SnapOMenuBar(
controller: UpdateController,
onNewWindow: () -> Unit,
onCheckForUpdates: () -> Unit,
onCloseRequest: () -> Unit,
) {
MenuBar {
Menu("File") {
Item(
text = "New Window",
shortcut = KeyShortcut(Key.N, meta = true),
onClick = onNewWindow,
)
Item(
text = "Close",
shortcut = KeyShortcut(Key.W, meta = true),
Expand Down