Compare commits

...
Author SHA1 Message Date
James Brunton 77d0edef34 kinda fix file duplication issue 2025-12-16 11:41:36 +00:00
James Brunton a72b687f10 initial attempt 2025-12-16 11:39:24 +00:00
3 changed files with 21 additions and 3 deletions
@@ -51,7 +51,8 @@ class UserLicenseSettingsServiceTest {
when(applicationProperties.getPremium()).thenReturn(premium);
when(applicationProperties.getAutomaticallyGenerated()).thenReturn(automaticallyGenerated);
when(automaticallyGenerated.getIsNewServer()).thenReturn(false); // Default: not a new server
when(automaticallyGenerated.getIsNewServer())
.thenReturn(false); // Default: not a new server
when(settingsRepository.findSettings()).thenReturn(Optional.of(mockSettings));
when(userService.getTotalUsersCount()).thenReturn(80L);
when(settingsRepository.save(any(UserLicenseSettings.class)))
@@ -84,7 +84,6 @@ export function AppProviders({ children, appConfigRetryOptions, appConfigProvide
<ScarfTrackingInitializer />
<AppConfigLoader />
<FileContextProvider enableUrlSync={true} enablePersistence={true}>
<AppInitializer />
<BrandingAssetManager />
<ToolRegistryProvider>
<NavigationProvider>
@@ -93,6 +92,7 @@ export function AppProviders({ children, appConfigRetryOptions, appConfigProvide
<HotkeyProvider>
<SidebarProvider>
<ViewerProvider>
<AppInitializer />
<PageEditorProvider>
<SignatureProvider>
<RightRailProvider>
@@ -1,20 +1,28 @@
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useOpenedFile } from '@app/hooks/useOpenedFile';
import { fileOpenService } from '@app/services/fileOpenService';
import { useFileManagement } from '@app/contexts/file/fileHooks';
import { useToolWorkflow } from '@app/contexts/ToolWorkflowContext';
import { useNavigationActions } from '@app/contexts/NavigationContext';
import { useViewer } from '@app/contexts/ViewerContext';
/**
* App initialization hook
* Desktop version: Handles Tauri-specific file initialization
* Requires FileContext - must be used inside FileContextProvider
* - Handles files opened with the app (adds directly to FileContext)
* - Opens single files in reader mode (collapsed tools for clean viewing)
*/
export function useAppInitialization(): void {
// Get file management actions
const { addFiles } = useFileManagement();
const { setReaderMode } = useToolWorkflow();
const { actions } = useNavigationActions();
const { setActiveFileIndex } = useViewer();
// Handle files opened with app (Tauri mode)
const { openedFilePaths, loading: openedFileLoading } = useOpenedFile();
const hasSetInitialReaderMode = useRef(false);
// Load opened files and add directly to FileContext
useEffect(() => {
@@ -46,6 +54,15 @@ export function useAppInitialization(): void {
if (filesArray.length > 0) {
await addFiles(filesArray);
console.log(`[Desktop] ${filesArray.length} opened file(s) added to FileContext`);
// Open single files in reader mode only on first app launch
if (filesArray.length === 1 && !hasSetInitialReaderMode.current) {
hasSetInitialReaderMode.current = true;
setReaderMode(true);
actions.setWorkbench('viewer');
setActiveFileIndex(0);
console.log('[Desktop] Opening in reader mode');
}
}
} catch (error) {
console.error('[Desktop] Failed to load opened files:', error);