browse tweaks
This commit is contained in:
parent
094499b8e9
commit
3e67d6689d
|
|
@ -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: () => {
|
||||
|
|
|
|||
|
|
@ -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"]}`, "•")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
////
|
||||
// NOSE webapps
|
||||
|
||||
import { sessionStore } from "./session"
|
||||
|
||||
export const apps: string[] = []
|
||||
|
||||
export function cacheApps(a: string[]) {
|
||||
|
|
@ -10,3 +12,13 @@ export function cacheApps(a: string[]) {
|
|||
|
||||
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}`
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user