Skip to content

Commit

Permalink
feat(core): 在关闭时清理虚拟文件系统并优化文件加载逻辑
Browse files Browse the repository at this point in the history
- 在加载文件前,增加清除虚拟文件系统的操作
- 在多个地方添加 VFileSystem.clear() 调用,以确保文件切换时清理虚拟文件系统
- 修改文件加载逻辑,只允许加载 .gp 后缀的文件
- 更新错误提示信息,明确指出需要选择 .gp 文件
  • Loading branch information
neooier committed Feb 1, 2025
1 parent 59fe414 commit 9fec9be
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/core/service/dataFileService/VFileSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export namespace VFileSystem {
setMetaData(JSON.stringify(StageDumper.dump()));
}
export async function loadFromPath(path: string) {
await clear();
const data = await readFile(path);
const zip = await jszip.loadAsync(data);
const entries = zip.files;
Expand Down
5 changes: 5 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import LogicNodePanel from "./_logic_node_panel";
import RecentFilesPanel from "./_recent_files_panel";
import StartFilePanel from "./_start_file_panel";
import TagPanel from "./_tag_panel";
import { VFileSystem } from "../core/service/dataFileService/VFileSystem";

export default function App() {
const [maxmized, setMaxmized] = React.useState(false);
Expand Down Expand Up @@ -104,6 +105,7 @@ export default function App() {
{
text: "不保存",
onClick: async () => {
await VFileSystem.clear();
await getCurrentWindow().destroy();
},
},
Expand All @@ -118,10 +120,12 @@ export default function App() {
if (isAutoSave) {
// 开启了自动保存,不弹窗
await StageSaveManager.saveHandle(file, StageDumper.dump());
await VFileSystem.clear();
getCurrentWindow().destroy();
} else {
// 没开启自动保存,逐步确认
if (StageSaveManager.isSaved()) {
await VFileSystem.clear();
getCurrentWindow().destroy();
} else {
await Dialog.show({
Expand All @@ -132,6 +136,7 @@ export default function App() {
text: "保存并关闭",
onClick: async () => {
await StageSaveManager.saveHandle(file, StageDumper.dump());
await VFileSystem.clear();
await getCurrentWindow().destroy();
},
},
Expand Down
7 changes: 5 additions & 2 deletions src/pages/_app_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { Stage } from "../core/stage/Stage";
import { GraphMethods } from "../core/stage/stageManager/basicMethods/GraphMethods";
import { TextNode } from "../core/stage/stageObject/entity/TextNode";
import { PathString } from "../utils/pathString";
import { VFileSystem } from "../core/service/dataFileService/VFileSystem";

export default function AppMenu({ className = "", open = false }: { className?: string; open: boolean }) {
const navigate = useNavigate();
Expand All @@ -57,9 +58,10 @@ export default function AppMenu({ className = "", open = false }: { className?:
/**
* 新建草稿
*/
const onNewDraft = () => {
const onNewDraft = async () => {
if (StageSaveManager.isSaved() || StageManager.isEmpty()) {
StageManager.destroy();
await VFileSystem.clear();
setFile("Project Graph");
} else {
// 当前文件未保存
Expand All @@ -76,8 +78,9 @@ export default function AppMenu({ className = "", open = false }: { className?:
},
{
text: "丢弃当前并直接新开",
onClick: () => {
onClick: async () => {
StageManager.destroy();
await VFileSystem.clear();
setFile("Project Graph");
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/pages/_recent_files_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export default function RecentFilesPanel() {
try {
const path = file.path;
setFile(decodeURIComponent(path));
if (isDesktop && !path.endsWith(".json")) {
if (isDesktop && !path.endsWith(".gp")) {
Dialog.show({
title: "请选择一个JSON文件",
title: "请选择一个GP文件",
type: "error",
});
return;
Expand All @@ -87,7 +87,7 @@ export default function RecentFilesPanel() {
setRecentFilePanelOpen(false);
} catch (error) {
Dialog.show({
title: "请选择正确的JSON文件",
title: "请选择正确的GP文件",
content: String(error),
type: "error",
});
Expand Down
4 changes: 2 additions & 2 deletions src/pages/_start_file_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ export default function StartFilePanel({ open = false }: { open: boolean }) {
const checkoutFile = (path: string) => {
try {
setFile(decodeURIComponent(path));
if (isDesktop && !path.endsWith(".json")) {
if (isDesktop && !path.endsWith(".gp")) {
Dialog.show({
title: "请选择一个JSON文件",
title: "请选择一个GP文件",
type: "error",
});
return;
Expand Down

0 comments on commit 9fec9be

Please sign in to comment.