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