From 2423618f1d572badba2bf0c3cf2a498dc18c0064 Mon Sep 17 00:00:00 2001 From: shmck Date: Sat, 30 Oct 2021 14:36:22 -0700 Subject: [PATCH] launch on codeally.json Signed-off-by: shmck --- package.json | 3 +- src/commands.ts | 40 +++++++++++--------- src/services/webview/{index.ts => create.ts} | 8 +++- web-app/.env.example | 2 +- 4 files changed, 33 insertions(+), 20 deletions(-) rename src/services/webview/{index.ts => create.ts} (90%) diff --git a/package.json b/package.json index d90a500e..8ca8493f 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,8 @@ "vscode": "^1.39.2" }, "activationEvents": [ - "onCommand:coderoad.start" + "onCommand:coderoad.start", + "workspaceContains:**/codeally.json" ], "categories": [ "Other" diff --git a/src/commands.ts b/src/commands.ts index c7ba69a5..63dba085 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -2,7 +2,7 @@ import * as T from 'typings' import * as TT from 'typings/tutorial' import * as vscode from 'vscode' import createTestRunner from './services/testRunner' -import createWebView from './services/webview' +import createWebView from './services/webview/create' import * as hooks from './services/hooks' import logger from './services/logger' import Channel from './channel' @@ -32,29 +32,35 @@ export const send = (action: T.Action): void => { if (action) sendToClient(action) } -export const createCommands = ({ extensionPath, workspaceState }: CreateCommandProps): { [key: string]: any } => { +export const createCommands = (commandProps: CreateCommandProps): { [key: string]: any } => { + console.log(commandProps) + const { extensionPath, workspaceState } = commandProps // React panel webview let webview: any let currentPosition: T.Position let testRunner: any const channel = new Channel(workspaceState) + const start = async () => { + if (webview && webview.state.loaded) { + webview.createOrShow() + } else { + // activate machine + webview = await createWebView({ + extensionPath, + channel, + }) + // make send to client function exportable + // as "send". + sendToClient = webview.send + } + } + + // run activation if triggered by "workspaceContains" + start() + return { - // initialize - [COMMANDS.START]: async () => { - if (webview && webview.state.loaded) { - webview.createOrShow() - } else { - // activate machine - webview = await createWebView({ - extensionPath, - channel, - }) - // make send to client function exportable - // as "send". - sendToClient = webview.send - } - }, + [COMMANDS.START]: start, [COMMANDS.CONFIG_TEST_RUNNER]: async ({ data, alreadyConfigured, diff --git a/src/services/webview/index.ts b/src/services/webview/create.ts similarity index 90% rename from src/services/webview/index.ts rename to src/services/webview/create.ts index 91e1484f..1db37e6a 100644 --- a/src/services/webview/index.ts +++ b/src/services/webview/create.ts @@ -18,6 +18,9 @@ interface Output { const state = { loaded: false } const createReactWebView = ({ extensionPath, channel }: ReactWebViewProps): Output => { + // throttle "already open" popup + let lastWebviewOpenedAt = new Date() + // TODO add disposables const disposables: vscode.Disposable[] = [] @@ -78,11 +81,14 @@ const createReactWebView = ({ extensionPath, channel }: ReactWebViewProps): Outp // Otherwise, create a new panel. if (panel && panel.webview) { - vscode.window.showInformationMessage('CodeRoad already open') + if (Date.now() - lastWebviewOpenedAt.getTime() > 5000) { + vscode.window.showInformationMessage('CodeRoad already open') + } panel.reveal(vscode.ViewColumn.Two) } else { panel = createWebViewPanel() } + lastWebviewOpenedAt = new Date() }, send, receive, diff --git a/web-app/.env.example b/web-app/.env.example index 56e84ffb..67fa581e 100644 --- a/web-app/.env.example +++ b/web-app/.env.example @@ -1,5 +1,5 @@ SKIP_PREFLIGHT_CHECK=true -VERSION=0.14.2 +VERSION=0.14.5 NODE_ENV=local REACT_APP_DEBUG=false REACT_APP_LOG=false