Skip to content

Commit b374d9f

Browse files
committed
Add End Session button
1 parent 02dfa8d commit b374d9f

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

web/frontend/src/lib/Console.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@
186186
};
187187
}
188188
189+
function endSession() {
190+
if (socket?.readyState === WebSocket.OPEN) {
191+
socket.send(JSON.stringify({ type: "CLOSE_SESSION" }));
192+
}
193+
}
194+
189195
function sendCommand(commandText: string) {
190196
if (socket?.readyState === WebSocket.OPEN) {
191197
virtualConsole.addLines([`\u001b[92m> ${commandText}\u001b[0m`]);
@@ -224,7 +230,7 @@
224230
</script>
225231

226232
<div id="console-container" class="h-full flex flex-col bg-gray-900 relative">
227-
<StatusPanel {socket} />
233+
<StatusPanel {socket} on:endsession={endSession} />
228234

229235
<div bind:this={outputContainer} class="flex-grow overflow-y-auto overflow-x-hidden p-4"></div>
230236
<div class="mt-auto p-4">
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script lang="ts">
2+
import { createEventDispatcher } from "svelte";
3+
4+
const dispatch = createEventDispatcher();
5+
6+
let confirming = false;
7+
8+
function confirm() {
9+
dispatch("endsession");
10+
confirming = false;
11+
}
12+
</script>
13+
14+
{#if confirming}
15+
<div class="flex items-center justify-between text-xs">
16+
<span class="text-gray-300">End session?</span>
17+
<div class="flex gap-2">
18+
<button on:click={confirm} class="text-red-400 hover:text-red-300 font-semibold transition-colors">Yes</button>
19+
<button on:click={() => confirming = false} class="text-gray-400 hover:text-gray-300 transition-colors">No</button>
20+
</div>
21+
</div>
22+
{:else}
23+
<button on:click={() => confirming = true} class="w-full text-xs text-center py-1.5 rounded-md bg-red-600/10 hover:bg-red-600/25 text-red-400/70 hover:text-red-300 border border-red-500/20 hover:border-red-500/30 transition-colors">
24+
End Session
25+
</button>
26+
{/if}

web/frontend/src/lib/StatusPanel.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import { sessionState, sessionMetadata, sessionTimer } from "./stores";
44
import SessionMetadata from "./SessionMetadata.svelte";
55
import TimeoutBar from "./TimeoutBar.svelte";
6+
import EndSessionButton from "./EndSessionButton.svelte";
7+
8+
import { createEventDispatcher } from "svelte";
9+
10+
const dispatch = createEventDispatcher();
611
712
export let socket: WebSocket | null;
813
@@ -108,6 +113,9 @@
108113
<div class="border-t border-gray-700 pt-3">
109114
<SessionMetadata />
110115
</div>
116+
{#if $sessionState === "active"}
117+
<EndSessionButton on:endsession={() => dispatch("endsession")} />
118+
{/if}
111119
</div>
112120
{/if}
113121
</div>

web/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ export class BaseSession extends Container<Env> {
251251
this.handleExtensionRequest();
252252
return;
253253
}
254+
if (message.type === "CLOSE_SESSION") {
255+
if (this.sessionState === "ACTIVE") {
256+
console.log("Browser requested session close");
257+
this.closeSession();
258+
}
259+
return;
260+
}
254261
if (this.containerSocket?.readyState === WebSocket.OPEN) {
255262
if (message.type === "SCRIPT") {
256263
const content = message.payload.content || "";

0 commit comments

Comments
 (0)