diff --git a/packages/core/src/app.ts b/packages/core/src/app.ts index 70e23ab439..40fc0147f8 100644 --- a/packages/core/src/app.ts +++ b/packages/core/src/app.ts @@ -25,7 +25,6 @@ export class App extends Context { _shortcuts: Command.Shortcut[] = [] _hooks: Record any][]> = {} _sessions: Dict = Object.create(null) - _services: Dict = Object.create(null) _userCache = new SharedCache>() _channelCache = new SharedCache>() diff --git a/packages/core/src/context.ts b/packages/core/src/context.ts index 02649b9202..ef02e2c8c8 100644 --- a/packages/core/src/context.ts +++ b/packages/core/src/context.ts @@ -586,8 +586,11 @@ export namespace Context { model: Model } + export const Services: (keyof Services)[] = [] + export function service(key: keyof Services) { if (Object.prototype.hasOwnProperty.call(Context.prototype, key)) return + Services.push(key) const privateKey = Symbol(key) Object.defineProperty(Context.prototype, key, { get(this: Context) { @@ -604,16 +607,13 @@ export namespace Context { const action = value ? oldValue ? 'changed' : 'enabled' : 'disabled' this.logger('service').debug(key, action) if (value) { - this.app._services[key] = this.state.id const dispose = () => { if (this.app[privateKey] !== value) return this[key] = null - delete this.app._services[key] } this.state.disposables.push(dispose) this.on('service', (name) => { if (name !== key) return - dispose() remove(this.state.disposables, dispose) }) } diff --git a/plugins/frontend/console/src/index.ts b/plugins/frontend/console/src/index.ts index 55e029c88d..084b8625d2 100644 --- a/plugins/frontend/console/src/index.ts +++ b/plugins/frontend/console/src/index.ts @@ -170,9 +170,9 @@ class Console extends Service { private onConnection = (socket: WebSocket) => { const channel = new SocketHandle(this, socket) - for (const name in this.ctx.app._services) { + for (const name of Context.Services) { if (!name.startsWith('console.')) continue - this.ctx[name].get().then((value) => { + this.ctx[name]?.['get']().then((value) => { const key = name.slice(8) socket.send(JSON.stringify({ type: 'data', body: { key, value } })) }) diff --git a/plugins/frontend/manager/client/graph/utils.ts b/plugins/frontend/manager/client/graph/utils.ts index 72b74993b7..bf25014bd1 100644 --- a/plugins/frontend/manager/client/graph/utils.ts +++ b/plugins/frontend/manager/client/graph/utils.ts @@ -3,8 +3,6 @@ import { store } from '~/client' import { Dict } from 'koishi' import { computed } from 'vue' -type Bound = [number, number][] - export interface Node extends PluginData { id: string col?: number diff --git a/plugins/frontend/manager/client/index.ts b/plugins/frontend/manager/client/index.ts index 1cdec32401..5608b98f26 100644 --- a/plugins/frontend/manager/client/index.ts +++ b/plugins/frontend/manager/client/index.ts @@ -48,6 +48,6 @@ registerPage({ name: '依赖图', icon: 'project-diagram', order: 600, - fields: ['registry', 'services'], + fields: ['registry'], component: Graph, }) diff --git a/plugins/frontend/manager/src/registry.ts b/plugins/frontend/manager/src/registry.ts index 980f783e3c..f9668dbd14 100644 --- a/plugins/frontend/manager/src/registry.ts +++ b/plugins/frontend/manager/src/registry.ts @@ -31,7 +31,7 @@ export default class RegistryProvider extends DataSource> { : capitalize(camelize(plugin.name)), parent: state.parent?.id, disposables: state.disposables.length, - dependencies: state.using.map(name => this.ctx.app._services[name]).filter(x => x), + dependencies: state.using.map(name => this.ctx[name]?.['ctx']?.state.id).filter(x => x), } for (const child of state.children) { this.traverse(child) diff --git a/plugins/frontend/manager/src/services.ts b/plugins/frontend/manager/src/services.ts index 8b9c61e56b..be089c7de9 100644 --- a/plugins/frontend/manager/src/services.ts +++ b/plugins/frontend/manager/src/services.ts @@ -9,6 +9,11 @@ export default class ServiceProvider extends DataSource> { } async get() { - return this.ctx.app._services + const result: Dict = {} + for (const name of Context.Services) { + const value = this.ctx[name]?.['ctx']?.state.id + if (value) result[name] = value + } + return result } }