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
details.hasWebkitGetUserMedia = !!(
navigator.getUserMedia || (navigator as any).webkitGetUserMedia
);
details.hasWebkitRTCPeerConnection = !!(window as any).webkitRTCPeerConnection;
details.hasWebkitGetUserMedia = !!(navigator.getUserMedia || navigator.webkitGetUserMedia);
details.hasWebkitRTCPeerConnection = !!window.webkitRTCPeerConnection;
// Check if mediaDevices API exists
details.hasMediaDevices = !!navigator.mediaDevices;
@@ -83,7 +81,7 @@ function checkWebRTCSupport(): { supported: boolean; details: Record<string, unk
const supported = !!(
navigator.mediaDevices &&
navigator.mediaDevices.getUserMedia &&
(window.RTCPeerConnection || (window as any).webkitRTCPeerConnection)
(window.RTCPeerConnection || window.webkitRTCPeerConnection)
);
return { supported, details };
+3 -2
View File
@@ -10,6 +10,7 @@ import React, {
import { useAtom, useAtomValue } from 'jotai';
import { isKeyHotkey } from 'is-hotkey';
import { EventType, IContent, MsgType, RelationType, Room } from 'matrix-js-sdk';
import { RoomMessageEventContent } from 'matrix-js-sdk/lib/types';
import { Transforms, Editor } from 'slate';
import {
Box,
@@ -405,11 +406,11 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
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);
+9 -11
View File
@@ -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',
});
+14
View File
@@ -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<unknown>;
@@ -172,6 +180,12 @@ declare global {
getPlatform?: () => string;
};
}
interface Navigator {
// Legacy WebKit fallbacks, same shape as MediaDevices.getUserMedia
getUserMedia?: (constraints?: MediaStreamConstraints) => Promise<MediaStream>;
webkitGetUserMedia?: (constraints?: MediaStreamConstraints) => Promise<MediaStream>;
}
}
export {};