diff --git a/lib/client/api.d.ts b/lib/client/api.d.ts index f5b3775..d88d706 100644 --- a/lib/client/api.d.ts +++ b/lib/client/api.d.ts @@ -9,9 +9,5 @@ export interface MailGatewayApi { testConnection(patch: MailboxPatch): Promise>; status(): Promise>; } -/** - * 直接调用已挂载贡献的方法描述符,不经过 `ctx.remote['mail-gateway']`。 - * 命名空间访问器要求调用方声明 `inject: ['remote.mail-gateway']`,而该服务只在 - * `$mount` 之后才存在,声明它会形成等待依赖的死锁。 - */ +/** 调用方必须已声明 `inject: ['remote.mail-gateway']`,见 client/index.ts 的子插件。 */ export declare function createApi(ctx: Context): MailGatewayApi; diff --git a/lib/client/api.js b/lib/client/api.js index 73a52ad..379141c 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -1,16 +1,11 @@ -import TYPERT_REMOTE from '../remote.js'; -/** - * 直接调用已挂载贡献的方法描述符,不经过 `ctx.remote['mail-gateway']`。 - * 命名空间访问器要求调用方声明 `inject: ['remote.mail-gateway']`,而该服务只在 - * `$mount` 之后才存在,声明它会形成等待依赖的死锁。 - */ +/** 调用方必须已声明 `inject: ['remote.mail-gateway']`,见 client/index.ts 的子插件。 */ export function createApi(ctx) { - const methods = TYPERT_REMOTE.methods; + const remote = ctx.remote['mail-gateway']; return { - get: () => methods['mail-gateway/get'].invoke(ctx.remote, {}), - saveMailbox: patch => methods['mail-gateway/saveMailbox'].invoke(ctx.remote, { patch }), - saveWhitelist: addresses => methods['mail-gateway/saveWhitelist'].invoke(ctx.remote, { addresses }), - testConnection: patch => methods['mail-gateway/testConnection'].invoke(ctx.remote, { patch }), - status: () => methods['mail-gateway/status'].invoke(ctx.remote, {}), + get: () => remote.get(), + saveMailbox: patch => remote.saveMailbox(patch), + saveWhitelist: addresses => remote.saveWhitelist(addresses), + testConnection: patch => remote.testConnection(patch), + status: () => remote.status(), }; } diff --git a/lib/client/index.d.ts b/lib/client/index.d.ts index 7cef64b..bd5bbce 100644 --- a/lib/client/index.d.ts +++ b/lib/client/index.d.ts @@ -1,5 +1,9 @@ import type { Context } from '@deepseek-ai/cordis'; export declare const name = "dsh-mail-sender"; export declare const inject: string[]; -/** 挂载本插件的 Remote 命名空间,并在设置页注册“邮件网关”分区。 */ +/** + * 先挂载本插件的 Remote 命名空间,再交给一个声明了 `remote.mail-gateway` 的子插件 + * 注册设置页分区。命名空间服务由 `$mount` 提供,若在同一个 fiber 的 `inject` 里声明 + * 它会因为“依赖自己提供”而永久等待激活。 + */ export declare function apply(ctx: Context): Promise<() => Promise>; diff --git a/lib/client/index.js b/lib/client/index.js index f5db48f..7039c11 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -19984,13 +19984,13 @@ var remote_default = TYPERT_REMOTE; // src/client/api.ts function createApi(ctx) { - const methods = remote_default.methods; + const remote = ctx.remote["mail-gateway"]; return { - get: () => methods["mail-gateway/get"].invoke(ctx.remote, {}), - saveMailbox: (patch) => methods["mail-gateway/saveMailbox"].invoke(ctx.remote, { patch }), - saveWhitelist: (addresses) => methods["mail-gateway/saveWhitelist"].invoke(ctx.remote, { addresses }), - testConnection: (patch) => methods["mail-gateway/testConnection"].invoke(ctx.remote, { patch }), - status: () => methods["mail-gateway/status"].invoke(ctx.remote, {}) + get: () => remote.get(), + saveMailbox: (patch) => remote.saveMailbox(patch), + saveWhitelist: (addresses) => remote.saveWhitelist(addresses), + testConnection: (patch) => remote.testConnection(patch), + status: () => remote.status() }; } @@ -20287,20 +20287,26 @@ var name = "dsh-mail-sender"; var inject = ["slots", "remote"]; async function apply(ctx) { const disposeRemote = await ctx.remote.$mount(remote_default); - const api = createApi(ctx); - ctx.slots.inject( - "settings.section", - () => ctx.slots.register( - { - name: "settings.section", - id: "mail-gateway", - order: 120, - label: () => "\u90AE\u4EF6\u7F51\u5173", - inject: () => ({ api }) - }, - MailGatewaySection - ) - ); + ctx.plugin({ + name: "dsh-mail-sender/ui", + inject: ["slots", "remote.mail-gateway"], + apply(ui) { + const api = createApi(ui); + ui.slots.inject( + "settings.section", + () => ui.slots.register( + { + name: "settings.section", + id: "mail-gateway", + order: 120, + label: () => "\u90AE\u4EF6\u7F51\u5173", + inject: () => ({ api }) + }, + MailGatewaySection + ) + ); + } + }); return disposeRemote; } Object.defineProperty(module.exports,Symbol.toStringTag,{value:"Module"});return module.exports}}); diff --git a/src/client/api.ts b/src/client/api.ts index 37cd699..28e2748 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -1,7 +1,7 @@ import type { Context } from '@deepseek-ai/cordis' import type {} from '@deepseek-ai/dsh-api-remotes/client' import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol' -import TYPERT_REMOTE from '../remote.js' +import type {} from '../remote.js' import type { ConnectionTestResult, MailSnapshot, @@ -18,18 +18,14 @@ export interface MailGatewayApi { status(): Promise> } -/** - * 直接调用已挂载贡献的方法描述符,不经过 `ctx.remote['mail-gateway']`。 - * 命名空间访问器要求调用方声明 `inject: ['remote.mail-gateway']`,而该服务只在 - * `$mount` 之后才存在,声明它会形成等待依赖的死锁。 - */ +/** 调用方必须已声明 `inject: ['remote.mail-gateway']`,见 client/index.ts 的子插件。 */ export function createApi(ctx: Context): MailGatewayApi { - const methods = TYPERT_REMOTE.methods + const remote = ctx.remote['mail-gateway'] return { - get: () => methods['mail-gateway/get'].invoke(ctx.remote, {}), - saveMailbox: patch => methods['mail-gateway/saveMailbox'].invoke(ctx.remote, { patch }), - saveWhitelist: addresses => methods['mail-gateway/saveWhitelist'].invoke(ctx.remote, { addresses }), - testConnection: patch => methods['mail-gateway/testConnection'].invoke(ctx.remote, { patch }), - status: () => methods['mail-gateway/status'].invoke(ctx.remote, {}), + get: () => remote.get(), + saveMailbox: patch => remote.saveMailbox(patch), + saveWhitelist: addresses => remote.saveWhitelist(addresses), + testConnection: patch => remote.testConnection(patch), + status: () => remote.status(), } } diff --git a/src/client/index.ts b/src/client/index.ts index 9d76b9a..79347c9 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -10,23 +10,33 @@ import { MailGatewaySection } from './MailGatewaySection.js' export const name = 'dsh-mail-sender' export const inject = ['slots', 'remote'] -/** 挂载本插件的 Remote 命名空间,并在设置页注册“邮件网关”分区。 */ +/** + * 先挂载本插件的 Remote 命名空间,再交给一个声明了 `remote.mail-gateway` 的子插件 + * 注册设置页分区。命名空间服务由 `$mount` 提供,若在同一个 fiber 的 `inject` 里声明 + * 它会因为“依赖自己提供”而永久等待激活。 + */ export async function apply(ctx: Context): Promise<() => Promise> { const disposeRemote = await ctx.remote.$mount(TYPERT_REMOTE) - const api = createApi(ctx) - ctx.slots.inject('settings.section', () => - ctx.slots.register( - { - name: 'settings.section', - id: 'mail-gateway', - order: 120, - label: () => '邮件网关', - inject: () => ({ api }), - }, - MailGatewaySection, - ), - ) + ctx.plugin({ + name: 'dsh-mail-sender/ui', + inject: ['slots', 'remote.mail-gateway'], + apply(ui: Context): void { + const api = createApi(ui) + ui.slots.inject('settings.section', () => + ui.slots.register( + { + name: 'settings.section', + id: 'mail-gateway', + order: 120, + label: () => '邮件网关', + inject: () => ({ api }), + }, + MailGatewaySection, + ), + ) + }, + }) return disposeRemote }