🎨 Support HarmonyOS NEXT system https://github.com/siyuan-note/siyuan/issues/13184
This commit is contained in:
parent
535db65bf6
commit
2df3baf92a
7 changed files with 39 additions and 11 deletions
|
@ -172,9 +172,12 @@ export const openEditorTab = (app: App, ids: string[], notebookId?: string, path
|
|||
};
|
||||
|
||||
export const copyPNGByLink = (link: string) => {
|
||||
if (isInAndroid() || isInHarmony()) {
|
||||
if (isInAndroid()) {
|
||||
window.JSAndroid.writeImageClipboard(link);
|
||||
return;
|
||||
} else if (isInHarmony()) {
|
||||
window.JSHarmony.writeImageClipboard(link);
|
||||
return;
|
||||
} else {
|
||||
const canvas = document.createElement("canvas");
|
||||
const tempElement = document.createElement("img");
|
||||
|
|
|
@ -34,7 +34,7 @@ class App {
|
|||
public appId: string;
|
||||
|
||||
constructor() {
|
||||
if (!window.webkit?.messageHandlers && !window.JSAndroid) {
|
||||
if (!window.webkit?.messageHandlers && !window.JSAndroid && !window.JSHarmony) {
|
||||
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
||||
}
|
||||
addBaseURL();
|
||||
|
|
|
@ -1653,8 +1653,10 @@ export class Gutter {
|
|||
label: `${window.siyuan.languages.copy} ${window.siyuan.languages.headings1}`,
|
||||
click() {
|
||||
fetchPost("/api/block/getHeadingChildrenDOM", {id}, (response) => {
|
||||
if (isInAndroid() || isInHarmony()) {
|
||||
if (isInAndroid()) {
|
||||
window.JSAndroid.writeHTMLClipboard(protyle.lute.BlockDOM2StdMd(response.data).trimEnd(), response.data + Constants.ZWSP);
|
||||
} else if (isInHarmony()) {
|
||||
window.JSHarmony.writeHTMLClipboard(protyle.lute.BlockDOM2StdMd(response.data).trimEnd(), response.data + Constants.ZWSP);
|
||||
} else {
|
||||
writeText(response.data + Constants.ZWSP);
|
||||
}
|
||||
|
@ -1667,8 +1669,10 @@ export class Gutter {
|
|||
label: `${window.siyuan.languages.cut} ${window.siyuan.languages.headings1}`,
|
||||
click() {
|
||||
fetchPost("/api/block/getHeadingChildrenDOM", {id}, (response) => {
|
||||
if (isInAndroid() || isInHarmony()) {
|
||||
if (isInAndroid()) {
|
||||
window.JSAndroid.writeHTMLClipboard(protyle.lute.BlockDOM2StdMd(response.data).trimEnd(), response.data + Constants.ZWSP);
|
||||
} else if (isInHarmony()) {
|
||||
window.JSHarmony.writeHTMLClipboard(protyle.lute.BlockDOM2StdMd(response.data).trimEnd(), response.data + Constants.ZWSP);
|
||||
} else {
|
||||
writeText(response.data + Constants.ZWSP);
|
||||
}
|
||||
|
|
|
@ -21,16 +21,20 @@ export const openByMobile = (uri: string) => {
|
|||
window.webkit.messageHandlers.openLink.postMessage("https://" + uri);
|
||||
}
|
||||
}
|
||||
} else if (isInAndroid() || isInHarmony()) {
|
||||
} else if (isInAndroid()) {
|
||||
window.JSAndroid.openExternal(uri);
|
||||
} else if (isInHarmony()) {
|
||||
window.JSHarmony.openExternal(uri);
|
||||
} else {
|
||||
window.open(uri);
|
||||
}
|
||||
};
|
||||
|
||||
export const readText = () => {
|
||||
if (isInAndroid() || isInHarmony()) {
|
||||
if (isInAndroid()) {
|
||||
return window.JSAndroid.readClipboard();
|
||||
} else if (isInHarmony()) {
|
||||
return window.JSHarmony.readClipboard();
|
||||
}
|
||||
return navigator.clipboard.readText();
|
||||
};
|
||||
|
@ -42,10 +46,14 @@ export const writeText = (text: string) => {
|
|||
}
|
||||
try {
|
||||
// navigator.clipboard.writeText 抛出异常不进入 catch,这里需要先处理移动端复制
|
||||
if (isInAndroid() || isInHarmony()) {
|
||||
if (isInAndroid()) {
|
||||
window.JSAndroid.writeClipboard(text);
|
||||
return;
|
||||
}
|
||||
if (isInHarmony()) {
|
||||
window.JSHarmony.writeClipboard(text);
|
||||
return;
|
||||
}
|
||||
if (isInIOS()) {
|
||||
window.webkit.messageHandlers.setClipboard.postMessage(text);
|
||||
return;
|
||||
|
@ -54,8 +62,10 @@ export const writeText = (text: string) => {
|
|||
} catch (e) {
|
||||
if (isInIOS()) {
|
||||
window.webkit.messageHandlers.setClipboard.postMessage(text);
|
||||
} else if (isInAndroid() || isInHarmony()) {
|
||||
} else if (isInAndroid()) {
|
||||
window.JSAndroid.writeClipboard(text);
|
||||
} else if (isInHarmony()) {
|
||||
window.JSHarmony.writeClipboard(text);
|
||||
} else {
|
||||
const textElement = document.createElement("textarea");
|
||||
textElement.value = text;
|
||||
|
@ -137,7 +147,7 @@ export const isInIOS = () => {
|
|||
};
|
||||
|
||||
export const isInHarmony = () => {
|
||||
return window.siyuan.config.system.container === "harmony";
|
||||
return window.siyuan.config.system.container === "harmony" && window.JSHarmony;
|
||||
}
|
||||
|
||||
// Mac,Windows 快捷键展示
|
||||
|
|
9
app/src/types/index.d.ts
vendored
9
app/src/types/index.d.ts
vendored
|
@ -178,6 +178,15 @@ interface Window {
|
|||
readClipboard(): string
|
||||
getBlockURL(): string
|
||||
}
|
||||
JSHarmony: {
|
||||
openExternal(url: string): void
|
||||
changeStatusBarColor(color: string, mode: number): void
|
||||
writeClipboard(text: string): void
|
||||
writeHTMLClipboard(text: string, html: string): void
|
||||
writeImageClipboard(uri: string): void
|
||||
readClipboard(): string
|
||||
getBlockURL(): string
|
||||
}
|
||||
|
||||
Protyle: import("../protyle/method").default
|
||||
|
||||
|
|
|
@ -342,8 +342,10 @@ const updateMobileTheme = (OSTheme: string) => {
|
|||
}
|
||||
if (isInIOS()) {
|
||||
window.webkit.messageHandlers.changeStatusBar.postMessage((backgroundColor || (mode === 0 ? "#fff" : "#1e1e1e")) + " " + mode);
|
||||
} else if (isInAndroid() || isInHarmony()) {
|
||||
} else if (isInAndroid()) {
|
||||
window.JSAndroid.changeStatusBarColor(backgroundColor, mode);
|
||||
} else if ( isInHarmony()) {
|
||||
window.JSHarmony.changeStatusBarColor(backgroundColor, mode);
|
||||
}
|
||||
}, 500); // 移动端需要加载完才可以获取到颜色
|
||||
}
|
||||
|
|
|
@ -416,7 +416,7 @@
|
|||
const {ipcRenderer} = require('electron')
|
||||
ipcRenderer.send('siyuan-quit', window.location.port)
|
||||
} catch (e) {
|
||||
if ((window.webkit && window.webkit.messageHandlers) || window.JSAndroid) {
|
||||
if ((window.webkit && window.webkit.messageHandlers) || window.JSAndroid || window.JSHarmony) {
|
||||
window.location.href = 'siyuan://api/system/exit'
|
||||
} else {
|
||||
window.location.reload()
|
||||
|
|
Loading…
Add table
Reference in a new issue