add import to api
This commit is contained in:
parent
1f1d748687
commit
9a652e3748
|
@ -99,4 +99,10 @@ export default class PluginApi {
|
||||||
return plugin.exports;
|
return plugin.exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import(m) {
|
||||||
|
const module = PluginManager.findPlugin(m);
|
||||||
|
if (module && module.__require) return module.__require;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,32 @@ import Vendor from './vendor';
|
||||||
import { ClientLogger as Logger } from 'common';
|
import { ClientLogger as Logger } from 'common';
|
||||||
import { Events } from 'modules';
|
import { Events } from 'modules';
|
||||||
|
|
||||||
|
class Module {
|
||||||
|
|
||||||
|
constructor(pluginInternals) {
|
||||||
|
this.__pluginInternals = pluginInternals;
|
||||||
|
this.__require = window.require(this.paths.mainPath);
|
||||||
|
this.hasSettings = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
get type() { return 'module' }
|
||||||
|
get configs() { return this.__pluginInternals.configs }
|
||||||
|
get info() { return this.__pluginInternals.info }
|
||||||
|
get icon() { return this.info.icon }
|
||||||
|
get paths() { return this.__pluginInternals.paths }
|
||||||
|
get main() { return this.__pluginInternals.main }
|
||||||
|
get defaultConfig() { return this.configs.defaultConfig }
|
||||||
|
get userConfig() { return this.configs.userConfig }
|
||||||
|
get id() { return this.info.id || this.info.name.replace(/[^a-zA-Z0-9-]/g, '-').replace(/--/g, '-') }
|
||||||
|
get name() { return this.info.name }
|
||||||
|
get authors() { return this.info.authors }
|
||||||
|
get version() { return this.info.version }
|
||||||
|
get pluginPath() { return this.paths.contentPath }
|
||||||
|
get dirName() { return this.paths.dirName }
|
||||||
|
get enabled() { return true }
|
||||||
|
get pluginConfig() { return this.userConfig.config || [] }
|
||||||
|
}
|
||||||
|
|
||||||
export default class extends ContentManager {
|
export default class extends ContentManager {
|
||||||
|
|
||||||
static get localPlugins() {
|
static get localPlugins() {
|
||||||
|
@ -38,17 +64,11 @@ export default class extends ContentManager {
|
||||||
|
|
||||||
static get loadContent() { return this.loadPlugin }
|
static get loadContent() { return this.loadPlugin }
|
||||||
static async loadPlugin(paths, configs, info, main, type) {
|
static async loadPlugin(paths, configs, info, main, type) {
|
||||||
if (type === 'module') return {
|
|
||||||
paths,
|
if (type === 'module') return new Module({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName, mainPath: paths.mainPath } });
|
||||||
configs,
|
|
||||||
info,
|
|
||||||
main,
|
|
||||||
type,
|
|
||||||
module: window.require(paths.mainPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
const plugin = window.require(paths.mainPath)(Plugin, new PluginApi(info), Vendor);
|
const plugin = window.require(paths.mainPath)(Plugin, new PluginApi(info), Vendor);
|
||||||
const instance = new plugin({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName } });
|
const instance = new plugin({ configs, info, main, paths: { contentPath: paths.contentPath, dirName: paths.dirName, mainPath: paths.mainPath } });
|
||||||
|
|
||||||
if (instance.enabled) instance.start();
|
if (instance.enabled) instance.start();
|
||||||
return instance;
|
return instance;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Card :item="plugin">
|
<Card :item="plugin">
|
||||||
<SettingSwitch slot="toggle" :checked="plugin.enabled" :change="() => plugin.enabled ? plugin.stop() : plugin.start()" />
|
<SettingSwitch v-if="plugin.type === 'plugin'" slot="toggle" :checked="plugin.enabled" :change="() => plugin.enabled ? plugin.stop() : plugin.start()" />
|
||||||
<ButtonGroup slot="controls">
|
<ButtonGroup slot="controls">
|
||||||
<Button v-tooltip="'Settings'" v-if="plugin.hasSettings" :onClick="() => showSettings(plugin)">
|
<Button v-tooltip="'Settings'" v-if="plugin.hasSettings" :onClick="() => showSettings(plugin)">
|
||||||
<MiSettings size="18" />
|
<MiSettings size="18" />
|
||||||
|
|
Loading…
Reference in New Issue