@sunshaobei/dsh-session-manager 3.1.3 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client.js +19 -14
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -224,23 +224,28 @@ window.__ModuleLoader__.load({
224
224
  let hostTranslate;
225
225
 
226
226
  function attachHostLocale(ctx) {
227
- // 宿主暴露方式因版本而异:0.2.x 直接挂在 ctx.locale;旧版经 ctx.get('locale')。两种都试。
228
- hostLocale = (ctx && ctx.locale && typeof ctx.locale.register === 'function') ? ctx.locale : undefined;
229
- if (!hostLocale && typeof ctx?.get === 'function') { try { hostLocale = ctx.get('locale'); } catch { /* keep undefined */ } }
227
+ try { hostLocale = ctx?.get?.('locale'); } catch { hostLocale = undefined; }
230
228
  if (!hostLocale || typeof hostLocale.register !== 'function' || typeof hostLocale.bind !== 'function') return;
229
+ let unsubLocale;
231
230
  try {
232
- const dispose = hostLocale.register(LOCALE_NS, MESSAGES);
233
- ctx.effect?.(() => dispose, 'session-trash: locale dictionaries');
234
- } catch {
235
- // A twin instance may already own the namespace; `bind` still resolves
236
- // the same dictionaries, so fall through and probe below.
231
+ hostLocale.register(LOCALE_NS, MESSAGES);
232
+ const bindNow = () => {
233
+ try {
234
+ const bound = hostLocale.bind(LOCALE_NS);
235
+ // Trust the service only once OUR keys resolve through it — translate()
236
+ // returns the raw key when the namespace carries no dictionary.
237
+ if (bound('recycleBin') !== 'recycleBin') hostTranslate = bound;
238
+ } catch { /* keep the built-in table */ }
239
+ };
240
+ bindNow();
241
+ // 语言切换时重绑(同 mcp-manager 的 subscribe 模式)
242
+ if (typeof hostLocale.subscribe === 'function' && typeof hostLocale.getSnapshot === 'function') {
243
+ unsubLocale = hostLocale.subscribe(bindNow);
244
+ }
245
+ } catch (error) {
246
+ console.warn('[dsh-session-manager] locale 注册失败:', error);
237
247
  }
238
- try {
239
- const bound = hostLocale.bind(LOCALE_NS);
240
- // Trust the service only once OUR keys resolve through it — translate()
241
- // returns the raw key when the namespace carries no dictionary.
242
- if (bound('recycleBin') !== 'recycleBin') hostTranslate = bound;
243
- } catch { /* keep the built-in table */ }
248
+ ctx.effect?.(() => () => { if (unsubLocale) unsubLocale(); }, 'session-trash: locale dictionaries');
244
249
  }
245
250
 
246
251
  function browserLocale() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunshaobei/dsh-session-manager",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "DSH 会话回收站:会话详情归档入口、回收站多选还原/彻底删除、活跃会话保护。 · Session trash & permanent delete for DeepSeek Harness.",
5
5
  "type": "module",
6
6
  "main": "index.js",