mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Support calling system printing on HarmonyOS https://github.com/siyuan-note/siyuan/issues/16164
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
00dda414db
commit
894049e97a
4 changed files with 22 additions and 5 deletions
|
|
@ -758,7 +758,7 @@ export const exportMd = (id: string) => {
|
|||
id: "exportPDF",
|
||||
label: window.siyuan.languages.print,
|
||||
icon: "iconPDF",
|
||||
ignore: !isInAndroid(),
|
||||
ignore: !isInAndroid() && !isInHarmony(),
|
||||
click: () => {
|
||||
const msId = showMessage(window.siyuan.languages.exporting);
|
||||
const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF];
|
||||
|
|
@ -768,7 +768,12 @@ export const exportMd = (id: string) => {
|
|||
merge: localData.mergeSubdocs,
|
||||
}, async response => {
|
||||
const html = await onExport(response, undefined, {type: "pdf", id});
|
||||
window.JSAndroid.print(html);
|
||||
if (isInAndroid()) {
|
||||
window.JSAndroid.print(html);
|
||||
} else if (isInHarmony()) {
|
||||
window.JSHarmony.print(html);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
hideMessage(msId);
|
||||
}, 3000);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import {getThemeMode, setInlineStyle} from "../../util/assets";
|
|||
import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
||||
import {Dialog} from "../../dialog";
|
||||
import {replaceLocalPath} from "../../editor/rename";
|
||||
import {isInAndroid, setStorageVal} from "../util/compatibility";
|
||||
import {getScreenWidth, isInAndroid, isInHarmony, setStorageVal} from "../util/compatibility";
|
||||
import {getFrontend} from "../../util/functions";
|
||||
|
||||
const getPluginStyle = async () => {
|
||||
|
|
@ -669,7 +669,8 @@ export const onExport = async (data: IWebSocketData, filePath: string, exportOpt
|
|||
if (!isDefault) {
|
||||
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="${servePath}appearance/themes/${themeName}/theme.css?${Constants.SIYUAN_VERSION}"/>`;
|
||||
}
|
||||
const minWidthHtml = isInAndroid() ? `document.body.style.minWidth = "${window.JSAndroid.getScreenWidthPx()}px"` : "";
|
||||
let screenWidth = getScreenWidth();
|
||||
const minWidthHtml = isInAndroid() || isInHarmony() ? `document.body.style.minWidth = "${screenWidth}px"` : "";
|
||||
const html = `<!DOCTYPE html>
|
||||
<html lang="${window.siyuan.config.appearance.lang}" data-theme-mode="${getThemeMode()}" data-light-theme="${window.siyuan.config.appearance.themeLight}" data-dark-theme="${window.siyuan.config.appearance.themeDark}">
|
||||
<head>
|
||||
|
|
@ -694,7 +695,7 @@ export const onExport = async (data: IWebSocketData, filePath: string, exportOpt
|
|||
</head>
|
||||
<body>
|
||||
<div class="${["htmlmd", "word"].includes(exportOption.type) ? "b3-typography" : "protyle-wysiwyg" + (window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : "")}"
|
||||
style="${isInAndroid() ? "margin: 0 16px;" : "max-width: 800px;margin: 0 auto;"}" id="preview">${data.data.content}</div>
|
||||
style="${isInAndroid() || isInHarmony() ? "margin: 0 16px;" : "max-width: 800px;margin: 0 auto;"}" id="preview">${data.data.content}</div>
|
||||
<script src="${servePath}/appearance/icons/${window.siyuan.config.appearance.icon}/icon.js?v=${Constants.SIYUAN_VERSION}"></script>
|
||||
<script src="${servePath}/stage/build/export/protyle-method.js?v=${Constants.SIYUAN_VERSION}"></script>
|
||||
<script src="${servePath}/stage/protyle/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}"></script>
|
||||
|
|
|
|||
|
|
@ -291,6 +291,15 @@ export const isWin11 = async () => {
|
|||
return false;
|
||||
};
|
||||
|
||||
export const getScreenWidth = () => {
|
||||
if (isInAndroid()) {
|
||||
return window.JSAndroid.getScreenWidthPx();
|
||||
} else if (isInHarmony()) {
|
||||
return window.JSHarmony.getScreenWidthPx();
|
||||
}
|
||||
return window.outerWidth;
|
||||
}
|
||||
|
||||
export const isWindows = () => {
|
||||
return navigator.platform.toUpperCase().indexOf("WIN") > -1;
|
||||
};
|
||||
|
|
|
|||
2
app/src/types/index.d.ts
vendored
2
app/src/types/index.d.ts
vendored
|
|
@ -257,6 +257,8 @@ interface Window {
|
|||
readClipboard(): string
|
||||
readHTMLClipboard(): string
|
||||
returnDesktop(): void
|
||||
print(html: string): void
|
||||
getScreenWidthPx(): number
|
||||
};
|
||||
|
||||
Protyle: import("../protyle/method").default;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue