Type the paarrot api, WebKit globals, and plugin command content. [skip build]
Checks / checks (push) Successful in 2m6s
Trigger cinny-mobile / dispatch (push) Successful in 2s

This commit is contained in:
2026-11-02 02:22:02 +11:00
parent b36335cde9
commit 6c8a085ae1
4 changed files with 29 additions and 18 deletions
+3 -5
View File
@@ -69,10 +69,8 @@ function checkWebRTCSupport(): { supported: boolean; details: Record<string, unk
); );
// Check WebKit-specific APIs // Check WebKit-specific APIs
details.hasWebkitGetUserMedia = !!( details.hasWebkitGetUserMedia = !!(navigator.getUserMedia || navigator.webkitGetUserMedia);
navigator.getUserMedia || (navigator as any).webkitGetUserMedia details.hasWebkitRTCPeerConnection = !!window.webkitRTCPeerConnection;
);
details.hasWebkitRTCPeerConnection = !!(window as any).webkitRTCPeerConnection;
// Check if mediaDevices API exists // Check if mediaDevices API exists
details.hasMediaDevices = !!navigator.mediaDevices; details.hasMediaDevices = !!navigator.mediaDevices;
@@ -83,7 +81,7 @@ function checkWebRTCSupport(): { supported: boolean; details: Record<string, unk
const supported = !!( const supported = !!(
navigator.mediaDevices && navigator.mediaDevices &&
navigator.mediaDevices.getUserMedia && navigator.mediaDevices.getUserMedia &&
(window.RTCPeerConnection || (window as any).webkitRTCPeerConnection) (window.RTCPeerConnection || window.webkitRTCPeerConnection)
); );
return { supported, details }; return { supported, details };
+3 -2
View File
@@ -10,6 +10,7 @@ import React, {
import { useAtom, useAtomValue } from 'jotai'; import { useAtom, useAtomValue } from 'jotai';
import { isKeyHotkey } from 'is-hotkey'; import { isKeyHotkey } from 'is-hotkey';
import { EventType, IContent, MsgType, RelationType, Room } from 'matrix-js-sdk'; import { EventType, IContent, MsgType, RelationType, Room } from 'matrix-js-sdk';
import { RoomMessageEventContent } from 'matrix-js-sdk/lib/types';
import { Transforms, Editor } from 'slate'; import { Transforms, Editor } from 'slate';
import { import {
Box, Box,
@@ -405,11 +406,11 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
const result = await pluginRegistry.executeCommand(commandName, plainText, roomId); const result = await pluginRegistry.executeCommand(commandName, plainText, roomId);
if (result) { if (result) {
// If command returns text, send it as a message // If command returns text, send it as a message
const content: IContent = { const content: RoomMessageEventContent = {
msgtype: MsgType.Text, msgtype: MsgType.Text,
body: result, body: result,
}; };
mx.sendMessage(roomId, content as any); mx.sendMessage(roomId, content);
} }
} catch (err) { } catch (err) {
console.error(`[RoomInput] Plugin command /${commandName} failed:`, err); console.error(`[RoomInput] Plugin command /${commandName} failed:`, err);
+9 -11
View File
@@ -7,7 +7,7 @@
* To use this, import and call initPaarrotAPI() early in your app initialization. * 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 { getHomeRoomPath, getDirectRoomPath, getSpaceRoomPath } from './pages/pathUtils';
import { getCanonicalAliasOrRoomId } from './utils/matrix'; import { getCanonicalAliasOrRoomId } from './utils/matrix';
import { getCallService } from './features/call/useCall'; import { getCallService } from './features/call/useCall';
@@ -300,18 +300,16 @@ async function getChannels(matrixClient: MatrixClient) {
/** /**
* Send a message to a specific room * 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); const room = matrixClient?.getRoom(roomId);
if (!room) { if (!room) {
throw new Error(`Room not found: ${roomId}`); throw new Error(`Room not found: ${roomId}`);
} }
const content = { const result = await matrixClient.sendMessage(roomId, {
msgtype: 'm.text', msgtype: MsgType.Text,
body: message.trim(), body: message.trim(),
}; });
const result = await matrixClient.sendMessage(roomId, content);
return { return {
eventId: result.event_id, eventId: result.event_id,
@@ -564,7 +562,7 @@ async function getUnreadsByScope(matrixClient: MatrixClient, scope: MessageScope
*/ */
export function initPaarrotAPI(matrixClient: MatrixClient) { export function initPaarrotAPI(matrixClient: MatrixClient) {
// Check if we're running in Electron // 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'); console.log('Paarrot API: Not running in Electron, skipping API initialization');
return; return;
} }
@@ -579,7 +577,7 @@ export function initPaarrotAPI(matrixClient: MatrixClient) {
console.log('Paarrot API: Initializing API handler'); console.log('Paarrot API: Initializing API handler');
// Listen for API actions from the Electron API server // 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 }) => { async (action: { action: string; params: any; responseChannel: string }) => {
console.log('Paarrot API: Received action:', action.action, action.params); console.log('Paarrot API: Received action:', action.action, action.params);
@@ -656,7 +654,7 @@ export function initPaarrotAPI(matrixClient: MatrixClient) {
} }
// Send success response back // Send success response back
(window as any).electron.api.sendResponse(action.responseChannel, { window.electron?.api?.sendResponse(action.responseChannel, {
success: true, success: true,
data: result, data: result,
}); });
@@ -666,7 +664,7 @@ export function initPaarrotAPI(matrixClient: MatrixClient) {
console.error('Paarrot API: Action failed:', action.action, error); console.error('Paarrot API: Action failed:', action.action, error);
// Send error response back // Send error response back
(window as any).electron.api.sendResponse(action.responseChannel, { window.electron?.api?.sendResponse(action.responseChannel, {
success: false, success: false,
error: error instanceof Error ? error.message : 'Unknown error', error: error instanceof Error ? error.message : 'Unknown error',
}); });
+14
View File
@@ -80,6 +80,12 @@ interface ElectronAPI {
}>; }>;
}; };
plugins?: PluginAPI; plugins?: PluginAPI;
api?: {
onAction: (
callback: (action: { action: string; params: unknown; responseChannel: string }) => void,
) => () => void;
sendResponse: (channel: string, result: unknown) => void;
};
debug?: { debug?: {
openWindow: () => Promise<{ success: boolean; error?: string }>; openWindow: () => Promise<{ success: boolean; error?: string }>;
send: (packet: DebugPacket) => void; send: (packet: DebugPacket) => void;
@@ -162,6 +168,8 @@ interface ElectronAPI {
declare global { declare global {
interface Window { interface Window {
// Legacy WebKit fallbacks, same shape as their standard counterparts
webkitRTCPeerConnection?: typeof RTCPeerConnection;
electron?: ElectronAPI; electron?: ElectronAPI;
__TAURI__?: { __TAURI__?: {
invoke: (command: string, args?: unknown) => Promise<unknown>; invoke: (command: string, args?: unknown) => Promise<unknown>;
@@ -172,6 +180,12 @@ declare global {
getPlatform?: () => string; getPlatform?: () => string;
}; };
} }
interface Navigator {
// Legacy WebKit fallbacks, same shape as MediaDevices.getUserMedia
getUserMedia?: (constraints?: MediaStreamConstraints) => Promise<MediaStream>;
webkitGetUserMedia?: (constraints?: MediaStreamConstraints) => Promise<MediaStream>;
}
} }
export {}; export {};