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
Anthony StirlingandGitHub d80e627899 Cache fix issues V2 (#5237)
# Description of Changes

<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.
2025-12-15 23:54:25 +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);