From f76fee23bff49574f7db7e48d06843aa2470f84c Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Mon, 23 Mar 2026 20:34:14 +1100 Subject: [PATCH] feat: prevent duplicate initialization of Paarrot API and update server port --- src/app/paarrot-api.ts | 12 ++++++++++++ src/app/pages/client/ClientRoot.tsx | 8 -------- vite.config.js | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app/paarrot-api.ts b/src/app/paarrot-api.ts index 59afbd1..76b00e4 100644 --- a/src/app/paarrot-api.ts +++ b/src/app/paarrot-api.ts @@ -18,6 +18,11 @@ import { getCallService } from './features/call/useCall'; */ let navigateFunction: ((path: string) => void) | null = null; +/** + * Track if the API has been initialized to prevent duplicate listeners + */ +let isInitialized = false; + /** * Set the navigate function for programmatic navigation * Call this from your router setup @@ -38,6 +43,13 @@ export function initPaarrotAPI(matrixClient: MatrixClient) { return; } + // Prevent duplicate registrations + if (isInitialized) { + console.log('Paarrot API: Already initialized, skipping'); + return; + } + isInitialized = true; + console.log('Paarrot API: Initializing API handler'); // Listen for API actions from the Electron API server diff --git a/src/app/pages/client/ClientRoot.tsx b/src/app/pages/client/ClientRoot.tsx index 3de5fc4..09c6579 100644 --- a/src/app/pages/client/ClientRoot.tsx +++ b/src/app/pages/client/ClientRoot.tsx @@ -37,7 +37,6 @@ import { getCurrentSession } from '../../state/sessions'; import { CallProviderWrapper } from '../../features/call/CallProviderWrapper'; import { isTauriMobile, startBackgroundSync, stopBackgroundSync } from '../../utils/tauri'; import { TitleBar } from '../../components/title-bar'; -import { initPaarrotAPI } from '../../paarrot-api'; import { AccountSwitcher } from '../../components/account-switcher'; import { getLoginPath, withSearchParam } from '../pathUtils'; @@ -178,13 +177,6 @@ export function ClientRoot({ children }: ClientRootProps) { useVisibilitySync(mx); useBackgroundSync(mx); - // Initialize Paarrot API when client is ready - useEffect(() => { - if (mx) { - initPaarrotAPI(mx); - } - }, [mx]); - useEffect(() => { if (loadState.status === AsyncStatus.Idle) { loadMatrix(); diff --git a/vite.config.js b/vite.config.js index eb37b56..fb49d09 100644 --- a/vite.config.js +++ b/vite.config.js @@ -102,7 +102,7 @@ export default defineConfig({ publicDir: false, base: buildConfig.base, server: { - port: 8080, + port: 38347, host: '0.0.0.0', fs: { // Allow serving files from one level up to the project root