diff --git a/public/lib/plugin/plugin-system/plugin-system-hook.js b/public/lib/plugin/plugin-system/plugin-system-hook.js index 35879c28..7ee72b7d 100644 --- a/public/lib/plugin/plugin-system/plugin-system-hook.js +++ b/public/lib/plugin/plugin-system/plugin-system-hook.js @@ -26,6 +26,14 @@ // 警告1⚠️:请勿在非思源笔记Electron环境调用此文件中的任何方法 // 警告2⚠️:此文件请勿引用其他任何需要编译的类库 +const log = (...p) => { + console.log(`[zhi-hook] plugin-system-hook`, ...p) +} + +const warn = (...p) => { + console.warn(`[zhi-hook] theme`, ...p) +} + const getCrossPlatformAppDataFolder = () => { const path = window.require("path") @@ -45,30 +53,46 @@ const getCrossPlatformAppDataFolder = () => { } const initPluginSystem = async () => { - const path = window.require("path") - try { - const data = window - .require("fs") - .readFileSync( - path.join(getCrossPlatformAppDataFolder(), ".siyuan", "plugin.js") - ) - const script = data.toString("utf8") - console.log("local plugin system found, loading...") - eval(script) - } catch (e) { - console.log("local plugin system not found, load online") - return fetch( - "https://gitee.com/zuoez02/siyuan-plugin-system/raw/main/main.js", - { cache: "no-cache" } + const path = window.require("path") + try { + const data = window + .require("fs") + .readFileSync( + path.join(getCrossPlatformAppDataFolder(), ".siyuan", "plugin.js") ) - .then((res) => res.text()) - .then((sc) => { - window.siyuanPluginScript = sc - eval(sc) - }) - } + const script = data.toString("utf8") + log("local plugin system found, loading...") + eval(script) + } catch (e) { + log("local plugin system not found, load online") + return fetch( + "https://gitee.com/zuoez02/siyuan-plugin-system/raw/main/main.js", + { cache: "no-cache" } + ) + .then((res) => res.text()) + .then((sc) => { + window.siyuanPluginScript = sc + eval(sc) + }) } +} + +const syncZhiPlugins = async () => { + log("Start syncing zhi plugin ", "xxx") +} ;(async () => { - await initPluginSystem() + if (!window.pluginSystem) { + log("Undetected plugin system,initiating plugin system...") + await initPluginSystem() + } else { + warn( + "Plugin system already loaded by snapshots, ignore initiation!Loaded plugin system version is ", + window.pluginSystemVersion + ) + } + + log("Plugin system initiation finished,syncing zhi theme plugins...") + await syncZhiPlugins() + log("Syncing zhi theme plugins finished.") })() diff --git a/theme.js b/theme.js index fb4426c7..d186b211 100644 --- a/theme.js +++ b/theme.js @@ -31,6 +31,18 @@ // 警告1⚠️:思源笔记启动会自动加载此文件,请勿调用此文件中的任何方法 // 警告2⚠️:此文件请勿引用其他任何需要编译的类库 +const log = (...p) => { + console.log(`[zhi-hook] theme`, ...p) +} + +const warn = (...p) => { + console.warn(`[zhi-hook] theme`, ...p) +} + +const error = (...p) => { + console.error(`[zhi-hook] theme`, ...p) +} + /** * 获取zhi主题构建路径目录 * @@ -62,14 +74,14 @@ const safeImport = async (libpath) => { try { if (!fs.existsSync(realpath)) { - console.warn("依赖库不存在,请排查。依赖库路径=>", realpath) + warn("Dependency not found, path is=>", libpath) return } - console.log("将要从以下位置引入依赖=>", libpath) await import(libpath) + log("Loaded dependency=>", libpath) } catch (e) { - console.error("依赖库加载失败,请排查。依赖库路径=>", realpath) - console.error(e) + error("Failed to load dependency!Dependency path=>", libpath) + error(e) } }