|
|
@@ -36,6 +36,8 @@ window.__ModuleLoader__.load({
|
|
|
|
|
|
|
|
|
|
|
|
/** Locale namespace owned by this package. */
|
|
|
|
/** Locale namespace owned by this package. */
|
|
|
|
const NS = 'session-notify'
|
|
|
|
const NS = 'session-notify'
|
|
|
|
|
|
|
|
/** This package's name: the plugin manager keys a bundle's configuration by it. */
|
|
|
|
|
|
|
|
const PACKAGE_NAME = '@dsh-plugin/session-notify'
|
|
|
|
/** Trigger ids shared by the store, the copy table, and the settings row. */
|
|
|
|
/** Trigger ids shared by the store, the copy table, and the settings row. */
|
|
|
|
const KINDS = ['completion', 'approval', 'question']
|
|
|
|
const KINDS = ['completion', 'approval', 'question']
|
|
|
|
/** Pending-interaction kinds the Harness itself renders, and this plugin serves. */
|
|
|
|
/** Pending-interaction kinds the Harness itself renders, and this plugin serves. */
|
|
|
@@ -82,6 +84,11 @@ window.__ModuleLoader__.load({
|
|
|
|
'settings.kind.completion': '完成',
|
|
|
|
'settings.kind.completion': '完成',
|
|
|
|
'settings.kind.approval': '授权',
|
|
|
|
'settings.kind.approval': '授权',
|
|
|
|
'settings.kind.question': '提问',
|
|
|
|
'settings.kind.question': '提问',
|
|
|
|
|
|
|
|
'config.section.kinds': '提醒内容',
|
|
|
|
|
|
|
|
'config.section.permission': '系统通知权限',
|
|
|
|
|
|
|
|
'config.section.status': '运行状态',
|
|
|
|
|
|
|
|
'config.intro': '提醒都从当前页面发出:窗口不在前台时是系统通知,窗口在前台时是这里的轻弹窗。',
|
|
|
|
|
|
|
|
'config.saveNote': '开关保存在浏览器本地,重装插件不会丢失。',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const en = {
|
|
|
|
const en = {
|
|
|
|
'notification.completion': 'Conversation finished',
|
|
|
|
'notification.completion': 'Conversation finished',
|
|
|
@@ -117,42 +124,53 @@ window.__ModuleLoader__.load({
|
|
|
|
'settings.kind.completion': 'Finished',
|
|
|
|
'settings.kind.completion': 'Finished',
|
|
|
|
'settings.kind.approval': 'Approval',
|
|
|
|
'settings.kind.approval': 'Approval',
|
|
|
|
'settings.kind.question': 'Questions',
|
|
|
|
'settings.kind.question': 'Questions',
|
|
|
|
|
|
|
|
'config.section.kinds': 'What to notify about',
|
|
|
|
|
|
|
|
'config.section.permission': 'System notification permission',
|
|
|
|
|
|
|
|
'config.section.status': 'Status',
|
|
|
|
|
|
|
|
'config.intro': 'Every alert comes from this page: a system notification while the window is in the background, the light popup here while it is in the foreground.',
|
|
|
|
|
|
|
|
'config.saveNote': 'The switches are stored in this browser and survive reinstalling the plugin.',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Every declaration below belongs to this package. The popup copies the
|
|
|
|
* Every declaration below belongs to this package. The popup copies the
|
|
|
|
* shipped toast surface (a fixed entry in the frame-wide overlay, the
|
|
|
|
* shipped toast surface (a fixed entry in the frame-wide overlay, the
|
|
|
|
* `--dsw-alias-toast-bg` / `--dsw-alias-toast-label` pair, `--dsw-radius-lg`,
|
|
|
|
* `--dsw-alias-toast-bg` / `--dsw-alias-toast-label` pair, `--dsw-radius-lg`,
|
|
|
|
* `--dsw-shadow-lv3`), the switch copies `Switch.module.css` behavior and
|
|
|
|
* `--dsw-shadow-lv3`) and adds a title line above the text; the switch copies
|
|
|
|
* proportion, and the settings row copies the General-section row pattern.
|
|
|
|
* `Switch.module.css` behavior and proportion; the configuration sections
|
|
|
|
|
|
|
|
* follow the Plugin Manager page's own section rhythm (a column, 32px apart).
|
|
|
|
* Class names are renamed under `dsn-`; only the popup glyphs carry their own
|
|
|
|
* Class names are renamed under `dsn-`; only the popup glyphs carry their own
|
|
|
|
* artwork colors.
|
|
|
|
* artwork colors.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
const CSS = `
|
|
|
|
const CSS = `
|
|
|
|
.dsn-stack{position:fixed;top:40px;right:24px;z-index:1100;display:flex;flex-direction:column;align-items:flex-end;gap:8px;pointer-events:none}
|
|
|
|
.dsn-stack{position:fixed;top:40px;right:24px;z-index:1100;display:flex;flex-direction:column;align-items:flex-end;gap:8px;pointer-events:none}
|
|
|
|
@media (max-width:520px){.dsn-stack{right:12px}}
|
|
|
|
@media (max-width:520px){.dsn-stack{right:12px}}
|
|
|
|
.dsn-toast{box-sizing:border-box;pointer-events:auto;display:flex;align-items:center;gap:10px;width:max-content;max-width:min(420px,calc(100vw - 48px));padding:12px 16px;border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-toast-bg);color:var(--dsw-alias-toast-label);font-size:14px;line-height:22px;box-shadow:var(--dsw-shadow-lv3);animation:dsn-toast-in 160ms ease-out}
|
|
|
|
.dsn-toast{box-sizing:border-box;pointer-events:auto;display:flex;align-items:flex-start;gap:10px;width:max-content;max-width:min(420px,calc(100vw - 48px));padding:12px 12px 12px 16px;border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-toast-bg);color:var(--dsw-alias-toast-label);font-size:14px;line-height:22px;box-shadow:var(--dsw-shadow-lv3);animation:dsn-toast-in 160ms ease-out}
|
|
|
|
@keyframes dsn-toast-in{from{opacity:0;transform:translateX(8px)}to{opacity:1;transform:translateX(0)}}
|
|
|
|
@keyframes dsn-toast-in{from{opacity:0;transform:translateX(8px)}to{opacity:1;transform:translateX(0)}}
|
|
|
|
@media (prefers-reduced-motion: reduce){.dsn-toast{animation:none}}
|
|
|
|
@media (prefers-reduced-motion: reduce){.dsn-toast{animation:none}}
|
|
|
|
.dsn-toast-icon{display:grid;place-items:center;flex:none;color:var(--dsw-alias-state-warn-label)}
|
|
|
|
.dsn-toast-icon{display:grid;place-items:center;flex:none;height:22px;color:var(--dsw-alias-state-warn-label)}
|
|
|
|
.dsn-toast-icon.is-completion{color:var(--dsw-alias-state-success-primary)}
|
|
|
|
.dsn-toast-icon.is-completion{color:var(--dsw-alias-state-success-primary)}
|
|
|
|
.dsn-toast-icon.is-question{color:var(--dsw-alias-brand-primary)}
|
|
|
|
.dsn-toast-icon.is-question{color:var(--dsw-alias-brand-primary)}
|
|
|
|
.dsn-toast-text{min-width:0}
|
|
|
|
.dsn-toast-text{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
|
|
|
|
.dsn-toast-action{padding:0;border:0;background:none;color:var(--dsw-static-deepseek-400);font:inherit;cursor:pointer;margin-inline:3px}
|
|
|
|
.dsn-toast-title{font-weight:500;font-size:14px;line-height:22px}
|
|
|
|
.dsn-toast-action:hover{opacity:.8}
|
|
|
|
.dsn-toast-desc{color:var(--dsw-alias-toast-label);opacity:.8;font-size:13px;line-height:20px;overflow-wrap:break-word}
|
|
|
|
|
|
|
|
.dsn-toast-actions{display:flex;align-items:center;gap:2px;flex:none}
|
|
|
|
|
|
|
|
.dsn-toast-action{display:inline-flex;align-items:center;height:28px;padding:0 8px;border:0;border-radius:var(--dsw-radius-sm);background:none;color:var(--dsw-static-deepseek-400);font:inherit;font-size:13px;line-height:20px;cursor:pointer}
|
|
|
|
|
|
|
|
.dsn-toast-action:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
|
|
.dsn-toast-action:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
|
|
|
|
.dsn-toast-action:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
|
|
|
|
.dsn-toast-close{flex:none;display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;border:0;border-radius:var(--dsw-radius-xs);background:transparent;color:var(--dsw-alias-toast-label);opacity:.7;cursor:pointer}
|
|
|
|
.dsn-toast-close{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:0;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-toast-label);opacity:.8;cursor:pointer}
|
|
|
|
.dsn-toast-close:hover{opacity:1}
|
|
|
|
.dsn-toast-close:hover{background:var(--dsw-alias-interactive-bg-hover);opacity:1}
|
|
|
|
.dsn-toast-close:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
|
|
|
|
.dsn-toast-close:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
|
|
|
|
.dsn-row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}
|
|
|
|
.dsn-sections{display:flex;flex-direction:column;gap:24px}
|
|
|
|
.dsn-row-text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}
|
|
|
|
.dsn-section{display:flex;flex-direction:column;gap:10px}
|
|
|
|
.dsn-row-title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}
|
|
|
|
.dsn-section-title{margin:0;color:var(--dsw-alias-label-primary);font-size:14px;font-weight:500;line-height:22px}
|
|
|
|
.dsn-row-desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}
|
|
|
|
.dsn-section-desc{margin:0;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
|
|
|
|
.dsn-status{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}
|
|
|
|
.dsn-row{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:10px 0;border-bottom:.5px solid var(--dsw-alias-border-l2)}
|
|
|
|
.dsn-status + .dsn-status,.dsn-row-desc + .dsn-status,.dsn-kinds + .dsn-status{margin-top:8px}
|
|
|
|
.dsn-row:last-child{border-bottom:0}
|
|
|
|
|
|
|
|
.dsn-row-text{display:flex;flex-direction:column;gap:2px;min-width:0}
|
|
|
|
|
|
|
|
.dsn-row-title{color:var(--dsw-alias-label-primary);font-size:14px;line-height:22px}
|
|
|
|
|
|
|
|
.dsn-row-desc{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
|
|
|
|
|
|
|
|
.dsn-status{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}
|
|
|
|
.dsn-status-error{color:var(--dsw-alias-state-error-primary)}
|
|
|
|
.dsn-status-error{color:var(--dsw-alias-state-error-primary)}
|
|
|
|
.dsn-kinds{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:10px;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
|
|
|
|
|
|
|
|
.dsn-kind{display:inline-flex;align-items:center;gap:6px;color:var(--dsw-alias-label-secondary)}
|
|
|
|
|
|
|
|
.dsn-switch{box-sizing:border-box;position:relative;flex:0 0 auto;width:36px;height:20px;padding:2px;border:0;border-radius:999px;background:var(--dsw-alias-border-l3);cursor:pointer}
|
|
|
|
.dsn-switch{box-sizing:border-box;position:relative;flex:0 0 auto;width:36px;height:20px;padding:2px;border:0;border-radius:999px;background:var(--dsw-alias-border-l3);cursor:pointer}
|
|
|
|
.dsn-switch[aria-checked='true']{background:var(--dsw-alias-brand-primary)}
|
|
|
|
.dsn-switch[aria-checked='true']{background:var(--dsw-alias-brand-primary)}
|
|
|
|
.dsn-switch:disabled{cursor:default;opacity:.5}
|
|
|
|
.dsn-switch:disabled{cursor:default;opacity:.5}
|
|
|
@@ -375,10 +393,35 @@ window.__ModuleLoader__.load({
|
|
|
|
return preview(interaction.displayReason?.text ?? interaction.reason?.text ?? '')
|
|
|
|
return preview(interaction.displayReason?.text ?? interaction.reason?.text ?? '')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Register this package's dictionaries with the locale service.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Without this the service has no entry for the namespace and every
|
|
|
|
|
|
|
|
* `locale.bind(NS)` lookup answers with the key itself, so the settings row
|
|
|
|
|
|
|
|
* shows `settings.title` instead of its copy. The typed form takes every
|
|
|
|
|
|
|
|
* shipped locale in one call, and the older single-locale form stays
|
|
|
|
|
|
|
|
* supported as a fallback. Registration bumps the locale revision, so
|
|
|
|
|
|
|
|
* already-rendered entries pick the copy up without a reload.
|
|
|
|
|
|
|
|
* @param locale - the locale service, or undefined when this profile has none.
|
|
|
|
|
|
|
|
* @returns a disposer for whichever registrations were installed.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function registerDictionaries(locale) {
|
|
|
|
|
|
|
|
if (locale === undefined || typeof locale.register !== 'function') return () => {}
|
|
|
|
|
|
|
|
const dictionaries = { zh, en }
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return locale.register(NS, dictionaries)
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
const disposers = Object.entries(dictionaries).map(([id, dict]) => locale.register(NS, id, dict))
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
|
|
for (const dispose of disposers) dispose?.()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Build a translate function for one locale service: the service's own bound
|
|
|
|
* Build a translate function for one locale service: the service's own bound
|
|
|
|
* namespace first, then the current language's dictionary, then the key
|
|
|
|
* namespace first, then this package's dictionaries, then the key itself, so
|
|
|
|
* itself, so a missing seat degrades copy instead of rendering.
|
|
|
|
* a missing seat degrades copy instead of rendering.
|
|
|
|
* @param locale - the locale service, or undefined when this profile has none.
|
|
|
|
* @param locale - the locale service, or undefined when this profile has none.
|
|
|
|
* @returns a translate function with `{ name }` interpolation.
|
|
|
|
* @returns a translate function with `{ name }` interpolation.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@@ -387,7 +430,10 @@ window.__ModuleLoader__.load({
|
|
|
|
if (locale !== undefined && typeof locale.bind === 'function') {
|
|
|
|
if (locale !== undefined && typeof locale.bind === 'function') {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const bound = locale.bind(NS)
|
|
|
|
const bound = locale.bind(NS)
|
|
|
|
if (typeof bound === 'function') return bound(key, params)
|
|
|
|
if (typeof bound === 'function') {
|
|
|
|
|
|
|
|
const translated = bound(key, params)
|
|
|
|
|
|
|
|
if (typeof translated === 'string' && translated !== key) return translated
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
/* a locale service without this namespace still renders the fallback */
|
|
|
|
/* a locale service without this namespace still renders the fallback */
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -395,7 +441,7 @@ window.__ModuleLoader__.load({
|
|
|
|
let language = ''
|
|
|
|
let language = ''
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const snapshot = locale?.getSnapshot?.()
|
|
|
|
const snapshot = locale?.getSnapshot?.()
|
|
|
|
language = String(snapshot?.language ?? snapshot?.locale ?? snapshot?.id ?? '')
|
|
|
|
language = String(snapshot?.active ?? '')
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
language = ''
|
|
|
|
language = ''
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -408,6 +454,42 @@ window.__ModuleLoader__.load({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Storage key for this package's own preferences. */
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'dsh-plugin/session-notify'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Read this package's stored trigger switches.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* These are browser preferences rather than cordis configuration, so they live
|
|
|
|
|
|
|
|
* in this origin's own storage instead of the profile's patch file: the plugin
|
|
|
|
|
|
|
|
* writes nothing into DSH's configuration, and every read is defensive because
|
|
|
|
|
|
|
|
* storage can be unavailable or hold something an older version wrote.
|
|
|
|
|
|
|
|
* @returns the stored switches, defaulting to everything on.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function readStoredKinds() {
|
|
|
|
|
|
|
|
const kinds = { completion: true, approval: true, question: true }
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const raw = globalThis.localStorage?.getItem(STORAGE_KEY)
|
|
|
|
|
|
|
|
if (typeof raw !== 'string' || raw === '') return kinds
|
|
|
|
|
|
|
|
const stored = JSON.parse(raw)
|
|
|
|
|
|
|
|
for (const kind of KINDS) {
|
|
|
|
|
|
|
|
if (typeof stored?.[kind] === 'boolean') kinds[kind] = stored[kind]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
/* unreadable or foreign storage keeps the defaults */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return kinds
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Store one trigger switch, ignoring storage that refuses to write. */
|
|
|
|
|
|
|
|
function writeStoredKinds(kinds) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
globalThis.localStorage?.setItem(STORAGE_KEY, JSON.stringify(kinds))
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
/* a refused write leaves the switches live for this page only */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Install the plugin.
|
|
|
|
* Install the plugin.
|
|
|
|
* @param ctx - Client root context providing `slots` and `locale`.
|
|
|
|
* @param ctx - Client root context providing `slots` and `locale`.
|
|
|
@@ -418,7 +500,7 @@ window.__ModuleLoader__.load({
|
|
|
|
|
|
|
|
|
|
|
|
const store = createStore({
|
|
|
|
const store = createStore({
|
|
|
|
permission: notificationPermission(),
|
|
|
|
permission: notificationPermission(),
|
|
|
|
kinds: { completion: true, approval: true, question: true },
|
|
|
|
kinds: readStoredKinds(),
|
|
|
|
toasts: [],
|
|
|
|
toasts: [],
|
|
|
|
promptError: '',
|
|
|
|
promptError: '',
|
|
|
|
health: { state: 'starting', message: '' },
|
|
|
|
health: { state: 'starting', message: '' },
|
|
|
@@ -511,13 +593,18 @@ window.__ModuleLoader__.load({
|
|
|
|
timers.delete(id)
|
|
|
|
timers.delete(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Show one light in-app popup. */
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Show one light in-app popup: the trigger as the title, the conversation
|
|
|
|
|
|
|
|
* and its detail as the description, so the heading says what happened and
|
|
|
|
|
|
|
|
* the line under it says where.
|
|
|
|
|
|
|
|
*/
|
|
|
|
const showToast = (candidate) => {
|
|
|
|
const showToast = (candidate) => {
|
|
|
|
const notice = copyFor(candidate)
|
|
|
|
const notice = copyFor(candidate)
|
|
|
|
state.toastSeq += 1
|
|
|
|
state.toastSeq += 1
|
|
|
|
const toast = {
|
|
|
|
const toast = {
|
|
|
|
id: `dsn-${String(state.toastSeq)}`,
|
|
|
|
id: `dsn-${String(state.toastSeq)}`,
|
|
|
|
kind: notice.kind,
|
|
|
|
kind: notice.kind,
|
|
|
|
|
|
|
|
title: notice.title,
|
|
|
|
body: notice.body,
|
|
|
|
body: notice.body,
|
|
|
|
sessionId: candidate.sessionId,
|
|
|
|
sessionId: candidate.sessionId,
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -752,10 +839,12 @@ window.__ModuleLoader__.load({
|
|
|
|
if (notificationPermission() === 'granted') sendTest()
|
|
|
|
if (notificationPermission() === 'granted') sendTest()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Toggle one trigger. */
|
|
|
|
/** Toggle one trigger and remember the choice. */
|
|
|
|
const setKindEnabled = (kind, enabled) => {
|
|
|
|
const setKindEnabled = (kind, enabled) => {
|
|
|
|
const snapshot = store.getSnapshot()
|
|
|
|
const snapshot = store.getSnapshot()
|
|
|
|
store.set({ ...snapshot, kinds: { ...snapshot.kinds, [kind]: enabled } })
|
|
|
|
const kinds = { ...snapshot.kinds, [kind]: enabled }
|
|
|
|
|
|
|
|
writeStoredKinds(kinds)
|
|
|
|
|
|
|
|
store.set({ ...snapshot, kinds })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------- components
|
|
|
|
// ----------------------------------------------------------- components
|
|
|
@@ -845,30 +934,60 @@ window.__ModuleLoader__.load({
|
|
|
|
onMouseLeave: () => props.arm(toast.id),
|
|
|
|
onMouseLeave: () => props.arm(toast.id),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
h('span', { className: `dsn-toast-icon is-${toast.kind}` }, h(KindIcon, { kind: toast.kind, size: 16 })),
|
|
|
|
h('span', { className: `dsn-toast-icon is-${toast.kind}` }, h(KindIcon, { kind: toast.kind, size: 16 })),
|
|
|
|
h('span', { className: 'dsn-toast-text' }, toast.body),
|
|
|
|
h('div', { className: 'dsn-toast-text' },
|
|
|
|
h('button', {
|
|
|
|
h('div', { className: 'dsn-toast-title' }, toast.title),
|
|
|
|
type: 'button',
|
|
|
|
h('div', { className: 'dsn-toast-desc' }, toast.body)),
|
|
|
|
className: 'dsn-toast-action',
|
|
|
|
h('div', { className: 'dsn-toast-actions' },
|
|
|
|
onClick: () => {
|
|
|
|
h('button', {
|
|
|
|
props.dismiss(toast.id)
|
|
|
|
type: 'button',
|
|
|
|
props.open(toast.sessionId)
|
|
|
|
className: 'dsn-toast-action',
|
|
|
|
},
|
|
|
|
onClick: () => {
|
|
|
|
}, tr('toast.view')),
|
|
|
|
props.dismiss(toast.id)
|
|
|
|
h('button', {
|
|
|
|
props.open(toast.sessionId)
|
|
|
|
type: 'button',
|
|
|
|
},
|
|
|
|
className: 'dsn-toast-close',
|
|
|
|
}, tr('toast.view')),
|
|
|
|
'aria-label': tr('toast.dismiss'),
|
|
|
|
h('button', {
|
|
|
|
onClick: () => props.dismiss(toast.id),
|
|
|
|
type: 'button',
|
|
|
|
}, h(CloseIcon, { size: 12 }))))))
|
|
|
|
className: 'dsn-toast-close',
|
|
|
|
|
|
|
|
'aria-label': tr('toast.dismiss'),
|
|
|
|
|
|
|
|
onClick: () => props.dismiss(toast.id),
|
|
|
|
|
|
|
|
}, h(CloseIcon, { size: 14 })))))))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** The General-settings row: permission state, one action, per-trigger switches. */
|
|
|
|
/**
|
|
|
|
function SettingsRow(props) {
|
|
|
|
* One trigger switch row: the label says which notification it governs and
|
|
|
|
|
|
|
|
* the switch is the control, so the row never needs a second description.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function KindRow(props) {
|
|
|
|
|
|
|
|
return h('div', { className: 'dsn-row' },
|
|
|
|
|
|
|
|
h('div', { className: 'dsn-row-text' },
|
|
|
|
|
|
|
|
h('div', { className: 'dsn-row-title' }, props.label)),
|
|
|
|
|
|
|
|
h('button', {
|
|
|
|
|
|
|
|
type: 'button',
|
|
|
|
|
|
|
|
role: 'switch',
|
|
|
|
|
|
|
|
className: 'dsn-switch',
|
|
|
|
|
|
|
|
'aria-checked': props.checked,
|
|
|
|
|
|
|
|
'aria-label': props.label,
|
|
|
|
|
|
|
|
disabled: props.disabled,
|
|
|
|
|
|
|
|
onClick: props.onToggle,
|
|
|
|
|
|
|
|
}, h('span', { className: 'dsn-thumb' })))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This plugin's configuration, rendered on its own page in the plugin
|
|
|
|
|
|
|
|
* manager (`plugins.bundle.config`, keyed by this package's name).
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* The owner asks for two views: `summary` (a one-liner that stands in for
|
|
|
|
|
|
|
|
* the row's description) and `page` (the whole form). Everything visible here
|
|
|
|
|
|
|
|
* belongs to this package, including the platform-specific permission hint.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function ConfigSection(props) {
|
|
|
|
const snapshot = useOwnStore(props.store)
|
|
|
|
const snapshot = useOwnStore(props.store)
|
|
|
|
|
|
|
|
const tr = seatFor(props)
|
|
|
|
|
|
|
|
if (props.view === 'summary') return h(React.Fragment, null, tr('settings.description'))
|
|
|
|
const permission = snapshot.permission
|
|
|
|
const permission = snapshot.permission
|
|
|
|
const supported = permission !== 'unsupported'
|
|
|
|
const supported = permission !== 'unsupported'
|
|
|
|
const failed = permission === 'denied' || snapshot.promptError !== ''
|
|
|
|
const failed = permission === 'denied' || snapshot.promptError !== ''
|
|
|
|
const tr = seatFor(props)
|
|
|
|
|
|
|
|
const statusKey = permission === 'granted'
|
|
|
|
const statusKey = permission === 'granted'
|
|
|
|
? 'settings.permission.granted'
|
|
|
|
? 'settings.permission.granted'
|
|
|
|
: permission === 'denied'
|
|
|
|
: permission === 'denied'
|
|
|
@@ -876,7 +995,7 @@ window.__ModuleLoader__.load({
|
|
|
|
: supported
|
|
|
|
: supported
|
|
|
|
? 'settings.permission.default'
|
|
|
|
? 'settings.permission.default'
|
|
|
|
: 'settings.permission.unsupported'
|
|
|
|
: 'settings.permission.unsupported'
|
|
|
|
const statusText = snapshot.promptError === ''
|
|
|
|
const permissionText = snapshot.promptError === ''
|
|
|
|
? `${tr(statusKey)}${permission === 'denied' || !supported ? ` · ${tr(`settings.permission.hint.${props.platform}`)}` : ''}`
|
|
|
|
? `${tr(statusKey)}${permission === 'denied' || !supported ? ` · ${tr(`settings.permission.hint.${props.platform}`)}` : ''}`
|
|
|
|
: snapshot.promptError
|
|
|
|
: snapshot.promptError
|
|
|
|
const health = snapshot.health
|
|
|
|
const health = snapshot.health
|
|
|
@@ -887,39 +1006,49 @@ window.__ModuleLoader__.load({
|
|
|
|
: health.state === 'error'
|
|
|
|
: health.state === 'error'
|
|
|
|
? tr('settings.health.error', { message: health.message })
|
|
|
|
? tr('settings.health.error', { message: health.message })
|
|
|
|
: tr('settings.health.starting')
|
|
|
|
: tr('settings.health.starting')
|
|
|
|
|
|
|
|
const healthFailed = health.state !== 'watching' && health.state !== 'starting'
|
|
|
|
return h(React.Fragment, null,
|
|
|
|
return h(React.Fragment, null,
|
|
|
|
h('style', null, CSS),
|
|
|
|
h('style', null, CSS),
|
|
|
|
h('div', { className: 'dsn-row' },
|
|
|
|
h('div', { className: 'dsn-sections' },
|
|
|
|
h('div', { className: 'dsn-row-text' },
|
|
|
|
// The page header already shows this bundle's title and description, so
|
|
|
|
h('div', { className: 'dsn-row-title' }, tr('settings.title')),
|
|
|
|
// this section opens with what the header cannot say: how alerts are
|
|
|
|
h('div', { className: 'dsn-row-desc' }, tr('settings.description')),
|
|
|
|
// carried, and what this form changes.
|
|
|
|
h('div', {
|
|
|
|
h('section', { className: 'dsn-section' },
|
|
|
|
className: `dsn-status${failed ? ' dsn-status-error' : ''}`,
|
|
|
|
h('p', { className: 'dsn-section-desc' }, tr('config.intro'))),
|
|
|
|
role: failed ? 'alert' : 'status',
|
|
|
|
h('section', { className: 'dsn-section' },
|
|
|
|
}, statusText),
|
|
|
|
h('h3', { className: 'dsn-section-title' }, tr('config.section.kinds')),
|
|
|
|
h('div', {
|
|
|
|
KINDS.map((kind) => h(KindRow, {
|
|
|
|
className: `dsn-status${health.state === 'watching' || health.state === 'starting' ? '' : ' dsn-status-error'}`,
|
|
|
|
key: kind,
|
|
|
|
role: health.state === 'watching' || health.state === 'starting' ? 'status' : 'alert',
|
|
|
|
label: tr(`settings.kind.${kind}`),
|
|
|
|
}, healthText),
|
|
|
|
checked: snapshot.kinds[kind] === true,
|
|
|
|
h('div', { className: 'dsn-kinds' },
|
|
|
|
disabled: false,
|
|
|
|
h('span', null, tr('settings.kinds.label')),
|
|
|
|
onToggle: () => props.setKind(kind, snapshot.kinds[kind] !== true),
|
|
|
|
KINDS.map((kind) => h('span', { className: 'dsn-kind', key: kind },
|
|
|
|
})),
|
|
|
|
h('span', null, tr(`settings.kind.${kind}`)),
|
|
|
|
h('p', { className: 'dsn-section-desc' }, tr('config.saveNote'))),
|
|
|
|
h('button', {
|
|
|
|
h('section', { className: 'dsn-section' },
|
|
|
|
type: 'button',
|
|
|
|
h('h3', { className: 'dsn-section-title' }, tr('config.section.permission')),
|
|
|
|
role: 'switch',
|
|
|
|
h('div', { className: 'dsn-row' },
|
|
|
|
className: 'dsn-switch',
|
|
|
|
h('div', { className: 'dsn-row-text' },
|
|
|
|
'aria-checked': snapshot.kinds[kind] === true,
|
|
|
|
h('p', {
|
|
|
|
'aria-label': tr(`settings.kind.${kind}`),
|
|
|
|
className: `dsn-status${failed ? ' dsn-status-error' : ''}`,
|
|
|
|
disabled: !supported,
|
|
|
|
role: failed ? 'alert' : 'status',
|
|
|
|
onClick: () => props.setKind(kind, snapshot.kinds[kind] !== true),
|
|
|
|
}, permissionText)),
|
|
|
|
}, h('span', { className: 'dsn-thumb' })))))),
|
|
|
|
h('button', {
|
|
|
|
h('button', {
|
|
|
|
type: 'button',
|
|
|
|
type: 'button',
|
|
|
|
className: 'dsn-button',
|
|
|
|
className: 'dsn-button',
|
|
|
|
disabled: !supported,
|
|
|
|
disabled: !supported,
|
|
|
|
onClick: permission === 'granted' ? props.test : props.ask,
|
|
|
|
onClick: permission === 'granted' ? props.test : props.ask,
|
|
|
|
}, tr(!supported
|
|
|
|
}, tr(!supported ? 'settings.action.unsupported' : permission === 'granted' ? 'settings.action.test' : 'settings.action.allow'))))
|
|
|
|
? 'settings.action.unsupported'
|
|
|
|
|
|
|
|
: permission === 'granted' ? 'settings.action.test' : 'settings.action.allow')))),
|
|
|
|
|
|
|
|
h('section', { className: 'dsn-section' },
|
|
|
|
|
|
|
|
h('h3', { className: 'dsn-section-title' }, tr('config.section.status')),
|
|
|
|
|
|
|
|
h('div', { className: 'dsn-row' },
|
|
|
|
|
|
|
|
h('div', { className: 'dsn-row-text' },
|
|
|
|
|
|
|
|
h('p', {
|
|
|
|
|
|
|
|
className: `dsn-status${healthFailed ? ' dsn-status-error' : ''}`,
|
|
|
|
|
|
|
|
role: healthFailed ? 'alert' : 'status',
|
|
|
|
|
|
|
|
}, healthText))))))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------- registration
|
|
|
|
// ---------------------------------------------------------- registration
|
|
|
@@ -951,6 +1080,7 @@ window.__ModuleLoader__.load({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.effect(() => registerDictionaries(locale), 'session-notify: dictionaries')
|
|
|
|
ctx.effect(() => installBridges(), 'session-notify: window focus')
|
|
|
|
ctx.effect(() => installBridges(), 'session-notify: window focus')
|
|
|
|
ctx.effect(() => () => {
|
|
|
|
ctx.effect(() => () => {
|
|
|
|
disposed = true
|
|
|
|
disposed = true
|
|
|
@@ -973,10 +1103,14 @@ window.__ModuleLoader__.load({
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}, ToastLayer))
|
|
|
|
}, ToastLayer))
|
|
|
|
|
|
|
|
|
|
|
|
ctx.slots.inject('settings.general.item', () => ctx.slots.register({
|
|
|
|
// This plugin's configuration lives on its own page in the plugin manager,
|
|
|
|
name: 'settings.general.item',
|
|
|
|
// keyed by this package's name — the seat the shipped experimental bundle
|
|
|
|
id: NS,
|
|
|
|
// uses for its own settings, and the one the plugin page renders between the
|
|
|
|
order: 97,
|
|
|
|
// bundle's description and its rows. It is deliberately NOT a General
|
|
|
|
|
|
|
|
// settings row: a plugin's options belong to the plugin.
|
|
|
|
|
|
|
|
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
|
|
|
|
|
|
name: 'plugins.bundle.config',
|
|
|
|
|
|
|
|
key: PACKAGE_NAME,
|
|
|
|
locale: NS,
|
|
|
|
locale: NS,
|
|
|
|
inject: () => ({
|
|
|
|
inject: () => ({
|
|
|
|
store,
|
|
|
|
store,
|
|
|
@@ -985,7 +1119,7 @@ window.__ModuleLoader__.load({
|
|
|
|
test: sendTest,
|
|
|
|
test: sendTest,
|
|
|
|
setKind: setKindEnabled,
|
|
|
|
setKind: setKindEnabled,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}, SettingsRow))
|
|
|
|
}, ConfigSection))
|
|
|
|
|
|
|
|
|
|
|
|
// The observer lives in the frame-wide overlay, NOT in `sidebar.panellist`.
|
|
|
|
// The observer lives in the frame-wide overlay, NOT in `sidebar.panellist`.
|
|
|
|
//
|
|
|
|
//
|
|
|
|