Merge fixes

This commit is contained in:
Connor Yoh 2025-07-18 11:25:14 +01:00
parent a02d325ca2
commit 6413099182
4 changed files with 63 additions and 12 deletions

View File

@ -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<File | null>(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 (
<>
<BackendHealthIndicator className="absolute top-3 left-3 z-10" />
<RainbowThemeProvider>
<FileContextProvider enableUrlSync={true} enablePersistence={true}>
<HomePage />
<HomePage openedFile={openedFile} />
</FileContextProvider>
</RainbowThemeProvider>
</>

View File

@ -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<string[]>([]);
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,
};
};

View File

@ -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 (

View File

@ -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