browse tweaks
This commit is contained in:
parent
094499b8e9
commit
3e67d6689d
|
|
@ -9,11 +9,21 @@ import { resize } from "./resize"
|
||||||
import { sessionId } from "./session"
|
import { sessionId } from "./session"
|
||||||
import { send } from "./websocket"
|
import { send } from "./websocket"
|
||||||
import { status } from "./statusbar"
|
import { status } from "./statusbar"
|
||||||
|
import { setStatus, latestId } from "./scrollback"
|
||||||
|
import { currentAppUrl } from "./webapp"
|
||||||
|
|
||||||
export const commands: string[] = []
|
export const commands: string[] = []
|
||||||
|
|
||||||
export const browserCommands: Record<string, (...args: string[]) => void | Promise<void> | CommandOutput> = {
|
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,
|
"browser-session": () => sessionId,
|
||||||
clear: () => scrollback.innerHTML = "",
|
clear: () => scrollback.innerHTML = "",
|
||||||
commands: () => {
|
commands: () => {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,12 @@ export function insert(node: HTMLElement) {
|
||||||
scrollback.append(node)
|
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) {
|
export function addInput(id: string, input: string, status?: InputStatus) {
|
||||||
const parent = $$("li.input")
|
const parent = $$("li.input")
|
||||||
const statusSpan = $$(`span.status.${statusColors[status || "waiting"]}`, "•")
|
const statusSpan = $$(`span.status.${statusColors[status || "waiting"]}`, "•")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
////
|
////
|
||||||
// NOSE webapps
|
// NOSE webapps
|
||||||
|
|
||||||
|
import { sessionStore } from "./session"
|
||||||
|
|
||||||
export const apps: string[] = []
|
export const apps: string[] = []
|
||||||
|
|
||||||
export function cacheApps(a: string[]) {
|
export function cacheApps(a: string[]) {
|
||||||
|
|
@ -9,4 +11,14 @@ export function cacheApps(a: string[]) {
|
||||||
apps.sort()
|
apps.sort()
|
||||||
|
|
||||||
window.dispatchEvent(new CustomEvent("apps:change"))
|
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