mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
This commit is contained in:
parent
844c5ce688
commit
ec65118339
6 changed files with 56 additions and 52 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue