fix file not exists when reopen project

This commit is contained in:
codetypes committed 2025-04-17 15:41:13 +08:00
1 parent 6894aacfd1
commit e21c32e800
1 file changed
+12 -7
+12 -7
View File
@@ -227,7 +227,8 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
init: (path) => { init: (path) => {
const workspace = get(); const workspace = get();
const files = useSetting.getState().getEditors(path); const setting = useSetting.getState();
const files = setting.getEditors(path);
if (!workspace.workdir) { if (!workspace.workdir) {
try { try {
workspace.workdir = Path.dirname(path).replaceAll(Path.sep, "/"); workspace.workdir = Path.dirname(path).replaceAll(Path.sep, "/");
@@ -236,15 +237,19 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
workspace.loadTrees(); workspace.loadTrees();
workspace.loadNodeDefs(); workspace.loadNodeDefs();
workspace.watch(); workspace.watch();
useSetting.getState().appendRecent(path); setting.appendRecent(path);
if (files.length) { if (files.length) {
for (const entry of files) { for (const entry of files) {
try { try {
entry.path = Path.posixPath(entry.path); if (fs.existsSync(entry.path)) {
const editor = new EditorStore(entry.path); entry.path = Path.posixPath(entry.path);
workspace.editors.push(editor); const editor = new EditorStore(entry.path);
if (entry.active) { workspace.editors.push(editor);
workspace.open(editor.path); if (entry.active) {
workspace.open(editor.path);
}
} else {
setting.closeEditor(workspace.path, entry.path);
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);