fix: My Computer luôn hiển thị cây hệ thống client, bỏ restore folder cũ
This commit is contained in:
+3
-29
@@ -9205,6 +9205,8 @@ const MediaExplorerPanel = ({ height }) => {
|
||||
}, [saveSession, computerMode, clientRoot]);
|
||||
|
||||
const restoreSession = React.useCallback(() => {
|
||||
// Chỉ khôi phục favorites + các pref khác. KHÔNG khôi phục thư mục/tree đã mở:
|
||||
// My Computer luôn phải hiển thị cây hệ thống client.
|
||||
try {
|
||||
const raw = localStorage.getItem(SESSION_KEY);
|
||||
if (!raw) return;
|
||||
@@ -9212,44 +9214,16 @@ const MediaExplorerPanel = ({ height }) => {
|
||||
if (snap.folder) setFolder(snap.folder);
|
||||
if (snap.computerMode) setComputerMode(snap.computerMode);
|
||||
if (snap.clientRootName) setClientRoot({ name: snap.clientRootName });
|
||||
if (snap.computerRoots && snap.computerRoots.length) setComputerRoots(snap.computerRoots);
|
||||
if (snap.computerPath) setComputerPath(snap.computerPath);
|
||||
if (snap.computerFiles) setComputerFiles(snap.computerFiles);
|
||||
if (snap.selected) setSelected(snap.selected);
|
||||
if (snap.computerTree) {
|
||||
const tree = {};
|
||||
Object.keys(snap.computerTree).forEach(path => {
|
||||
tree[path] = {
|
||||
dirs: snap.computerTree[path].dirs || [],
|
||||
expanded: snap.computerTree[path].expanded
|
||||
};
|
||||
});
|
||||
setComputerTree(tree);
|
||||
}
|
||||
} catch (e) {}
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
(async () => {
|
||||
await restoreSession();
|
||||
// Restore the FileSystemDirectoryHandle so client-mode browsing still works
|
||||
// Chỉ nối lại FileSystemDirectoryHandle để client browsing hoạt động (không khôi phục folder cũ)
|
||||
const savedHandle = await loadClientRootHandle();
|
||||
if (savedHandle && savedHandle.kind === 'directory') {
|
||||
setClientRoot(savedHandle);
|
||||
const restoredPath = (() => { try { return JSON.parse(localStorage.getItem(SESSION_KEY) || '{}').computerPath; } catch (e) { return null; } })();
|
||||
if (restoredPath) {
|
||||
setComputerRoots([{ name: savedHandle.name, path: 'root', is_dir: true, handle: savedHandle }]);
|
||||
// Re-browse current dir to re-attach real handles (metadata-only tree from localStorage)
|
||||
const storedTree = (() => { try { return JSON.parse(localStorage.getItem(SESSION_KEY) || '{}').computerTree; } catch (e) { return null; } })();
|
||||
if (storedTree) {
|
||||
const rebuilt = {};
|
||||
Object.keys(storedTree).forEach(p => { rebuilt[p] = { dirs: storedTree[p].dirs || [], expanded: storedTree[p].expanded }; });
|
||||
setComputerTree(rebuilt);
|
||||
}
|
||||
setComputerMode('client');
|
||||
// Rebuild handles for the current folder + ancestors by walking from root
|
||||
browseComputerDir({ name: savedHandle.name, path: 'root', is_dir: true, handle: savedHandle });
|
||||
}
|
||||
}
|
||||
})();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
|
||||
Reference in New Issue
Block a user