From 804c688a46dca3c05997dcc8382945dac52ebccf Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 24 Jul 2023 09:36:33 +0200 Subject: [PATCH] Fixes shell/fetch regression --- deno.jsonc | 6 ++++-- web/client.ts | 13 +++++++++++++ web/client_system.ts | 4 ++-- web/syscalls/fetch.ts | 10 +++++----- web/syscalls/shell.ts | 10 +++++----- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/deno.jsonc b/deno.jsonc index 4aea8e0f..de1cdadb 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -1,16 +1,18 @@ { "tasks": { "clean": "rm -rf dist dist_client_bundle dist_plug_bundle website_build", + "deep-clean-mac": "rm -f deno.lock && rm -rf $HOME/Library/Caches/deno && deno task clean", "install": "deno install -f -A --importmap import_map.json silverbullet.ts", "check": "find . -name '*.ts*' | xargs deno check", "test": "deno test -A --unstable", "build": "deno run -A build_plugs.ts && deno run -A --unstable build_web.ts", "plugs": "deno run -A build_plugs.ts", - "watch-web": "deno run -A --check build_web.ts --watch", "server": "deno run -A --check silverbullet.ts", + + "watch-web": "deno run -A --check build_web.ts --watch", "watch-server": "deno run -A --check --watch silverbullet.ts", - // The only reason to run a shell script is that deno task doesn't support globs yet (e.g. *.plug.yaml) "watch-plugs": "deno run -A --check build_plugs.ts -w", + "bundle": "deno run -A build_bundle.ts", // Regenerates some bundle files (checked into the repo) // Install lezer-generator with "npm install -g @lezer/generator" diff --git a/web/client.ts b/web/client.ts index 9bcc41d0..8cda30ce 100644 --- a/web/client.ts +++ b/web/client.ts @@ -562,6 +562,19 @@ export class Client { } focus() { + const viewState = this.ui.viewState; + if ( + [ + viewState.showCommandPalette, + viewState.showPageNavigator, + viewState.showFilterBox, + viewState.showConfirm, + viewState.showPrompt, + ].some(Boolean) + ) { + // Some other modal UI element is visible, don't focus editor now + return; + } this.editorView!.focus(); } diff --git a/web/client_system.ts b/web/client_system.ts index 1c30dcf9..4765c9bd 100644 --- a/web/client_system.ts +++ b/web/client_system.ts @@ -126,12 +126,12 @@ export class ClientSystem { // Syscalls that require some additional permissions this.system.registerSyscalls( ["fetch"], - sandboxFetchSyscalls(this.editor.remoteSpacePrimitives), + sandboxFetchSyscalls(this.editor), ); this.system.registerSyscalls( ["shell"], - shellSyscalls(this.editor.remoteSpacePrimitives), + shellSyscalls(this.editor), ); } diff --git a/web/syscalls/fetch.ts b/web/syscalls/fetch.ts index 2e690c34..b196333d 100644 --- a/web/syscalls/fetch.ts +++ b/web/syscalls/fetch.ts @@ -1,13 +1,13 @@ import type { SysCallMapping } from "../../plugos/system.ts"; -import type { HttpSpacePrimitives } from "../../common/spaces/http_space_primitives.ts"; import { performLocalFetch, ProxyFetchRequest, ProxyFetchResponse, } from "../../common/proxy_fetch.ts"; +import type { Client } from "../client.ts"; export function sandboxFetchSyscalls( - httpSpacePrimitives?: HttpSpacePrimitives, + client: Client, ): SysCallMapping { return { "sandboxFetch.fetch": async ( @@ -16,12 +16,12 @@ export function sandboxFetchSyscalls( options: ProxyFetchRequest, ): Promise => { // console.log("Got sandbox fetch ", url); - if (!httpSpacePrimitives) { + if (!client.remoteSpacePrimitives) { // No SB server to proxy the fetch available so let's execute the request directly return performLocalFetch(url, options); } - const resp = httpSpacePrimitives.authenticatedFetch( - `${httpSpacePrimitives.url}/.rpc`, + const resp = client.remoteSpacePrimitives.authenticatedFetch( + `${client.remoteSpacePrimitives.url}/.rpc`, { method: "POST", body: JSON.stringify({ diff --git a/web/syscalls/shell.ts b/web/syscalls/shell.ts index a7270c49..700c9dab 100644 --- a/web/syscalls/shell.ts +++ b/web/syscalls/shell.ts @@ -1,8 +1,8 @@ -import { HttpSpacePrimitives } from "../../common/spaces/http_space_primitives.ts"; import { SysCallMapping } from "../../plugos/system.ts"; +import type { Client } from "../client.ts"; export function shellSyscalls( - httpSpacePrimitives?: HttpSpacePrimitives, + client: Client, ): SysCallMapping { return { "shell.run": async ( @@ -10,11 +10,11 @@ export function shellSyscalls( cmd: string, args: string[], ): Promise<{ stdout: string; stderr: string; code: number }> => { - if (!httpSpacePrimitives) { + if (!client.remoteSpacePrimitives) { throw new Error("Not supported in fully local mode"); } - const resp = httpSpacePrimitives.authenticatedFetch( - `${httpSpacePrimitives.url}/.rpc`, + const resp = client.remoteSpacePrimitives.authenticatedFetch( + `${client.remoteSpacePrimitives.url}/.rpc`, { method: "POST", body: JSON.stringify({