From f5998495af9a42ff247c685b2a7ad8f7dd9592a7 Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Sun, 7 Nov 2021 17:05:45 +0000 Subject: [PATCH 1/2] Touch file hat snapshots --- src/extension.ts | 5 +++++ src/paths.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index 99466b0..0b72dad 100755 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,6 +2,7 @@ import * as vscode from "vscode"; import { initializeCommunicationDir } from "./initializeCommunicationDir"; import CommandRunner from "./commandRunner"; +import { getNamedSubdir } from "./paths"; export function activate(context: vscode.ExtensionContext) { initializeCommunicationDir(); @@ -14,6 +15,10 @@ export function activate(context: vscode.ExtensionContext) { commandRunner.runCommand ) ); + + return { + getNamedSubdir, + }; } // this method is called when your extension is deactivated diff --git a/src/paths.ts b/src/paths.ts index 2b5bdf2..36cd4f5 100644 --- a/src/paths.ts +++ b/src/paths.ts @@ -11,6 +11,10 @@ export function getCommunicationDirPath() { return join(tmpdir(), `vscode-command-server${suffix}`); } +export function getNamedSubdir(name: string): string { + return join(getCommunicationDirPath(), "namedSubdirs", name); +} + export function getRequestPath() { return join(getCommunicationDirPath(), "request.json"); } From 23740d0d16d0ab37d37f8cb5f84a78fe1b7e8027 Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Tue, 30 Nov 2021 13:01:23 +0000 Subject: [PATCH 2/2] Add support for signals --- LICENSE | 21 +++++++++++++++++++++ src/extension.ts | 14 ++++++++++++-- src/paths.ts | 4 ++-- src/signal.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 LICENSE create mode 100644 src/signal.ts diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ec2b623 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Brandon Virgil Rule + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/extension.ts b/src/extension.ts index 0b72dad..e218eac 100755 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,7 +2,7 @@ import * as vscode from "vscode"; import { initializeCommunicationDir } from "./initializeCommunicationDir"; import CommandRunner from "./commandRunner"; -import { getNamedSubdir } from "./paths"; +import { getInboundSignal } from "./signal"; export function activate(context: vscode.ExtensionContext) { initializeCommunicationDir(); @@ -17,7 +17,17 @@ export function activate(context: vscode.ExtensionContext) { ); return { - getNamedSubdir, + /** + * These signals can be used as a form of IPC to indicate that an event has + * occurred. + */ + signals: { + /** + * This signal is emitted by the voice engine to indicate that a phrase has + * just begun execution. + */ + prePhrase: getInboundSignal("prePhrase"), + }, }; } diff --git a/src/paths.ts b/src/paths.ts index 36cd4f5..237c110 100644 --- a/src/paths.ts +++ b/src/paths.ts @@ -11,8 +11,8 @@ export function getCommunicationDirPath() { return join(tmpdir(), `vscode-command-server${suffix}`); } -export function getNamedSubdir(name: string): string { - return join(getCommunicationDirPath(), "namedSubdirs", name); +export function getSignalDirPath(): string { + return join(getCommunicationDirPath(), "signals"); } export function getRequestPath() { diff --git a/src/signal.ts b/src/signal.ts new file mode 100644 index 0000000..02dd679 --- /dev/null +++ b/src/signal.ts @@ -0,0 +1,33 @@ +import { stat } from "fs/promises"; +import { join } from "path"; +import { getSignalDirPath } from "./paths"; + +class InboundSignal { + constructor(private path: string) {} + + /** + * Gets the current version of the signal. This version string changes every + * time the signal is emitted, and can be used to detect whether signal has + * been emitted between two timepoints. + * @returns The current signal version or null if the signal file could not be + * found + */ + async getVersion() { + try { + return (await stat(this.path)).mtimeMs.toString(); + } catch (err) { + if ((err as NodeJS.ErrnoException).code !== "ENOENT") { + throw err; + } + + return null; + } + } +} + +export function getInboundSignal(name: string) { + const signalDir = getSignalDirPath(); + const path = join(signalDir, name); + + return new InboundSignal(path); +}