diff --git a/src/app/features/call/CallService.ts b/src/app/features/call/CallService.ts index 9466d24a..dc07ceb4 100644 --- a/src/app/features/call/CallService.ts +++ b/src/app/features/call/CallService.ts @@ -69,10 +69,8 @@ function checkWebRTCSupport(): { supported: boolean; details: Record( const result = await pluginRegistry.executeCommand(commandName, plainText, roomId); if (result) { // If command returns text, send it as a message - const content: IContent = { + const content: RoomMessageEventContent = { msgtype: MsgType.Text, body: result, }; - mx.sendMessage(roomId, content as any); + mx.sendMessage(roomId, content); } } catch (err) { console.error(`[RoomInput] Plugin command /${commandName} failed:`, err); diff --git a/src/app/paarrot-api.ts b/src/app/paarrot-api.ts index d22ea8de..94f7fc4c 100644 --- a/src/app/paarrot-api.ts +++ b/src/app/paarrot-api.ts @@ -7,7 +7,7 @@ * To use this, import and call initPaarrotAPI() early in your app initialization. */ -import { MatrixClient, Room } from 'matrix-js-sdk'; +import { MatrixClient, MsgType, Room } from 'matrix-js-sdk'; import { getHomeRoomPath, getDirectRoomPath, getSpaceRoomPath } from './pages/pathUtils'; import { getCanonicalAliasOrRoomId } from './utils/matrix'; import { getCallService } from './features/call/useCall'; @@ -300,18 +300,16 @@ async function getChannels(matrixClient: MatrixClient) { /** * Send a message to a specific room */ -async function sendMessage(matrixClient: any, roomId: string, message: string) { +async function sendMessage(matrixClient: MatrixClient, roomId: string, message: string) { const room = matrixClient?.getRoom(roomId); if (!room) { throw new Error(`Room not found: ${roomId}`); } - const content = { - msgtype: 'm.text', + const result = await matrixClient.sendMessage(roomId, { + msgtype: MsgType.Text, body: message.trim(), - }; - - const result = await matrixClient.sendMessage(roomId, content); + }); return { eventId: result.event_id, @@ -564,7 +562,7 @@ async function getUnreadsByScope(matrixClient: MatrixClient, scope: MessageScope */ export function initPaarrotAPI(matrixClient: MatrixClient) { // Check if we're running in Electron - if (!(window as any).electron?.api?.onAction) { + if (!window.electron?.api?.onAction) { console.log('Paarrot API: Not running in Electron, skipping API initialization'); return; } @@ -579,7 +577,7 @@ export function initPaarrotAPI(matrixClient: MatrixClient) { console.log('Paarrot API: Initializing API handler'); // Listen for API actions from the Electron API server - (window as any).electron.api.onAction( + window.electron.api.onAction( async (action: { action: string; params: any; responseChannel: string }) => { console.log('Paarrot API: Received action:', action.action, action.params); @@ -656,7 +654,7 @@ export function initPaarrotAPI(matrixClient: MatrixClient) { } // Send success response back - (window as any).electron.api.sendResponse(action.responseChannel, { + window.electron?.api?.sendResponse(action.responseChannel, { success: true, data: result, }); @@ -666,7 +664,7 @@ export function initPaarrotAPI(matrixClient: MatrixClient) { console.error('Paarrot API: Action failed:', action.action, error); // Send error response back - (window as any).electron.api.sendResponse(action.responseChannel, { + window.electron?.api?.sendResponse(action.responseChannel, { success: false, error: error instanceof Error ? error.message : 'Unknown error', }); diff --git a/src/ext.d.ts b/src/ext.d.ts index 7f306b5a..56543ee5 100644 --- a/src/ext.d.ts +++ b/src/ext.d.ts @@ -80,6 +80,12 @@ interface ElectronAPI { }>; }; plugins?: PluginAPI; + api?: { + onAction: ( + callback: (action: { action: string; params: unknown; responseChannel: string }) => void, + ) => () => void; + sendResponse: (channel: string, result: unknown) => void; + }; debug?: { openWindow: () => Promise<{ success: boolean; error?: string }>; send: (packet: DebugPacket) => void; @@ -162,6 +168,8 @@ interface ElectronAPI { declare global { interface Window { + // Legacy WebKit fallbacks, same shape as their standard counterparts + webkitRTCPeerConnection?: typeof RTCPeerConnection; electron?: ElectronAPI; __TAURI__?: { invoke: (command: string, args?: unknown) => Promise; @@ -172,6 +180,12 @@ declare global { getPlatform?: () => string; }; } + + interface Navigator { + // Legacy WebKit fallbacks, same shape as MediaDevices.getUserMedia + getUserMedia?: (constraints?: MediaStreamConstraints) => Promise; + webkitGetUserMedia?: (constraints?: MediaStreamConstraints) => Promise; + } } export {};