browse tweaks

This commit is contained in:
Chris Wanstrath 2025-10-06 22:13:13 -07:00
parent 094499b8e9
commit 3e67d6689d
3 changed files with 29 additions and 1 deletions

View File

@ -9,11 +9,21 @@ import { resize } from "./resize"
import { sessionId } from "./session"
import { send } from "./websocket"
import { status } from "./statusbar"
import { setStatus, latestId } from "./scrollback"
import { currentAppUrl } from "./webapp"
export const commands: string[] = []
export const browserCommands: Record<string, (...args: string[]) => void | Promise<void> | CommandOutput> = {
browse: (url: string) => openBrowser(url, "command"),
browse: (url?: string) => {
const currentUrl = url ?? currentAppUrl()
if (currentUrl) {
openBrowser(currentUrl, "command")
} else {
setTimeout(() => setStatus(latestId()!, "error"), 0)
return "usage: browse <url>"
}
},
"browser-session": () => sessionId,
clear: () => scrollback.innerHTML = "",
commands: () => {

View File

@ -22,6 +22,12 @@ export function insert(node: HTMLElement) {
scrollback.append(node)
}
export function latestId(): string | undefined {
const nodes = document.querySelectorAll("[data-id]")
if (nodes.length)
return (nodes[nodes.length - 1] as HTMLElement).dataset.id
}
export function addInput(id: string, input: string, status?: InputStatus) {
const parent = $$("li.input")
const statusSpan = $$(`span.status.${statusColors[status || "waiting"]}`, "•")

View File

@ -1,6 +1,8 @@
////
// NOSE webapps
import { sessionStore } from "./session"
export const apps: string[] = []
export function cacheApps(a: string[]) {
@ -9,4 +11,14 @@ export function cacheApps(a: string[]) {
apps.sort()
window.dispatchEvent(new CustomEvent("apps:change"))
}
export function currentAppUrl(): string | undefined {
const project = sessionStore.get("project") || "root"
if (!apps.includes(project)) return
const hostname = sessionStore.get("hostname") || "localhost"
const s = hostname.startsWith("localhost") ? "" : "s"
return `http${s}://${project}.${hostname}`
}