Use localhost setting
This commit is contained in:
@@ -59,6 +59,11 @@
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Automatically start the server when vscode starts"
|
||||
},
|
||||
"devrun.useLocalhostServer": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Use localhost:3000 as the DevRun run submission server (for development usage)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-5
@@ -9,11 +9,18 @@ export function getCookies(): string | undefined {
|
||||
export function setCookies(c: string) {
|
||||
cookies = c;
|
||||
}
|
||||
function getOrigin(useLocalhost: boolean) {
|
||||
return useLocalhost ? "http://localhost:3000" : "https://dev-run.netlify.app";
|
||||
}
|
||||
|
||||
export async function addRun(problem: string, mode: string): Promise<string> {
|
||||
export async function addRun(
|
||||
useLocalhost: boolean,
|
||||
problem: string,
|
||||
mode: string,
|
||||
): Promise<string> {
|
||||
return (
|
||||
await axios.put(
|
||||
"http://localhost:3000/api/run",
|
||||
getOrigin(useLocalhost) + "/api/run",
|
||||
{
|
||||
problem,
|
||||
category: mode,
|
||||
@@ -27,9 +34,9 @@ export async function addRun(problem: string, mode: string): Promise<string> {
|
||||
).data.runId;
|
||||
}
|
||||
|
||||
export async function submitRun(runId: string) {
|
||||
export async function submitRun(useLocalhost: boolean, runId: string) {
|
||||
await axios.post(
|
||||
"http://localhost:3000/api/run",
|
||||
getOrigin(useLocalhost) + "/api/run",
|
||||
{
|
||||
runId,
|
||||
},
|
||||
@@ -42,13 +49,14 @@ export async function submitRun(runId: string) {
|
||||
}
|
||||
|
||||
export async function addRunMoves(
|
||||
useLocalhost: boolean,
|
||||
runId: string,
|
||||
file: string | null,
|
||||
language: string | null,
|
||||
moves: LiveRunMove[],
|
||||
) {
|
||||
await axios.post(
|
||||
"http://localhost:3000/api/run/move",
|
||||
getOrigin(useLocalhost) + "/api/run/move",
|
||||
{
|
||||
runId,
|
||||
file,
|
||||
|
||||
+10
-3
@@ -5,6 +5,8 @@ import os from "os";
|
||||
import { exec } from "child_process";
|
||||
import net from "net";
|
||||
|
||||
var globalStatusBarItem: vscode.StatusBarItem | undefined;
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
const config = vscode.workspace.getConfiguration("devrun");
|
||||
const statusBarItem = vscode.window.createStatusBarItem(
|
||||
@@ -12,13 +14,18 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
10,
|
||||
);
|
||||
|
||||
globalStatusBarItem = statusBarItem;
|
||||
|
||||
statusBarItem.text = "$(clock) No active run";
|
||||
statusBarItem.show();
|
||||
|
||||
const useLocalhost = config.get<boolean>("useLocalhostServer") || false;
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand(
|
||||
"devrun-vscode.startRun",
|
||||
async (problemId?: string) => startRun(statusBarItem, problemId),
|
||||
async (problemId?: string) =>
|
||||
startRun(useLocalhost, statusBarItem, problemId),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -34,7 +41,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
);
|
||||
|
||||
if (isStop === "Yes") {
|
||||
stopRun();
|
||||
stopRun(useLocalhost);
|
||||
statusBarItem.text = "$(clock) No active run";
|
||||
}
|
||||
}),
|
||||
@@ -95,7 +102,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
stopRun();
|
||||
stopServer(globalStatusBarItem as any);
|
||||
}
|
||||
|
||||
export function canConnect(
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ import { LiveRunMove } from "./types";
|
||||
import { addRunMoves } from "./client";
|
||||
import path from "path";
|
||||
|
||||
export function startMonitoring(runId: string) {
|
||||
export function startMonitoring(useLocalhost: boolean, runId: string) {
|
||||
const dmp = new diff_match_patch();
|
||||
|
||||
let moveId = 0;
|
||||
@@ -29,7 +29,7 @@ export function startMonitoring(runId: string) {
|
||||
moves = [];
|
||||
|
||||
try {
|
||||
await addRunMoves(runId, file, language, batch);
|
||||
await addRunMoves(useLocalhost, runId, file, language, batch);
|
||||
} finally {
|
||||
isSending = false;
|
||||
}
|
||||
|
||||
+5
-4
@@ -11,6 +11,7 @@ export var currentRun: {
|
||||
} | null = null;
|
||||
|
||||
export async function startRun(
|
||||
useLocalhost: boolean,
|
||||
statusBarItem: vscode.StatusBarItem,
|
||||
problemId?: string,
|
||||
) {
|
||||
@@ -40,7 +41,7 @@ export async function startRun(
|
||||
|
||||
if (!mode) return;
|
||||
|
||||
const runId = await addRun(problemId, mode);
|
||||
const runId = await addRun(useLocalhost, problemId, mode);
|
||||
|
||||
let start = Date.now();
|
||||
|
||||
@@ -48,7 +49,7 @@ export async function startRun(
|
||||
id: runId,
|
||||
problemId,
|
||||
start: new Date(),
|
||||
stopMonitoring: startMonitoring(runId),
|
||||
stopMonitoring: startMonitoring(useLocalhost, runId),
|
||||
interval: setInterval(() => {
|
||||
const elapsed = Date.now() - start;
|
||||
|
||||
@@ -65,10 +66,10 @@ export async function startRun(
|
||||
await vscode.commands.executeCommand("setContext", "devrun.runActive", true);
|
||||
}
|
||||
|
||||
export async function stopRun() {
|
||||
export async function stopRun(useLocalhost: boolean) {
|
||||
if (currentRun) {
|
||||
clearInterval(currentRun.interval);
|
||||
submitRun(currentRun.id);
|
||||
submitRun(useLocalhost, currentRun.id);
|
||||
|
||||
currentRun = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user