diff --git a/app/electron/main.js b/app/electron/main.js index 11a8b4dbc..f5025a5f0 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -665,7 +665,7 @@ app.whenReady().then(() => { app.exit(); }); ipcMain.handle("siyuan-dialog", (event, data) => { - return dialog.showOpenDialog(data); + return dialog[data.type || "showOpenDialog"](data); }); ipcMain.on("siyuan-cmd", (event, cmd) => { switch (cmd) { diff --git a/app/src/config/exportConfig.ts b/app/src/config/exportConfig.ts index d071c1d84..24ed952f0 100644 --- a/app/src/config/exportConfig.ts +++ b/app/src/config/exportConfig.ts @@ -1,12 +1,13 @@ import {fetchPost} from "../util/fetch"; /// #if !BROWSER -import {dialog} from "@electron/remote"; import {afterExport} from "../protyle/export/util"; +import { ipcRenderer } from "electron"; import * as path from "path"; /// #endif import {isBrowser} from "../util/functions"; import {showMessage} from "../dialog/message"; import {showFileInFolder} from "../util/pathName"; +import {Constants} from "../constants"; export const exportConfig = { element: undefined as Element, @@ -179,13 +180,14 @@ export const exportConfig = { }); } }); - exportConfig.element.querySelector("#exportData").addEventListener("click", () => { + exportConfig.element.querySelector("#exportData").addEventListener("click", async () => { /// #if BROWSER fetchPost("/api/export/exportData", {}, response => { window.location.href = response.data.zip; }); /// #else - const filePaths = dialog.showOpenDialogSync({ + const filePaths = await ipcRenderer.invoke(Constants.SIYUAN_DIALOG,{ + type: "showOpenDialogSync", title: window.siyuan.languages.export + " " + "Data", properties: ["createDirectory", "openDirectory"], }); @@ -209,7 +211,8 @@ export const exportConfig = { }); const pandocBinElement = exportConfig.element.querySelector("#pandocBin") as HTMLInputElement; pandocBinElement.addEventListener("click", async () => { - const localPath = await dialog.showOpenDialog({ + const localPath = await ipcRenderer.invoke(Constants.SIYUAN_DIALOG,{ + type: "showOpenDialog", defaultPath: window.siyuan.config.system.homeDir, properties: ["openFile"], }); diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts index 87dd29bd0..6b34c8fe7 100644 --- a/app/src/menus/navigation.ts +++ b/app/src/menus/navigation.ts @@ -643,6 +643,7 @@ export const genImportMenu = (notebookId: string, pathString: string) => { filters = [{name: "Markdown", extensions: ["md", "markdown"]}]; } const localPath = await ipcRenderer.invoke(Constants.SIYUAN_DIALOG, { + type: "showOpenDialog", defaultPath: window.siyuan.config.system.homeDir, filters, properties: [isDoc ? "openFile" : "openDirectory"], diff --git a/app/src/menus/util.ts b/app/src/menus/util.ts index 7338a6633..462270b4c 100644 --- a/app/src/menus/util.ts +++ b/app/src/menus/util.ts @@ -1,6 +1,5 @@ /// #if !BROWSER -import {dialog} from "@electron/remote"; -import {SaveDialogReturnValue} from "electron"; +import {ipcRenderer} from "electron"; import * as path from "path"; /// #endif import {fetchPost} from "../util/fetch"; @@ -17,15 +16,15 @@ export const exportAsset = (src: string) => { return { label: window.siyuan.languages.export, icon: "iconUpload", - click() { - dialog.showSaveDialog({ + async click() { + const result = await ipcRenderer.invoke(Constants.SIYUAN_DIALOG,{ + type: "showSaveDialog", defaultPath: getAssetName(src) + pathPosix().extname(src), properties: ["showOverwriteConfirmation"], - }).then((result: SaveDialogReturnValue) => { - if (!result.canceled) { - fetchPost("/api/file/copyFile", {src, dest: result.filePath}); - } }); + if (!result.canceled) { + fetchPost("/api/file/copyFile", {src, dest: result.filePath}); + } } }; /// #endif diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.ts index 41ee51035..982ce5160 100644 --- a/app/src/menus/workspace.ts +++ b/app/src/menus/workspace.ts @@ -1,6 +1,6 @@ import {MenuItem} from "./Menu"; /// #if !BROWSER -import {dialog, getCurrentWindow} from "@electron/remote"; +import {getCurrentWindow} from "@electron/remote"; import {ipcRenderer} from "electron"; /// #endif import {openHistory} from "../history/history"; @@ -85,7 +85,8 @@ export const workspaceMenu = (app: App, rect: DOMRect) => { label: `${window.siyuan.languages.new} / ${window.siyuan.languages.openBy}`, iconHTML: "", click: async () => { - const localPath = await dialog.showOpenDialog({ + const localPath = await ipcRenderer.invoke(Constants.SIYUAN_DIALOG,{ + type: "showOpenDialog", defaultPath: window.siyuan.config.system.homeDir, properties: ["openDirectory", "createDirectory"], }); diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index 0089f4d4b..1da273143 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -1,8 +1,8 @@ import {hideMessage, showMessage} from "../../dialog/message"; import {Constants} from "../../constants"; /// #if !BROWSER -import {ipcRenderer, OpenDialogReturnValue} from "electron"; -import {app, BrowserWindow, dialog, getCurrentWindow} from "@electron/remote"; +import {ipcRenderer} from "electron"; +import {app, BrowserWindow, getCurrentWindow} from "@electron/remote"; import * as fs from "fs"; import * as path from "path"; import {afterExport} from "./util"; @@ -527,7 +527,7 @@ const renderPDF = (id: string) => { const getExportPath = (option: { type: string, id: string }, removeAssets?: boolean, mergeSubdocs?: boolean) => { fetchPost("/api/block/getBlockInfo", { id: option.id - }, (response) => { + }, async (response) => { if (response.code === 3) { showMessage(response.msg); return; @@ -545,43 +545,43 @@ const getExportPath = (option: { type: string, id: string }, removeAssets?: bool break; } - dialog.showOpenDialog({ + const result = await ipcRenderer.invoke(Constants.SIYUAN_DIALOG, { + type: "showOpenDialog", title: window.siyuan.languages.export + " " + exportType, properties: ["createDirectory", "openDirectory"], - }).then((result: OpenDialogReturnValue) => { - if (!result.canceled) { - const msgId = showMessage(window.siyuan.languages.exporting, -1); - let url = "/api/export/exportHTML"; - if (option.type === "htmlmd") { - url = "/api/export/exportMdHTML"; - } else if (option.type === "word") { - url = "/api/export/exportDocx"; - } - let savePath = result.filePaths[0]; - if (option.type !== "word" && !savePath.endsWith(response.data.rootTitle)) { - savePath = path.join(savePath, replaceLocalPath(response.data.rootTitle)); - } - savePath = savePath.trim(); - fetchPost(url, { - id: option.id, - pdf: option.type === "pdf", - removeAssets: removeAssets, - merge: mergeSubdocs, - savePath - }, exportResponse => { - if (option.type === "word") { - if (exportResponse.code === 1) { - showMessage(exportResponse.msg, undefined, "error"); - hideMessage(msgId); - return; - } - afterExport(path.join(savePath, replaceLocalPath(response.data.rootTitle)) + ".docx", msgId); - } else { - onExport(exportResponse, savePath, option.type, removeAssets, msgId); - } - }); - } }); + if (!result.canceled) { + const msgId = showMessage(window.siyuan.languages.exporting, -1); + let url = "/api/export/exportHTML"; + if (option.type === "htmlmd") { + url = "/api/export/exportMdHTML"; + } else if (option.type === "word") { + url = "/api/export/exportDocx"; + } + let savePath = result.filePaths[0]; + if (option.type !== "word" && !savePath.endsWith(response.data.rootTitle)) { + savePath = path.join(savePath, replaceLocalPath(response.data.rootTitle)); + } + savePath = savePath.trim(); + fetchPost(url, { + id: option.id, + pdf: option.type === "pdf", + removeAssets: removeAssets, + merge: mergeSubdocs, + savePath + }, exportResponse => { + if (option.type === "word") { + if (exportResponse.code === 1) { + showMessage(exportResponse.msg, undefined, "error"); + hideMessage(msgId); + return; + } + afterExport(path.join(savePath, replaceLocalPath(response.data.rootTitle)) + ".docx", msgId); + } else { + onExport(exportResponse, savePath, option.type, removeAssets, msgId); + } + }); + } }); };