Skip to content

Commit 04260cb

Browse files
committed
Fix haptics: WASM backend StrictMode loading, autoStop override, TS errors
- Reset wasmBackendLoaded ref in cleanup so React 18 StrictMode double-mount doesn't permanently prevent WASM backend registration - Remove rebuildMaps() auto-override of autoStopTimeoutSecs that was clobbering user preferences on every device change - Fix navigator.bluetooth type assertion in HapticsStatus - Cast Core.Supports handler to GMCPCoreSupports for sendAdd/sendRemove - Use intersection type for GamepadWithVibration to fix TS interface error - Add WASM haptics module declaration
1 parent c11ef66 commit 04260cb

6 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/@types/buttplug-wasm.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare module "buttplug-wasm/dist/buttplug-wasm.mjs" {
2+
export class ButtplugWasmClientConnector {
3+
Connected: boolean;
4+
connect(): Promise<void>;
5+
disconnect(): Promise<void>;
6+
static activateLogging(): Promise<void>;
7+
}
8+
}

src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ function App() {
195195
wasmBackendLoaded.current = false;
196196
});
197197

198-
return () => { cancelled = true; };
198+
return () => {
199+
cancelled = true;
200+
wasmBackendLoaded.current = false;
201+
};
199202
}, [preferences.haptics.enabled]);
200203

201204
// Effect for CTRL + Number shortcut

src/HapticsService.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,11 @@ export class HapticsService extends EventEmitter<HapticsServiceEvents> {
281281
let nextActuatorId = 0;
282282
let nextSensorId = 0;
283283

284-
// Determine effective auto-stop timeout based on device classes present
285-
const deviceClasses = new Set<HapticsDeviceClass>();
286-
287284
for (const backend of this.backends) {
288285
// Actuators
289286
const actuators = backend.getActuators();
290287
for (const actuator of actuators) {
291288
const globalId = nextActuatorId++;
292-
deviceClasses.add(actuator.deviceClass);
293289
this.actuatorMap.set(globalId, {
294290
backend,
295291
localId: actuator.id,
@@ -315,12 +311,6 @@ export class HapticsService extends EventEmitter<HapticsServiceEvents> {
315311
}
316312
}
317313

318-
// Auto-stop timeout: use shorter timeout if intimate devices are present
319-
if (deviceClasses.has("intimate")) {
320-
this._autoStopTimeoutSecs = 5;
321-
} else if (deviceClasses.has("gaming")) {
322-
this._autoStopTimeoutSecs = 30;
323-
}
324314
}
325315

326316
// -----------------------------------------------------------------------

src/components/HapticsStatus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const HapticsStatus: React.FC<HapticsStatusProps> = ({ client }) => {
108108
<div style={{ marginBottom: "8px" }}>
109109
<strong>Bluetooth Devices</strong>
110110
</div>
111-
{typeof navigator !== "undefined" && navigator.bluetooth ? (
111+
{typeof navigator !== "undefined" && (navigator as any).bluetooth ? (
112112
<div>
113113
<button
114114
onClick={handleScan}

src/gmcp/Client/Haptics.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GMCPPackage } from "../package";
2+
import type { GMCPCoreSupports } from "../Core";
23
import { hapticsService } from "../../HapticsService";
34
import { preferencesStore } from "../../PreferencesStore";
45
import type { HapticsCommand, HapticsSensorReading } from "../../haptics/types";
@@ -183,7 +184,7 @@ export class GMCPClientHaptics extends GMCPPackage {
183184

184185
advertiseHapticsSupport(): void {
185186
if (!this.isAdvertised) {
186-
const coreSupports = this.client.gmcpHandlers["Core.Supports"];
187+
const coreSupports = this.client.gmcpHandlers["Core.Supports"] as GMCPCoreSupports | undefined;
187188
if (coreSupports) {
188189
coreSupports.sendAdd([
189190
{ name: "Client.Haptics", version: this.packageVersion || 1 },
@@ -195,7 +196,7 @@ export class GMCPClientHaptics extends GMCPPackage {
195196

196197
unadvertiseHapticsSupport(): void {
197198
if (this.isAdvertised) {
198-
const coreSupports = this.client.gmcpHandlers["Core.Supports"];
199+
const coreSupports = this.client.gmcpHandlers["Core.Supports"] as GMCPCoreSupports | undefined;
199200
if (coreSupports) {
200201
coreSupports.sendRemove(["Client.Haptics"]);
201202
this.isAdvertised = false;

src/haptics/GamepadBackend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,6 @@ interface GamepadHapticActuatorExtended {
362362
reset(): Promise<string>;
363363
}
364364

365-
interface GamepadWithVibration extends Gamepad {
365+
type GamepadWithVibration = Gamepad & {
366366
vibrationActuator: GamepadHapticActuatorExtended | null;
367-
}
367+
};

0 commit comments

Comments
 (0)