Compare commits
2 Commits
094499b8e9
...
cae2c1a9b1
| Author | SHA1 | Date | |
|---|---|---|---|
| cae2c1a9b1 | |||
| 3e67d6689d |
|
|
@ -1,5 +1,5 @@
|
||||||
////
|
////
|
||||||
// version: 1a97e37
|
// version: 3e67d66
|
||||||
|
|
||||||
// src/js/dom.ts
|
// src/js/dom.ts
|
||||||
var content2 = $("content");
|
var content2 = $("content");
|
||||||
|
|
@ -64,6 +64,11 @@ function initScrollback() {
|
||||||
function insert(node) {
|
function insert(node) {
|
||||||
scrollback.append(node);
|
scrollback.append(node);
|
||||||
}
|
}
|
||||||
|
function latestId() {
|
||||||
|
const nodes = document.querySelectorAll("[data-id]");
|
||||||
|
if (nodes.length)
|
||||||
|
return nodes[nodes.length - 1].dataset.id;
|
||||||
|
}
|
||||||
function addInput(id, input, status) {
|
function addInput(id, input, status) {
|
||||||
const parent = $$("li.input");
|
const parent = $$("li.input");
|
||||||
const statusSpan = $$(`span.status.${statusColors[status || "waiting"]}`, "•");
|
const statusSpan = $$(`span.status.${statusColors[status || "waiting"]}`, "•");
|
||||||
|
|
@ -342,6 +347,14 @@ function cacheApps(a) {
|
||||||
apps.sort();
|
apps.sort();
|
||||||
window.dispatchEvent(new CustomEvent("apps:change"));
|
window.dispatchEvent(new CustomEvent("apps:change"));
|
||||||
}
|
}
|
||||||
|
function currentAppUrl() {
|
||||||
|
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}`;
|
||||||
|
}
|
||||||
|
|
||||||
// src/js/session.ts
|
// src/js/session.ts
|
||||||
var sessionId = randomId();
|
var sessionId = randomId();
|
||||||
|
|
@ -820,7 +833,15 @@ function hideStatusMsg() {
|
||||||
// src/js/commands.ts
|
// src/js/commands.ts
|
||||||
var commands = [];
|
var commands = [];
|
||||||
var browserCommands = {
|
var browserCommands = {
|
||||||
browse: (url) => openBrowser(url, "command"),
|
browse: (url) => {
|
||||||
|
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: () => {
|
||||||
|
|
|
||||||
|
|
@ -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