Skip to content

Commit

Permalink
add disconnect to file menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sproctor committed Jan 9, 2025
1 parent ebe7a1a commit df298c1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
13 changes: 8 additions & 5 deletions app/src/main/kotlin/warlockfe/warlock3/app/AppMenuBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ import javax.swing.JMenuBar
@Composable
fun FrameWindowScope.AppMenuBar(
characterId: String?,
isConnected: Boolean,
windowRepository: WindowRepository,
scriptEngineRegistry: ScriptManager,
runScript: (File) -> Unit,
newWindow: () -> Unit,
showSettings: () -> Unit,
showUpdateDialog: () -> Unit,
disconnect: (() -> Unit)?,
disconnect: () -> Unit,
warlockVersion: String,
) {
val windows by windowRepository.windows.collectAsState()
Expand Down Expand Up @@ -68,10 +69,12 @@ fun FrameWindowScope.AppMenuBar(
}
)
}
if (disconnect != null) {
HorizontalDivider()
Item("Disconnect", onClick = disconnect)
}
Separator()
Item(
text = "Disconnect",
enabled = isConnected,
onClick = disconnect,
)
}

if (characterId != null) {
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/kotlin/warlockfe/warlock3/app/WarlockApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ fun FrameWindowScope.WarlockApp(
}
AppMenuBar(
characterId = characterId,
isConnected =
(gameState.screen as? GameScreen.ConnectedGameState)?.viewModel?.client?.connected?.value == true,
windowRepository = gameState.windowRepository,
scriptEngineRegistry = appContainer.scriptManager,
newWindow = newWindow,
showSettings = { showSettings = true },
disconnect = null,
disconnect = {
val screen = gameState.screen
if (screen is GameScreen.ConnectedGameState) {
screen.viewModel.client.disconnect()
}
},
runScript = {
val screen = gameState.screen
if (screen is GameScreen.ConnectedGameState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface WarlockClient {

fun connect()

suspend fun disconnect()
fun disconnect()

suspend fun sendCommand(line: String): SendCommandType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,11 @@ class StormfrontClient(
SendCommandType.SCRIPT
}

override suspend fun disconnect() {
override fun disconnect() {
doDisconnect()
mainStream.appendLine(StyledString("Closed connection to server."))
scope.launch {
mainStream.appendLine(StyledString("Closed connection to server."))
}
}

private suspend fun disconnected() {
Expand Down

0 comments on commit df298c1

Please sign in to comment.