Skip to content

Commit e25c0cc

Browse files
authored
Pre-phrase signal (#10)
* Touch file hat snapshots * Add support for signals
1 parent 4c4174e commit e25c0cc

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Brandon Virgil Rule
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/extension.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
22

33
import { initializeCommunicationDir } from "./initializeCommunicationDir";
44
import CommandRunner from "./commandRunner";
5+
import { getInboundSignal } from "./signal";
56

67
export function activate(context: vscode.ExtensionContext) {
78
initializeCommunicationDir();
@@ -14,6 +15,20 @@ export function activate(context: vscode.ExtensionContext) {
1415
commandRunner.runCommand
1516
)
1617
);
18+
19+
return {
20+
/**
21+
* These signals can be used as a form of IPC to indicate that an event has
22+
* occurred.
23+
*/
24+
signals: {
25+
/**
26+
* This signal is emitted by the voice engine to indicate that a phrase has
27+
* just begun execution.
28+
*/
29+
prePhrase: getInboundSignal("prePhrase"),
30+
},
31+
};
1732
}
1833

1934
// this method is called when your extension is deactivated

src/paths.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export function getCommunicationDirPath() {
1111
return join(tmpdir(), `vscode-command-server${suffix}`);
1212
}
1313

14+
export function getSignalDirPath(): string {
15+
return join(getCommunicationDirPath(), "signals");
16+
}
17+
1418
export function getRequestPath() {
1519
return join(getCommunicationDirPath(), "request.json");
1620
}

src/signal.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { stat } from "fs/promises";
2+
import { join } from "path";
3+
import { getSignalDirPath } from "./paths";
4+
5+
class InboundSignal {
6+
constructor(private path: string) {}
7+
8+
/**
9+
* Gets the current version of the signal. This version string changes every
10+
* time the signal is emitted, and can be used to detect whether signal has
11+
* been emitted between two timepoints.
12+
* @returns The current signal version or null if the signal file could not be
13+
* found
14+
*/
15+
async getVersion() {
16+
try {
17+
return (await stat(this.path)).mtimeMs.toString();
18+
} catch (err) {
19+
if ((err as NodeJS.ErrnoException).code !== "ENOENT") {
20+
throw err;
21+
}
22+
23+
return null;
24+
}
25+
}
26+
}
27+
28+
export function getInboundSignal(name: string) {
29+
const signalDir = getSignalDirPath();
30+
const path = join(signalDir, name);
31+
32+
return new InboundSignal(path);
33+
}

0 commit comments

Comments
 (0)