# Description of Changes - Adds a reusable banner component/system to the core app - Adds banner at the top of the desktop app if Stirling isn't your default PDF editor, with a button to make it your default - Adds a permanent button in the settings to do it manually (in case you've dismissed the banner) - Simplifies the file loading logic to fix a bug where the input file could be duplicated occasionally. Now, the TS just receives files from one buffer, regardless of how they've been passed to the app in Rust. ## Caveats I've only been able to get the setting of default apps working properly on Mac. The Windows build isn't signed (yet) so we can't use the proper API for it, so currently it just sends you to the Settings UI. I've also not been able to test it on Linux at all.
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import { fileOpenService } from '@app/services/fileOpenService';
|
|
import { listen } from '@tauri-apps/api/event';
|
|
|
|
export function useOpenedFile() {
|
|
const [openedFilePaths, setOpenedFilePaths] = useState<string[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
// Function to read and process files from storage
|
|
const readFilesFromStorage = async () => {
|
|
console.log('🔍 Reading files from storage...');
|
|
try {
|
|
const filePaths = await fileOpenService.getOpenedFiles();
|
|
console.log('🔍 fileOpenService.getOpenedFiles() returned:', filePaths);
|
|
|
|
if (filePaths.length > 0) {
|
|
console.log(`✅ Found ${filePaths.length} file(s) in storage:`, filePaths);
|
|
setOpenedFilePaths(filePaths);
|
|
await fileOpenService.clearOpenedFiles();
|
|
}
|
|
} catch (error) {
|
|
console.error('❌ Failed to read files from storage:', error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
// Read files on mount
|
|
readFilesFromStorage();
|
|
|
|
// Listen for files-changed events (when new files are added to storage)
|
|
let unlisten: (() => void) | undefined;
|
|
listen('files-changed', async () => {
|
|
console.log('📂 files-changed event received, re-reading storage...');
|
|
await readFilesFromStorage();
|
|
}).then(unlistenFn => {
|
|
unlisten = unlistenFn;
|
|
});
|
|
|
|
// Cleanup function
|
|
return () => {
|
|
if (unlisten) unlisten();
|
|
};
|
|
}, []);
|
|
|
|
return { openedFilePaths, loading };
|
|
}
|