blob: 0cfa787d1c19add9483e82a62db9d71b214a9271 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
import * as vscode from 'vscode';
import * as buttplug from 'buttplug';
let selected_device: buttplug.ButtplugClientDevice | null = null;
let timeout: NodeJS.Timeout | null = null;
let config: vscode.WorkspaceConfiguration | null = null;
let building = false;
const client: buttplug.ButtplugClient = new buttplug.ButtplugClient("VS Code");
async function connect() {
const connector = new buttplug.ButtplugNodeWebsocketClientConnector(config!.get('serverAddress') as string);
if (client.connected) {
await client.stopAllDevices();
await client.disconnect();
}
try {
await client.connect(connector);
vscode.window.showInformationMessage("Connected to buttplug server.");
} catch (e) {
vscode.window.showErrorMessage(`Failed to connect to buttplug server: ${e}`);
}
}
export async function activate(context: vscode.ExtensionContext) {
client.addListener("deviceadded", async (device: buttplug.ButtplugClientDevice) => {
vscode.window.showInformationMessage(`Device Connected: ${device.name}`);
if (device.vibrateAttributes.length === 0) {
return;
}
try {
await device.vibrate((config!.get('typingStrength') as number) * (config!.get('strength') as number));
timeout = setTimeout(async () => await device?.stop(), 100);
selected_device = device;
} catch (e) {
vscode.window.showErrorMessage(e as string);
if (e instanceof buttplug.ButtplugDeviceError) {
vscode.window.showErrorMessage("got a device error!");
}
}
});
client
.addListener("deviceremoved", (device) => vscode.window.showInformationMessage(`Device Removed: ${device.name}`));
config = vscode.workspace.getConfiguration('buttplug');
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async e => {
if (!e.affectsConfiguration('buttplug')) { return; }
config = vscode.workspace.getConfiguration('buttplug');
await connect();
}));
// Vibe on type
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(async (e) => {
if (config!.get('typingStrength') === 0) { return; }
if (config!.get('buildStrength') !== 0 && building) { return; }
const activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
return;
}
await selected_device?.vibrate((config!.get('typingStrength') as number) * (config!.get('strength') as number));
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(async () => await selected_device?.stop(), config!.get('typingDuration') as number * 1000);
}));
// Vibrate continuously while building
context.subscriptions.push(vscode.tasks.onDidStartTask(async e => {
if (config!.get('buildStrength') === 0) { return; }
if (e.execution.task.group === vscode.TaskGroup.Build) {
building = true;
await selected_device?.vibrate((config!.get('buildStrength') as number) * (config!.get('strength') as number));
}
}));
// Stop vibration once build tasks all finish
context.subscriptions.push(vscode.tasks.onDidEndTask(async e => {
if ((await vscode.tasks.taskExecutions).every(t => t.task.group !== vscode.TaskGroup.Build)) {
building = false;
await selected_device?.stop();
}
}));
// Asshole obliteration command
vscode.commands.registerCommand("buttplug.assblast", () => {
selected_device?.vibrate(1.0);
});
// Killswitch for safety purposes
vscode.commands.registerCommand("buttplug.killswitch", () => {
selected_device?.stop();
});
vscode.commands.registerCommand("buttplug.reconnect", () => {
connect();
});
connect();
}
|