Vanessa 2024-03-14 12:41:08 +08:00
parent d1009f2333
commit 60beaf291d
3 changed files with 94 additions and 35 deletions

View file

@ -6,6 +6,8 @@ import {Constants} from "../constants";
import {Tab} from "../layout/Tab";
import {fetchPost} from "../util/fetch";
import {showMessage} from "../dialog/message";
import {getDisplayName, pathPosix} from "../util/pathName";
import {getSearch} from "../util/functions";
interface windowOptions {
position?: {
@ -62,5 +64,39 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
});
/// #endif
});
};
export const openAssetNewWindow = (assetPath: string, options: windowOptions = {}) => {
/// #if !BROWSER
const suffix = pathPosix().extname(assetPath.split("?page")[0]);
if (Constants.SIYUAN_ASSETS_EXTS.includes(suffix)) {
let docIcon = "iconPDF";
if (Constants.SIYUAN_ASSETS_IMAGE.includes(suffix)) {
docIcon = "iconImage";
} else if (Constants.SIYUAN_ASSETS_AUDIO.includes(suffix)) {
docIcon = "iconRecord";
} else if (Constants.SIYUAN_ASSETS_VIDEO.includes(suffix)) {
docIcon = "iconVideo";
}
const json: any = {
title: getDisplayName(assetPath),
docIcon,
pin: false,
active: true,
instance: "Tab",
action: "Tab",
children: {
path: assetPath,
page: parseInt(getSearch("page", assetPath)),
instance: "Asset",
}
};
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
position: options.position,
width: options.width,
height: options.height,
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
});
}
/// #endif
};