Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/boot/onGetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {sendGlobalShortcut} from "./globalEvent/keydown";
import {closeWindow} from "../window/closeWin";
import {correctHotkey} from "./globalEvent/commonHotkey";
import {recordBeforeResizeTop} from "../protyle/util/resize";
import {processSiYuanUri} from "../editor/openLink";
import {processSiYuanUri} from "../util/uri";
import {getAllEditor} from "../layout/getAll";

export const onGetConfig = (isStart: boolean, app: App) => {
Expand Down
8 changes: 8 additions & 0 deletions app/src/config/bazaar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export const mountBazaarTab = (root: HTMLElement, keywords?: string, app?: App)
}
};

/**
* 渲染集市 README
*/
export const renderReadme = (bazaarType: TBazaarType, from: "downloaded" | "updated" | "bazaar", data: IBazaarItem) => {
if (bazaar.element == null) return;
bazaar._renderReadme(bazaarType, from, data);
};

const bazaar = {
element: undefined as Element,
genHTML() {
Expand Down
38 changes: 37 additions & 1 deletion app/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import {bindSettingSaveDelegation} from "./setting/save";
import {Dialog} from "../dialog";
import {Constants} from "../constants";
import {focusByRange} from "../protyle/util/selection";
import {renderReadme} from "./bazaar";
import {fetchSyncPost} from "../util/fetch";
/// #endif
import type {TSettingTab} from "./setting/tabs";
import {getSettingTabDefs} from "./setting/tabs";
import {clearAccessTabElement} from "./tabs/accessRuntime";
import {clearSyncTabElement} from "./tabs/syncRuntime";
import type {TSettingTab} from "./setting/tabs";
import type {App} from "../index";

/// #if !MOBILE
Expand Down Expand Up @@ -80,3 +82,37 @@ export const openSetting = (app: App, tab?: TSettingTab) => {
return openSettingDialog(app, tab);
/// #endif
};

export const openBazaarReadme = async (app: App, bazaarType: TBazaarType, itemName: string) => {
/// #if !MOBILE
let getResourcesUrl: string;
switch (bazaarType) {
case "templates":
getResourcesUrl = "/api/bazaar/getBazaarTemplate";
break;
case "icons":
getResourcesUrl = "/api/bazaar/getBazaarIcon";
break;
case "widgets":
getResourcesUrl = "/api/bazaar/getBazaarWidget";
break;
case "themes":
getResourcesUrl = "/api/bazaar/getBazaarTheme";
break;
case "plugins":
getResourcesUrl = "/api/bazaar/getBazaarPlugin";
break;
default:
return;
}

const response = await fetchSyncPost(getResourcesUrl, {frontend: "all", keyword: itemName});
if (response.code !== 0) return;

const resource = (response.data.packages as IBazaarItem[]).find((item: IBazaarItem) => item.name === itemName);
if (!resource) return;

openSettingDialog(app, "bazaar");
renderReadme(bazaarType, "bazaar", resource);
/// #endif
};
121 changes: 6 additions & 115 deletions app/src/editor/openLink.ts
Original file line number Diff line number Diff line change
@@ -1,125 +1,16 @@
import {isLocalPath, isSiYuanUriProtocol, parseSiYuanUriInfo, pathPosix} from "../util/pathName";
import {isLocalPath, pathPosix} from "../util/pathName";
/// #if !BROWSER
import {shell, ipcRenderer} from "electron";
import {shell} from "electron";
/// #endif
import {getSearch} from "../util/functions";
import {Constants} from "../constants";
/// #if !MOBILE
import {openAsset, openBy, openFile, openFileById} from "./util";
/// #if MOBILE
import {processSiYuanUri} from "../util/uri";
/// #else
import {openAsset, openBy} from "./util";
/// #endif
import {showMessage} from "../dialog/message";
import {isInIOS, isInAndroid, isInHarmony} from "../protyle/util/compatibility";
import {fetchPost} from "../util/fetch";
import {checkFold} from "../util/noRelyPCFunction";
import {openMobileFileById} from "../mobile/editor";

import type {App} from "../index";

const processSiYuanUriBlocks = (app: App, uriObj: URL): boolean => {
const blockInfo = parseSiYuanUriInfo(uriObj);
if (blockInfo != null) {
const {id, focus} = blockInfo;
window.siyuan.editorIsFullscreen = blockInfo.fullscreen;
fetchPost("/api/block/checkBlockExist", { id }, existResponse => {
if (existResponse.data) {
checkFold(id, (zoomIn) => {
/// #if !MOBILE
openFileById({
app,
id,
action: (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: zoomIn || focus
});
/// #else
openMobileFileById(app, id, (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
/// #endif
});
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_CMD, "show");
/// #endif
}
app.plugins.forEach(plugin => {
plugin.eventBus.emit("open-siyuan-url-block", {
url: uriObj.href,
id,
focus,
exist: existResponse.data,
});
});
});
return true;
}
return false;
};

const processSiYuanUriPlugins = (app: App, uriObj: URL): boolean => {
const pluginNameOrTabType: string | null = (() => {
const name = uriObj.pathname.split("/")[1];
if (!name) {
return null;
}
try {
return decodeURIComponent(name);
} catch (error) {
return null;
}
})();

if (!pluginNameOrTabType) {
return false;
}

const plugin = app.plugins.find(plugin => pluginNameOrTabType === plugin.name);
if (plugin) {
// siyuan://plugins/plugin-name/foo?bar=baz
plugin.eventBus.emit("open-siyuan-url-plugin", { url: uriObj.href });
} else {
// siyuan://plugins/plugin-samplecustom_tab?title=自定义页签&icon=iconFace&data={"text": "This is the custom plugin tab I opened via protocol."}
/// #if !MOBILE
// https://github.com/siyuan-note/siyuan/pull/9256
const data = (() => {
try {
return JSON.parse(uriObj.searchParams.get("data") || "{}");
} catch (e) {
console.log("Error open plugin tab with protocol:", e);
return undefined;
}
})();
// id 不存在时无副作用
openFile({
app,
custom: {
title: uriObj.searchParams.get("title") ?? pluginNameOrTabType,
icon: uriObj.searchParams.get("icon") ?? "iconPlugin",
data,
id: pluginNameOrTabType
},
});
/// #endif
}
return true;
};

export const processSiYuanUri = (app: App, uri: string) => {
let uriObj: URL;
try {
uriObj = new URL(uri);
if (!isSiYuanUriProtocol(uriObj)) {
return false;
}
} catch (error) {
return false;
}
switch (uriObj.hostname) {
case "blocks":
return processSiYuanUriBlocks(app, uriObj);
case "plugins":
return processSiYuanUriPlugins(app, uriObj);
default:
break;
}
return false;
};

export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, ctrlIsPressed = false) => {
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
Expand Down
3 changes: 2 additions & 1 deletion app/src/layout/dock/agent/AgentMessageRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {escapeHtml} from "../../../util/escape";
import {processSiYuanUri} from "../../../util/uri";
import {highlightRender} from "../../../protyle/render/highlightRender";
import {mathRender} from "../../../protyle/render/mathRender";
import {mermaidRender} from "../../../protyle/render/mermaidRender";
Expand All @@ -10,8 +11,8 @@ import {abcRender} from "../../../protyle/render/abcRender";
import {plantumlRender} from "../../../protyle/render/plantumlRender";
import {htmlRender} from "../../../protyle/render/htmlRender";
import {showMessage} from "../../../dialog/message";

import type {App} from "../../../index";
import {processSiYuanUri} from "../../../editor/openLink";

export const renderTodoList = (result: string): string => {
const L = window.siyuan.languages;
Expand Down
5 changes: 2 additions & 3 deletions app/src/util/pathName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ export const parseSiYuanUriInfo = (uri: URL | string | null | undefined): ISiYua

export const parseUriInfo = (): ISiYuanUriBlockInfo => {
const searchParams = new URLSearchParams(window.location.search);
const PWAURL = searchParams.get("url");
if (/^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(PWAURL)) {
const dataInfo = parseSiYuanUriInfo(PWAURL);
if (searchParams.has("url")) {
const dataInfo = parseSiYuanUriInfo(searchParams.get("url"));
if (dataInfo != null) {
window.siyuan.editorIsFullscreen = dataInfo.fullscreen;
return dataInfo;
Expand Down
147 changes: 147 additions & 0 deletions app/src/util/uri.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import {isSiYuanUriProtocol, parseSiYuanUriInfo} from "./pathName";
/// #if !BROWSER
import {ipcRenderer} from "electron";
/// #endif
import {Constants} from "../constants";
/// #if !MOBILE
import {openFile, openFileById} from "../editor/util";
/// #endif
import {fetchPost} from "./fetch";
import {checkFold} from "./noRelyPCFunction";
import {openMobileFileById} from "../mobile/editor";

import type {App} from "../index";

const processSiYuanUriBlocks = (app: App, uriObj: URL): boolean => {
const blockInfo = parseSiYuanUriInfo(uriObj);
if (blockInfo != null) {
const {id, focus} = blockInfo;
window.siyuan.editorIsFullscreen = blockInfo.fullscreen;
fetchPost("/api/block/checkBlockExist", { id }, existResponse => {
if (existResponse.data) {
checkFold(id, (zoomIn) => {
/// #if !MOBILE
openFileById({
app,
id,
action: (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
zoomIn: zoomIn || focus
});
/// #else
openMobileFileById(app, id, (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
/// #endif
});
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_CMD, "show");
/// #endif
}
app.plugins.forEach(plugin => {
plugin.eventBus.emit("open-siyuan-url-block", {
url: uriObj.href,
id,
focus,
exist: existResponse.data,
});
});
});
return true;
}
return false;
};

const processSiYuanUriPlugins = (app: App, uriObj: URL): boolean => {
const pluginNameOrTabType: string | null = (() => {
const name = uriObj.pathname.split("/")[1];
if (!name) {
return null;
}
try {
return decodeURIComponent(name);
} catch (error) {
return null;
}
})();

if (!pluginNameOrTabType) {
return false;
}

const plugin = app.plugins.find(plugin => pluginNameOrTabType === plugin.name);
if (plugin) {
// siyuan://plugins/plugin-name/foo?bar=baz
plugin.eventBus.emit("open-siyuan-url-plugin", { url: uriObj.href });
} else {
// siyuan://plugins/plugin-samplecustom_tab?title=自定义页签&icon=iconFace&data={"text": "This is the custom plugin tab I opened via protocol."}
/// #if !MOBILE
// https://github.com/siyuan-note/siyuan/pull/9256
const data = (() => {
try {
return JSON.parse(uriObj.searchParams.get("data") || "{}");
} catch (e) {
console.log("Error open plugin tab with protocol:", e);
return undefined;
}
})();
// id 不存在时无副作用
openFile({
app,
custom: {
title: uriObj.searchParams.get("title") ?? pluginNameOrTabType,
icon: uriObj.searchParams.get("icon") ?? "iconPlugin",
data,
id: pluginNameOrTabType
},
});
/// #endif
}
return true;
};

const processSiYuanUriBazaar = (app: App, uriObj: URL): boolean => {
/// #if !MOBILE
const [, _type, _name, target] = uriObj.pathname.split("/");
if (!_type || !_name) return false;
const resourceType = _type as TBazaarType;
let resourceName: string;
try {
resourceName = decodeURIComponent(_name);
} catch {
return false;
}
switch (target) {
case "readme":
// siyuan://bazaar/plugins/plugin-sample/readme
(async () => {
const {openBazaarReadme} = await import("../config");
openBazaarReadme(app, resourceType, resourceName);
})();
return true;
default:
break;
}
/// #endif
return false;
};

export const processSiYuanUri = (app: App, uri: string) => {
let uriObj: URL;
try {
uriObj = new URL(uri);
if (!isSiYuanUriProtocol(uriObj)) {
return false;
}
} catch (error) {
return false;
}
switch (uriObj.hostname) {
case "blocks":
return processSiYuanUriBlocks(app, uriObj);
case "plugins":
return processSiYuanUriPlugins(app, uriObj);
case "bazaar":
return processSiYuanUriBazaar(app, uriObj);
default:
break;
}
return false;
};
2 changes: 1 addition & 1 deletion kernel/harmony/build-win.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export CFLAGS="-target x86_64-linux-ohos --sysroot=${OHOS_NDK_HOME}/native/sysro
export CXXFLAGS="-target x86_64-linux-ohos --sysroot=${OHOS_NDK_HOME}/native/sysroot -D__MUSL__"
export LLVMCONFIG=$OHOS_NDK_HOME/native/llvm/bin/llvm-config

export GOPROXY=https://mirrors.aliyun.com/goproxy/
export GOPROXY=https://mirrors.aliyun.com/goproxy/,https://goproxy.cn,direct
export CGO_ENABLED=1
export GOOS=android
export GOARCH=amd64
Expand Down
Loading