feat: 任务保存冲突检测——磁盘被外部修改时提示选择而非静默覆盖
This commit is contained in:
1 parent
97fda1696a
commit
876e4969bd
6 files changed
+80
-22
No files matched your search
+12
-2
@@ -1,6 +1,6 @@
|
||||
import { app, BrowserWindow, dialog, ipcMain, shell } from "electron";
|
||||
import path from "node:path";
|
||||
import type { AppInfo, AppSettings, FlowDefinition } from "../shared/types";
|
||||
import type { AppInfo, AppSettings, FlowDefinition, FlowSaveOptions, FlowSaveResult } from "../shared/types";
|
||||
import { BrowserSession, hasBrowserSession, setBrowserElementWaitMs } from "./browser/session";
|
||||
import "./capabilities";
|
||||
import { catalogPath, loadCatalog } from "./catalog";
|
||||
@@ -128,7 +128,15 @@ function registerIpc(): void {
|
||||
return listFlows();
|
||||
});
|
||||
ipcMain.handle("flows:get", (_event, id: string) => getFlow(id));
|
||||
ipcMain.handle("flows:save", (_event, flow: FlowDefinition) => saveFlow(flow));
|
||||
ipcMain.handle("flows:save", (_event, flow: FlowDefinition, opts?: FlowSaveOptions): FlowSaveResult => {
|
||||
if (!opts?.force && opts?.expectedUpdatedAt) {
|
||||
const disk = getFlow(flow.id);
|
||||
if (disk && disk.meta?.updatedAt && disk.meta.updatedAt !== opts.expectedUpdatedAt) {
|
||||
return { conflict: true, diskFlow: disk };
|
||||
}
|
||||
}
|
||||
return { conflict: false, flow: saveFlow(flow) };
|
||||
});
|
||||
ipcMain.handle("flows:delete", (_event, id: string) => {
|
||||
deleteFlow(id);
|
||||
return true;
|
||||
@@ -190,3 +198,5 @@ if (!gotLock) {
|
||||
void stopFixtureServer();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user