Refactors code.

This commit is contained in:
Henning Dieterichs
2019-08-12 10:48:33 +02:00
parent 9f833ffa4a
commit df6a8a8a22
8 changed files with 114 additions and 105 deletions

View File

@@ -17,7 +17,7 @@ export class Config {
);
}
public useChromeKioskModeKey(): boolean {
public useChromeKioskMode(): boolean {
const c = workspace.getConfiguration();
const b = c.get<boolean>(useChromeKioskModeKey);
if (b === undefined) {

View File

@@ -4,9 +4,11 @@ import { ConsoleRpcLogger } from "@hediet/typed-json-rpc";
import { EvaluationWatcher } from "./DataSource/DataSource";
import { WebSocketStream } from "@hediet/typed-json-rpc-websocket";
import { observable, autorun } from "mobx";
import { Sources } from "./extension";
import { Sources } from "./DataSource";
import { Server } from "./Server";
import * as open from "open";
import chromeLauncher = require("chrome-launcher");
import { Config } from "./Config";
export class ConnectionHandler {
public readonly dispose = Disposable.fn();
@@ -49,7 +51,7 @@ export class ConnectionHandler {
},
openInBrowser: async ({}) => {
let opened = false;
if (config.useChromeKioskModeKey()) {
if (config.useChromeKioskMode()) {
opened = await launchChrome(server.indexUrl);
}
if (!opened) {
@@ -91,12 +93,9 @@ export class ConnectionHandler {
}
}
import chromeLauncher = require("chrome-launcher");
import { Config } from "./Config";
async function launchChrome(url: string): Promise<boolean> {
try {
const chrome = await chromeLauncher.launch({
const _chrome = await chromeLauncher.launch({
startingUrl: url,
// `--window-size=${width},${height}`
chromeFlags: ["--app=" + url],

View File

@@ -0,0 +1,5 @@
import { createJsDebuggerSource } from "./JsDebuggerSource";
export class Sources {
public readonly jsSource = createJsDebuggerSource();
}

View File

@@ -3,7 +3,7 @@ import { AddressInfo } from "net";
import WebSocket = require("ws");
import { join } from "path";
import { ConnectionHandler } from "./ConnectionHandler";
import { Sources } from "./extension";
import { Sources } from "./DataSource";
import * as express from "express";
import * as http from "http";
import * as serveStatic from "serve-static";
@@ -14,7 +14,8 @@ export class Server {
constructor(sources: Sources, config: Config) {
const app = express();
app.use(serveStatic(join(__dirname, "../ui/dist")));
const distPath = join(__dirname, "../ui/dist");
app.use(serveStatic(distPath));
this.server = app.listen();
@@ -23,7 +24,6 @@ export class Server {
const stream = new WebSocketStream(ws);
new ConnectionHandler(sources, stream, this, config);
});
console.log(this.port);
}
public get indexUrl(): string {

View File

@@ -1,4 +1,5 @@
import { window, ExtensionContext, WebviewPanel, commands } from "vscode";
import { Disposable } from "@hediet/std/disposable";
import {
enableHotReload,
hotRequireExportedFn,
@@ -10,20 +11,13 @@ if (process.env.USE_DEV_UI) {
enableHotReload({ entryModule: module, loggingEnabled: true });
}
import { Disposable } from "@hediet/std/disposable";
import { createJsDebuggerSource } from "./DataSource/JsDebuggerSource";
import { WebViews } from "./WebViews";
import { Server } from "./Server";
import { Config } from "./Config";
import { Sources } from "./DataSource";
registerUpdateReconciler(module);
export class Sources {
public readonly jsSource = createJsDebuggerSource();
}
export class Extension {
public dispose = Disposable.fn();
@@ -39,11 +33,13 @@ export class Extension {
i.show();
}
commands.registerCommand(
"vscode-debug-visualizer.new-visualizer",
() => {
this.views.createNew();
}
this.dispose.track(
commands.registerCommand(
"vscode-debug-visualizer.new-visualizer",
() => {
this.views.createNew();
}
)
);
}
}