Skip to content

Commit 894049e

Browse files
committed
🎨 Support calling system printing on HarmonyOS siyuan-note#16164
Signed-off-by: Daniel <[email protected]>
1 parent 00dda41 commit 894049e

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

app/src/menus/commonMenuItem.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ export const exportMd = (id: string) => {
758758
id: "exportPDF",
759759
label: window.siyuan.languages.print,
760760
icon: "iconPDF",
761-
ignore: !isInAndroid(),
761+
ignore: !isInAndroid() && !isInHarmony(),
762762
click: () => {
763763
const msId = showMessage(window.siyuan.languages.exporting);
764764
const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF];
@@ -768,7 +768,12 @@ export const exportMd = (id: string) => {
768768
merge: localData.mergeSubdocs,
769769
}, async response => {
770770
const html = await onExport(response, undefined, {type: "pdf", id});
771-
window.JSAndroid.print(html);
771+
if (isInAndroid()) {
772+
window.JSAndroid.print(html);
773+
} else if (isInHarmony()) {
774+
window.JSHarmony.print(html);
775+
}
776+
772777
setTimeout(() => {
773778
hideMessage(msId);
774779
}, 3000);

app/src/protyle/export/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {getThemeMode, setInlineStyle} from "../../util/assets";
1111
import {fetchPost, fetchSyncPost} from "../../util/fetch";
1212
import {Dialog} from "../../dialog";
1313
import {replaceLocalPath} from "../../editor/rename";
14-
import {isInAndroid, setStorageVal} from "../util/compatibility";
14+
import {getScreenWidth, isInAndroid, isInHarmony, setStorageVal} from "../util/compatibility";
1515
import {getFrontend} from "../../util/functions";
1616

1717
const getPluginStyle = async () => {
@@ -669,7 +669,8 @@ export const onExport = async (data: IWebSocketData, filePath: string, exportOpt
669669
if (!isDefault) {
670670
themeStyle = `<link rel="stylesheet" type="text/css" id="themeStyle" href="${servePath}appearance/themes/${themeName}/theme.css?${Constants.SIYUAN_VERSION}"/>`;
671671
}
672-
const minWidthHtml = isInAndroid() ? `document.body.style.minWidth = "${window.JSAndroid.getScreenWidthPx()}px"` : "";
672+
let screenWidth = getScreenWidth();
673+
const minWidthHtml = isInAndroid() || isInHarmony() ? `document.body.style.minWidth = "${screenWidth}px"` : "";
673674
const html = `<!DOCTYPE html>
674675
<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}">
675676
<head>
@@ -694,7 +695,7 @@ export const onExport = async (data: IWebSocketData, filePath: string, exportOpt
694695
</head>
695696
<body>
696697
<div class="${["htmlmd", "word"].includes(exportOption.type) ? "b3-typography" : "protyle-wysiwyg" + (window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : "")}"
697-
style="${isInAndroid() ? "margin: 0 16px;" : "max-width: 800px;margin: 0 auto;"}" id="preview">${data.data.content}</div>
698+
style="${isInAndroid() || isInHarmony() ? "margin: 0 16px;" : "max-width: 800px;margin: 0 auto;"}" id="preview">${data.data.content}</div>
698699
<script src="${servePath}/appearance/icons/${window.siyuan.config.appearance.icon}/icon.js?v=${Constants.SIYUAN_VERSION}"></script>
699700
<script src="${servePath}/stage/build/export/protyle-method.js?v=${Constants.SIYUAN_VERSION}"></script>
700701
<script src="${servePath}/stage/protyle/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}"></script>

app/src/protyle/util/compatibility.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ export const isWin11 = async () => {
291291
return false;
292292
};
293293

294+
export const getScreenWidth = () => {
295+
if (isInAndroid()) {
296+
return window.JSAndroid.getScreenWidthPx();
297+
} else if (isInHarmony()) {
298+
return window.JSHarmony.getScreenWidthPx();
299+
}
300+
return window.outerWidth;
301+
}
302+
294303
export const isWindows = () => {
295304
return navigator.platform.toUpperCase().indexOf("WIN") > -1;
296305
};

app/src/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ interface Window {
257257
readClipboard(): string
258258
readHTMLClipboard(): string
259259
returnDesktop(): void
260+
print(html: string): void
261+
getScreenWidthPx(): number
260262
};
261263

262264
Protyle: import("../protyle/method").default;

0 commit comments

Comments
 (0)