Compare commits
No commits in common. "1a97e3721c4e5da664fe44041174b33d567262f3" and "b92b40d9f178ca312fac64b37e6e420061898589" have entirely different histories.
1a97e3721c
...
b92b40d9f1
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import { projects } from "@/project"
|
||||
import { sessionGet, sessionSet } from "@/session"
|
||||
import ls from "./ls"
|
||||
|
||||
export default function (project: string) {
|
||||
const state = sessionGet()
|
||||
|
|
@ -11,7 +10,6 @@ export default function (project: string) {
|
|||
if (state && projects().includes(project)) {
|
||||
sessionSet("project", project)
|
||||
sessionSet("cwd", "")
|
||||
return ls()
|
||||
} else {
|
||||
return { error: `failed to load ${project}` }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
|
||||
// Listen for navigation commands from parent
|
||||
window.addEventListener('message', (event) => {
|
||||
console.log(event)
|
||||
if (event.data.type === 'NAV_COMMAND') {
|
||||
switch (event.data.action) {
|
||||
case 'back': history.back(); break
|
||||
|
|
|
|||
|
|
@ -181,8 +181,7 @@
|
|||
display: none;
|
||||
}
|
||||
|
||||
#statusbar.showing-msg .line-cwd,
|
||||
#statusbar.showing-msg .line-www {
|
||||
#statusbar.showing-msg .line-cwd {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ export const Terminal: FC = async () => (
|
|||
|
||||
<div id="statusbar">
|
||||
<div class="line-cwd"><a href="#projects" id="project-name">root</a>: <a href="#ls" id="project-cwd">/</a></div>
|
||||
<div class="line-www"><a id="project-www" href="#">www</a></div>
|
||||
<div class="line-msg"><span id="statusbar-msg"></span></div>
|
||||
</div>
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import { focusInput } from "./focus"
|
|||
import { resize } from "./resize"
|
||||
import { sessionId } from "./session"
|
||||
import { send } from "./websocket"
|
||||
import { status } from "./statusbar"
|
||||
|
||||
export const commands: string[] = []
|
||||
|
||||
|
|
@ -31,7 +30,6 @@ export const browserCommands: Record<string, (...args: string[]) => void | Promi
|
|||
resize()
|
||||
focusInput()
|
||||
},
|
||||
status: (msg: string) => status(msg),
|
||||
reload: () => window.location.reload(),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
import type { Message } from "@/shared/types"
|
||||
import { cacheCommands } from "./commands"
|
||||
import { cacheApps } from "./webapp"
|
||||
import { handleOutput } from "./scrollback"
|
||||
import { handleStreamStart, handleStreamAppend, handleStreamReplace, handleStreamEnd } from "./stream"
|
||||
import { handleGameStart } from "./game"
|
||||
|
|
@ -15,9 +14,7 @@ export async function dispatchMessage(msg: Message) {
|
|||
case "output":
|
||||
handleOutput(msg); break
|
||||
case "commands":
|
||||
cacheCommands(msg.data); break
|
||||
case "apps":
|
||||
cacheApps(msg.data); break
|
||||
cacheCommands(msg.data as string[]); break
|
||||
case "error":
|
||||
console.error(msg.data); break
|
||||
case "stream:start":
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import { initHyperlink } from "./hyperlink"
|
|||
import { initInput } from "./input"
|
||||
import { initResize } from "./resize"
|
||||
import { initScrollback } from "./scrollback"
|
||||
import { initSession } from "./session"
|
||||
import { startVramCounter } from "./vram"
|
||||
import { startConnection } from "./websocket"
|
||||
|
||||
|
|
@ -26,7 +25,6 @@ initHyperlink()
|
|||
initInput()
|
||||
initResize()
|
||||
initScrollback()
|
||||
initSession()
|
||||
|
||||
startConnection()
|
||||
startVramCounter()
|
||||
|
|
@ -5,24 +5,15 @@
|
|||
import type { SessionStartMessage, SessionUpdateMessage } from "@/shared/types"
|
||||
import { browserCommands } from "./commands"
|
||||
import { randomId } from "../shared/utils"
|
||||
import { apps } from "./webapp"
|
||||
import { $ } from "./dom"
|
||||
|
||||
export const sessionId = randomId()
|
||||
export const projectName = $("project-name") as HTMLAnchorElement
|
||||
export const projectCwd = $("project-cwd") as HTMLAnchorElement
|
||||
export const projectWww = $("project-www") as HTMLAnchorElement
|
||||
export const sessionStore = new Map<string, string>()
|
||||
|
||||
export function initSession() {
|
||||
window.addEventListener("apps:change", e =>
|
||||
updateWww(sessionStore.get("project") || "root")
|
||||
)
|
||||
}
|
||||
|
||||
export function handleSessionStart(msg: SessionStartMessage) {
|
||||
sessionStore.set("NOSE_DIR", msg.data.NOSE_DIR)
|
||||
sessionStore.set("hostname", msg.data.hostname)
|
||||
updateProjectName(msg.data.project)
|
||||
updateCwd(msg.data.cwd)
|
||||
browserCommands.mode?.(msg.data.mode)
|
||||
|
|
@ -41,7 +32,6 @@ export function handleSessionUpdate(msg: SessionUpdateMessage) {
|
|||
function updateProjectName(project: string) {
|
||||
sessionStore.set("project", project)
|
||||
projectName.textContent = project
|
||||
updateWww(project)
|
||||
updateCwd("/")
|
||||
}
|
||||
|
||||
|
|
@ -51,18 +41,6 @@ function updateCwd(cwd: string) {
|
|||
projectCwd.textContent = cwd
|
||||
}
|
||||
|
||||
function updateWww(project: string) {
|
||||
if (!apps.includes(project)) {
|
||||
projectWww.style.display = "none"
|
||||
return
|
||||
}
|
||||
|
||||
projectWww.style.display = ""
|
||||
const hostname = sessionStore.get("hostname") || "localhost"
|
||||
const s = hostname.startsWith("localhost") ? "" : "s"
|
||||
projectWww.href = `http${s}://${project}.${hostname}`
|
||||
}
|
||||
|
||||
function displayProjectPath(path: string): string {
|
||||
let prefix = sessionStore.get("NOSE_DIR") || ""
|
||||
prefix += "/" + sessionStore.get("project")
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
////
|
||||
// NOSE webapps
|
||||
|
||||
export const apps: string[] = []
|
||||
|
||||
export function cacheApps(a: string[]) {
|
||||
apps.length = 0
|
||||
apps.unshift(...a)
|
||||
apps.sort()
|
||||
|
||||
window.dispatchEvent(new CustomEvent("apps:change"))
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import color from "kleur"
|
|||
import type { Message } from "./shared/types"
|
||||
import { NOSE_ICON, NOSE_BIN, NOSE_DATA, NOSE_DIR, NOSE_ROOT_BIN, DEFAULT_PROJECT } from "./config"
|
||||
import { transpile, isFile, tilde, isDir } from "./utils"
|
||||
import { serveApp, apps, initWebapps } from "./webapp"
|
||||
import { serveApp } from "./webapp"
|
||||
import { commands, commandPath, loadCommandModule } from "./commands"
|
||||
import { runCommandFn } from "./shell"
|
||||
import { send, addWebsocket, removeWebsocket, closeWebsockets } from "./websocket"
|
||||
|
|
@ -164,14 +164,11 @@ app.get("/", c => c.html(<Layout><Terminal /></Layout>))
|
|||
|
||||
app.get("/ws", c => {
|
||||
const _sessionId = c.req.query("session")
|
||||
const url = new URL(c.req.url)
|
||||
let hostname = url.hostname + (url.port === "80" ? "" : `:${url.port}`)
|
||||
|
||||
return upgradeWebSocket(c, {
|
||||
async onOpen(_e, ws) {
|
||||
addWebsocket(ws)
|
||||
send(ws, { type: "commands", data: await commands() })
|
||||
send(ws, { type: "apps", data: apps() })
|
||||
|
||||
send(ws, {
|
||||
type: "session:start",
|
||||
|
|
@ -179,8 +176,7 @@ app.get("/ws", c => {
|
|||
NOSE_DIR: NOSE_DIR,
|
||||
project: DEFAULT_PROJECT,
|
||||
cwd: "/",
|
||||
mode: getState("ui:mode") || "tall",
|
||||
hostname
|
||||
mode: getState("ui:mode") || "tall"
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
@ -246,7 +242,6 @@ console.log(color.blue("NOSE_ROOT_BIN:"), color.yellow(tilde(NOSE_ROOT_BIN)))
|
|||
|
||||
await initNoseDir()
|
||||
initCommands()
|
||||
initWebapps()
|
||||
initSneakers()
|
||||
|
||||
export default {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ export type Message =
|
|||
| GameStartMessage
|
||||
| StreamMessage
|
||||
| CommandsMessage
|
||||
| AppsMessage
|
||||
|
||||
export type CommandOutput = string | string[]
|
||||
| { text: string, script?: string }
|
||||
|
|
@ -31,11 +30,6 @@ export type CommandsMessage = {
|
|||
data: string[]
|
||||
}
|
||||
|
||||
export type AppsMessage = {
|
||||
type: "apps"
|
||||
data: string[]
|
||||
}
|
||||
|
||||
export type OutputMessage = {
|
||||
type: "output"
|
||||
id?: string
|
||||
|
|
@ -63,7 +57,6 @@ export type SessionStartMessage = {
|
|||
project: string
|
||||
cwd: string
|
||||
mode: string
|
||||
hostname: string
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,19 +5,14 @@ import type { Child } from "hono/jsx"
|
|||
import { type Context, Hono } from "hono"
|
||||
import { renderToString } from "hono/jsx/dom/server"
|
||||
import { join } from "path"
|
||||
import { readdirSync, watch } from "fs"
|
||||
import { sendAll } from "./websocket"
|
||||
import { expectDir } from "./utils"
|
||||
import { readdirSync } from "fs"
|
||||
|
||||
import { NOSE_DIR } from "./config"
|
||||
import { isFile, isDir } from "./utils"
|
||||
|
||||
export type Handler = (r: Context) => string | Child | Response | Promise<Response>
|
||||
export type App = Hono | Handler
|
||||
|
||||
export function initWebapps() {
|
||||
startWatcher()
|
||||
}
|
||||
|
||||
export async function serveApp(c: Context, subdomain: string): Promise<Response> {
|
||||
const app = await findApp(subdomain)
|
||||
const path = appDir(subdomain)
|
||||
|
|
@ -98,16 +93,4 @@ function serveStatic(path: string): Response {
|
|||
"Content-Type": file.type
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let wwwWatcher
|
||||
function startWatcher() {
|
||||
if (!expectDir(NOSE_DIR)) return
|
||||
|
||||
wwwWatcher = watch(NOSE_DIR, { recursive: true }, async (event, filename) => {
|
||||
if (!filename) return
|
||||
|
||||
if (/^.+\/index\.tsx?$/.test(filename))
|
||||
sendAll({ type: "apps", data: apps() })
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user