mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-10 17:24:21 +01:00
This commit is contained in:
parent
875f00398e
commit
99725ea21d
14 changed files with 122 additions and 40 deletions
|
|
@ -1,20 +1,26 @@
|
|||
import {App} from "../index";
|
||||
import {EventBus} from "./EventBus";
|
||||
import {fetchPost} from "../util/fetch";
|
||||
|
||||
export class Plugin {
|
||||
public i18n: IObject;
|
||||
public eventBus: EventBus;
|
||||
public data: any = {};
|
||||
public name: string;
|
||||
|
||||
constructor(options: {
|
||||
app: App,
|
||||
id: string,
|
||||
name: string,
|
||||
i18n: IObject
|
||||
}) {
|
||||
this.i18n = options.i18n;
|
||||
this.name = options.name;
|
||||
this.eventBus = new EventBus(options.name);
|
||||
}
|
||||
|
||||
public onload() {
|
||||
}
|
||||
|
||||
public addTopBar(options: {
|
||||
icon: string,
|
||||
title: string,
|
||||
|
|
@ -31,7 +37,36 @@ export class Plugin {
|
|||
return iconElement;
|
||||
}
|
||||
|
||||
public onload() {
|
||||
console.log("Hello, world!");
|
||||
public openSetting() {
|
||||
}
|
||||
|
||||
public loadData(storageName: string) {
|
||||
if (typeof this.data[storageName] === "undefined") {
|
||||
this.data[storageName] = "";
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
fetchPost("/api/file/getFile", {path: `/data/storage/petal/${this.name}/${storageName}`}, (response) => {
|
||||
if (response.code === 404) {
|
||||
this.data[storageName] = "";
|
||||
} else {
|
||||
this.data[storageName] = response;
|
||||
}
|
||||
resolve(this.data[storageName]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public saveData(storageName: string, data: any) {
|
||||
return new Promise((resolve) => {
|
||||
const pathString = `/data/storage/petal/${this.name}/${storageName}`;
|
||||
const file = new File([new Blob([data])], pathString.split('/').pop());
|
||||
const formData = new FormData();
|
||||
formData.append('path', pathString);
|
||||
formData.append('file', file);
|
||||
formData.append('isDir', "false");
|
||||
fetchPost("/api/file/putFile", formData, (response) => {
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const runCode = (code: string, sourceURL: string) => {
|
|||
export const loadPlugins = (app: App) => {
|
||||
fetchPost("/api/petal/loadPetals", {}, response => {
|
||||
let css = "";
|
||||
response.data.forEach((item: { id: string, name: string, js: string, css: string, i18n: IObject }) => {
|
||||
response.data.forEach((item: { name: string, js: string, css: string, i18n: IObject }) => {
|
||||
const exportsObj: { [key: string]: any } = {};
|
||||
const moduleObj = {exports: exportsObj};
|
||||
try {
|
||||
|
|
@ -39,7 +39,6 @@ export const loadPlugins = (app: App) => {
|
|||
const plugin = new pluginClass({
|
||||
app,
|
||||
name: item.name,
|
||||
id: item.id,
|
||||
i18n: item.i18n
|
||||
});
|
||||
app.plugins.push(plugin);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue