Skip to content

Commit

Permalink
fix for #591 (attempt)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 28, 2023
1 parent 87307b6 commit e4e2237
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
6 changes: 6 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
"description": "Listens for a jacdac-docs devtools server at localhost:8000",
"scope": "machine-overridable"
},
"devicescript.devtools.internet": {
"type": "boolean",
"default": false,
"description": "allows connections from non-localhost on developer server",
"scope": "machine-overridable"
},
"devicescript.connect.web": {
"type": "boolean",
"default": false,
Expand Down
10 changes: 10 additions & 0 deletions vscode/src/devtoolsserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ function normalizeUsedFiles(dir: vscode.Uri, usedFiles: string[]) {

const PROJECT_FOLDER_KEY = "devicescript.devtools.projectFolder"

export async function resolveDevtoolsPath(route?: string) {
const target = vscode.Uri.parse(`http://localhost:8081/${route || ""}`)
const external = await vscode.env.asExternalUri(target)
return external
}

export class DeveloperToolsManager extends JDEventSource {
private _connectionState: ConnectionState = ConnectionState.Disconnected
private _projectFolder: vscode.Uri
Expand Down Expand Up @@ -828,6 +834,7 @@ export class DeveloperToolsManager extends JDEventSource {
useShell?: boolean
diagnostics?: boolean
developerMode?: boolean
internet?: boolean
message?: string
args: string[]
}): Promise<vscode.Terminal> {
Expand Down Expand Up @@ -905,12 +912,15 @@ export class DeveloperToolsManager extends JDEventSource {
options.diagnostics ?? jacdacConfig.get("diagnostics")
const developerMode =
options.developerMode ?? devToolsConfig.get("developerMode")
const internet =
options.internet || !!devToolsConfig.get("internet")
let cli = nodePath || "node"
if (isWindows) {
cli = "node_modules\\.bin\\devicescript.cmd"
} else args.unshift("./node_modules/.bin/devicescript")
if (diagnostics) args.push("--diagnostics", "--verbose")
if (developerMode) args.push("--dev")
if (internet) args.push("--internet")
console.debug(
`create terminal: ${useShell ? "shell:" : ""}${
cwd.fsPath
Expand Down
5 changes: 2 additions & 3 deletions vscode/src/simulatorWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from "vscode"
import { JDEventSource } from "jacdac-ts"
import { DeviceScriptExtensionState } from "./state"
import { logo, resolveDarkMode } from "./assets"
import { resolveDevtoolsPath } from "./devtoolsserver"

class SimulatorsSerializer implements vscode.WebviewPanelSerializer {
constructor(readonly deserialize: (view: vscode.WebviewPanel) => void) {}
Expand Down Expand Up @@ -29,9 +30,7 @@ export class SimulatorsWebView extends JDEventSource {

private async generateSimulatorsHtml() {
const darkMode = resolveDarkMode()
const fullWebServerUri = await vscode.env.asExternalUri(
vscode.Uri.parse(`http://localhost:8081/`)
)
const fullWebServerUri = await resolveDevtoolsPath()
const cspSource = this.simulatorsWebviewPanel.webview.cspSource
const nonce = getNonce()

Expand Down
21 changes: 9 additions & 12 deletions vscode/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import type {
ServerInfo,
ServerInfoFile,
} from "@devicescript/interop"
import {
architectureFamily,
normalizeDeviceConfig,
parseAnyInt,
} from "@devicescript/interop"
import { normalizeDeviceConfig, parseAnyInt } from "@devicescript/interop"
import {
CHANGE,
ControlReg,
Expand Down Expand Up @@ -45,9 +41,9 @@ import {
TransportStatus,
} from "../../cli/src/sideprotocol"
import { openDocUri, showInformationMessageWithHelp } from "./commands"
import { CONNECTION_RESOURCE_GROUP, MESSAGE_PREFIX } from "./constants"
import { CONNECTION_RESOURCE_GROUP } from "./constants"
import { prepareForDeploy, readRuntimeVersion } from "./deploy"
import { DeveloperToolsManager } from "./devtoolsserver"
import { DeveloperToolsManager, resolveDevtoolsPath } from "./devtoolsserver"
import { checkFileExists, openFileEditor, writeFile } from "./fs"
import { sideRequest, subSideEvent } from "./jacdac"
import { JDomDeviceTreeItem } from "./JDomTreeDataProvider"
Expand Down Expand Up @@ -665,9 +661,11 @@ export class DeviceScriptExtensionState extends JDEventSource {

if (this.isRemote || !!config.get("web")) {
const darkMode = resolveDarkMode()
vscode.env.openExternal(
vscode.Uri.parse(`http://localhost:8081/connect?${darkMode}=1`)
const connectUri = await resolveDevtoolsPath(
`connect?${darkMode}=1`
)
console.log({ connectUri })
await vscode.env.openExternal(connectUri)
return
}

Expand Down Expand Up @@ -898,9 +896,8 @@ export class DeviceScriptExtensionState extends JDEventSource {
.register(ControlReg.DeviceDescription)
await description.refresh(true)

return `${description.stringValue || ""} (${
runtimeVersion || "?"
})`
return `${description.stringValue || ""} (${runtimeVersion || "?"
})`
}
const items: DeviceQuickItem[] = await Promise.all(
services.map(
Expand Down

0 comments on commit e4e2237

Please sign in to comment.