diff --git a/app/src/config/exportConfig.ts b/app/src/config/exportConfig.ts index da7aedaad..330db9289 100644 --- a/app/src/config/exportConfig.ts +++ b/app/src/config/exportConfig.ts @@ -166,8 +166,7 @@ export const exportConfig = { fetchPost("/api/export/exportDataInFolder", { folder: result.filePath }, () => { - hideMessage(id); - afterExport(result.filePath); + afterExport(result.filePath, id); }); } }); diff --git a/app/src/dialog/message.ts b/app/src/dialog/message.ts index 69ed6ed6f..8ec9b39b4 100644 --- a/app/src/dialog/message.ts +++ b/app/src/dialog/message.ts @@ -33,15 +33,23 @@ export const showMessage = (message: string, timeout = 6000, type = "info", mess const existElement = messagesElement.querySelector(`.b3-snackbar[data-id="${id}"]`) if (existElement) { existElement.firstElementChild.innerHTML = message; + window.clearTimeout(parseInt(existElement.getAttribute("data-timeoutid"))); + if (timeout > 0) { + const timeoutId = window.setTimeout(() => { + hideMessage(id); + }, timeout); + existElement.setAttribute("data-timeoutid", timeoutId.toString()); + } return; } let messageHTML = `
${message}
`; if (timeout === 0) { messageHTML += ''; } else if (timeout !== -1) { // -1 时需等待请求完成后手动关闭 - window.setTimeout(() => { + const timeoutId = window.setTimeout(() => { hideMessage(id); }, timeout); + messageHTML.replace("
{ export const exitSiYuan = () => { fetchPost("/api/system/exit", {force: false}, (response) => { if (response.code === 1) { - showMessage(response.msg, response.data.closeTimeout, "error"); - const buttonElement = document.querySelector("#message button"); + const msgId = showMessage(response.msg, response.data.closeTimeout, "error"); + const buttonElement = document.querySelector(`#message [data-id="${msgId}"] button`); if (buttonElement) { buttonElement.addEventListener("click", () => { fetchPost("/api/system/exit", {force: true}, () => { diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index 3f882266c..fc299163d 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -138,11 +138,10 @@ const getExportPath = (option: { type: string, id: string }, pdfOption?: PrintTo pdf: option.type === "pdf", savePath: result.filePath }, exportResponse => { - hideMessage(id); if (option.type === "word") { - afterExport(result.filePath); + afterExport(result.filePath, id); } else { - onExport(exportResponse, result.filePath, option.type, pdfOption, removeAssets); + onExport(exportResponse, result.filePath, option.type, pdfOption, removeAssets, id); } }); } @@ -150,7 +149,7 @@ const getExportPath = (option: { type: string, id: string }, pdfOption?: PrintTo }); }; -const onExport = (data: IWebSocketData, filePath: string, type: string, pdfOptions?: PrintToPDFOptions, removeAssets?: boolean) => { +const onExport = (data: IWebSocketData, filePath: string, type: string, pdfOptions?: PrintToPDFOptions, removeAssets?: boolean, msgId?:string) => { let themeName = window.siyuan.config.appearance.themeLight; let mode = 0; if (["html", "htmlmd"].includes(type) && window.siyuan.config.appearance.mode === 1) { @@ -319,7 +318,7 @@ pre code { id: data.data.id, path: pdfFilePath }, () => { - afterExport(pdfFilePath); + afterExport(pdfFilePath, msgId); if (removeAssets) { const removePromise = (dir: string) => { return new Promise(function (resolve) { @@ -354,7 +353,7 @@ pre code { } else { const htmlPath = path.join(filePath, "index.html"); fs.writeFileSync(htmlPath, html); - afterExport(htmlPath); + afterExport(htmlPath, msgId); } }; /// #endif diff --git a/app/src/protyle/export/util.ts b/app/src/protyle/export/util.ts index dd535bc56..6e1a66e62 100644 --- a/app/src/protyle/export/util.ts +++ b/app/src/protyle/export/util.ts @@ -4,16 +4,13 @@ import {escapeHtml} from "../../util/escape"; import {shell} from "electron"; import * as path from "path"; -export const afterExport = (exportPath: string) => { - const id = showMessage(`
-
${window.siyuan.languages.exported}${escapeHtml(exportPath)}
-
-
- -
`, 6000); - document.querySelector("#message button").addEventListener("click", () => { +export const afterExport = (exportPath: string, msgId: string) => { + showMessage(`${window.siyuan.languages.exported}${escapeHtml(exportPath)} +
+`, 6000, "info", msgId); + document.querySelector(`#message [data-id="${msgId}"] button`).addEventListener("click", () => { shell.showItemInFolder(path.join(exportPath)); - hideMessage(id); + hideMessage(msgId); }); }; /// #endif