示例工程 11-main-process-services
11-main-process-services/app/.tsc/main/services/dialog-service.js
import path from "node:path";
import { ServiceError } from "../../shared/ipc";
export function createDialogService(options) {
return {
async pick() {
if (options.dryRun) {
return { path: "/tmp/demo-notes/welcome.md", name: "welcome.md" };
}
const result = await options.showOpenDialog();
const file = result.filePaths[0];
if (result.canceled || !file)
return null;
if (!/\.(md|txt)$/i.test(file)) {
throw new ServiceError("BAD_EXTENSION", "只支持 .md 与 .txt", "path");
}
return { path: file, name: path.basename(file) };
},
};
}
//# sourceMappingURL=dialog-service.js.map