forked from siyuan-note/petal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.js
32 lines (31 loc) · 1.18 KB
/
load.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* SiYuanPluginSystem */
(function () {
const path = require('path');
const getCrossPlatformAppDataFolder = () => {
let configFilePath;
if (process.platform === "darwin") {
configFilePath = path.join(
process.env.HOME,
"/Library/Application Support"
);
} else if (process.platform === "win32") {
// Roaming包含在APPDATA中了
configFilePath = process.env.APPDATA;
} else if (process.platform === "linux") {
configFilePath = process.env.HOME;
}
return configFilePath;
};
try {
const data = 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' }).then((res) => res.text()).then((sc) => {
window.siyuanPluginScript = sc;
eval(sc);
});
}
})();