diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 58fe2e3b4..16d6c6973 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,9 +1,10 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { RainbowThemeProvider } from './components/shared/RainbowThemeProvider'; import { FileContextProvider } from './contexts/FileContext'; import HomePage from './pages/HomePage'; import { useOpenedFile } from './hooks/useOpenedFile'; import { useBackendInitializer } from './hooks/useBackendInitializer'; +import { fileOpenService } from './services/fileOpenService'; // Import global styles import './styles/tailwind.css'; @@ -12,16 +13,42 @@ import './index.css'; import { BackendHealthIndicator } from './components/BackendHealthIndicator'; export default function App() { - const { openedFilePath, loading: fileLoading } = useOpenedFile(); // Initialize backend on app startup useBackendInitializer(); + + // Handle file opened with app (Tauri mode) + const { openedFilePath, loading: openedFileLoading } = useOpenedFile(); + const [openedFile, setOpenedFile] = useState(null); + + // Load opened file once when path is available + useEffect(() => { + if (openedFilePath && !openedFileLoading) { + const loadOpenedFile = async () => { + try { + const fileData = await fileOpenService.readFileAsArrayBuffer(openedFilePath); + if (fileData) { + // Create a File object from the ArrayBuffer + const file = new File([fileData.arrayBuffer], fileData.fileName, { + type: 'application/pdf' + }); + setOpenedFile(file); + } + } catch (error) { + console.error('Failed to load opened file:', error); + } + }; + + loadOpenedFile(); + } + }, [openedFilePath, openedFileLoading]); + return ( <> - + diff --git a/frontend/src/hooks/useToolManagement.tsx b/frontend/src/hooks/useToolManagement.tsx index 31e63e93d..07b02daaf 100644 --- a/frontend/src/hooks/useToolManagement.tsx +++ b/frontend/src/hooks/useToolManagement.tsx @@ -6,7 +6,7 @@ import ZoomInMapIcon from "@mui/icons-material/ZoomInMap"; import SplitPdfPanel from "../tools/Split"; import CompressPdfPanel from "../tools/Compress"; import MergePdfPanel from "../tools/Merge"; -import { useMultipleEndpointsEnabled } from "./useEndpointConfig"; +import { useMultipleEndpointsEnabledWithHealthCheck } from './useEndpointConfig'; type ToolRegistryEntry = { icon: React.ReactNode; @@ -40,7 +40,8 @@ export const useToolManagement = () => { const [toolSelectedFileIds, setToolSelectedFileIds] = useState([]); const allEndpoints = Array.from(new Set(Object.values(toolEndpoints).flat())); - const { endpointStatus, loading: endpointsLoading } = useMultipleEndpointsEnabled(allEndpoints); + const { endpointStatus, loading: endpointsLoading } = useMultipleEndpointsEnabledWithHealthCheck(allEndpoints); + const isToolAvailable = useCallback((toolKey: string): boolean => { if (endpointsLoading) return true; @@ -91,6 +92,5 @@ export const useToolManagement = () => { selectTool, clearToolSelection, setToolSelectedFileIds, - }; }; diff --git a/frontend/src/pages/HomePage.tsx b/frontend/src/pages/HomePage.tsx index 749fe0001..0fb546f51 100644 --- a/frontend/src/pages/HomePage.tsx +++ b/frontend/src/pages/HomePage.tsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback} from "react"; +import React, { useState, useCallback, useEffect} from "react"; import { useTranslation } from 'react-i18next'; import { useFileContext } from "../contexts/FileContext"; import { useToolManagement } from "../hooks/useToolManagement"; @@ -15,9 +15,12 @@ import Viewer from "../components/viewer/Viewer"; import FileUploadSelector from "../components/shared/FileUploadSelector"; import ToolRenderer from "../components/tools/ToolRenderer"; import QuickAccessBar from "../components/shared/QuickAccessBar"; -import { useMultipleEndpointsEnabledWithHealthCheck } from "../hooks/useEndpointConfig"; -export default function HomePage() { +interface HomePageProps { + openedFile?: File | null; +} + +export default function HomePage({ openedFile }: HomePageProps) { const { t } = useTranslation(); const { isRainbowMode } = useRainbowThemeContext(); @@ -25,6 +28,7 @@ export default function HomePage() { const fileContext = useFileContext(); const { activeFiles, currentView, currentMode, setCurrentView, addFiles } = fileContext; + const { selectedToolKey, selectedTool, @@ -77,6 +81,26 @@ export default function HomePage() { } }, [activeFiles, addFiles]); + // Handle file opened with app (Tauri mode) + useEffect(() => { + if (openedFile) { + const loadOpenedFile = async () => { + try { + // Add to active files if not already present + await addToActiveFiles(openedFile); + + // Switch to viewer mode to show the opened file + setCurrentView('viewer'); + setReaderMode(true); + } catch (error) { + console.error('Failed to load opened file:', error); + } + }; + + loadOpenedFile(); + } + }, [openedFile]); + return ( diff --git a/scripts/build-tauri-jlink.bat b/scripts/build-tauri-jlink.bat index d7c332036..fb81b8438 100644 --- a/scripts/build-tauri-jlink.bat +++ b/scripts/build-tauri-jlink.bat @@ -27,9 +27,9 @@ if errorlevel 1 ( ) REM Find the built JAR(s) -echo ▶ Listing all built JAR files in stirling-pdf\build\libs: -dir /b stirling-pdf\build\libs\Stirling-PDF-*.jar -for %%f in (stirling-pdf\build\libs\Stirling-PDF-*.jar) do set STIRLING_JAR=%%f +echo ▶ Listing all built JAR files in app\core\build\libs: +dir /b app\core\build\libs\Stirling-PDF-*.jar +for %%f in (app\core\build\libs\Stirling-PDF-*.jar) do set STIRLING_JAR=%%f if not exist "%STIRLING_JAR%" ( echo ❌ No Stirling-PDF JAR found in build/libs/ exit /b 1