dsh-task-cat 0.0.0-stage → 1.0.0
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.
- package/README.md +96 -2
- package/client.js +1486 -0
- package/cordis.patch.yml +3 -0
- package/desktop.js +559 -0
- package/icon.svg +15 -0
- package/index.js +561 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/overlay/TaskPetOverlay.swift +1566 -0
- package/package.json +50 -4
package/client.js
ADDED
|
@@ -0,0 +1,1486 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-task-cat — browser half.
|
|
3
|
+
*
|
|
4
|
+
* Draws one floating pet in the frame-wide `shell.overlay` layer. The pet reads
|
|
5
|
+
* the `taskPet` projection that the Host half attaches to every Session list row
|
|
6
|
+
* (progress of the open turn, todo list, goal, last tool) plus the Session
|
|
7
|
+
* status source (running, pending interaction, unread completion), so it shows
|
|
8
|
+
* what the whole app is doing, not only the conversation on stage.
|
|
9
|
+
*
|
|
10
|
+
* One click opens a compact roster; a row jumps straight into that conversation
|
|
11
|
+
* through `ctx.uiWorkspace.openSession`, which is the same navigation the
|
|
12
|
+
* sidebar and the schedule card use. The pet can be dragged and minimized, and
|
|
13
|
+
* stays inside the layer's own flow (the overlay is click-through; the entry
|
|
14
|
+
* opts back into pointer events).
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-task-cat
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
window.__ModuleLoader__.load({
|
|
20
|
+
id: 'dsh-task-cat',
|
|
21
|
+
factory(require) {
|
|
22
|
+
const React = require('react');
|
|
23
|
+
const h = React.createElement;
|
|
24
|
+
|
|
25
|
+
/** Locale namespace, also used for slot ids and CSS prefixes. */
|
|
26
|
+
const NS = 'dsh-task-cat';
|
|
27
|
+
|
|
28
|
+
/** Reads the app's active locale; replaced once `apply` runs. */
|
|
29
|
+
let activeLocale = () => '';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether the app is showing a light surface.
|
|
33
|
+
*
|
|
34
|
+
* The helper is a separate process with no access to the DOM, so it cannot
|
|
35
|
+
* ask; a dark card over a light app (or the reverse) is the most obvious way
|
|
36
|
+
* for two surfaces to look like two different products.
|
|
37
|
+
* @returns true for a light surface, false for dark, null when unknowable.
|
|
38
|
+
*/
|
|
39
|
+
function surfaceIsLight() {
|
|
40
|
+
try {
|
|
41
|
+
const background = getComputedStyle(document.body).backgroundColor;
|
|
42
|
+
const match = /rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/.exec(background);
|
|
43
|
+
if (match === null) return null;
|
|
44
|
+
const alpha = match[4] === undefined ? 1 : Number(match[4]);
|
|
45
|
+
// A transparent body says nothing about the surface underneath.
|
|
46
|
+
if (alpha < 0.2) return null;
|
|
47
|
+
const luminance = (0.2126 * Number(match[1]) + 0.7152 * Number(match[2]) + 0.0722 * Number(match[3])) / 255;
|
|
48
|
+
return luminance > 0.55;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The language tag to hand the desktop helper.
|
|
56
|
+
* @returns a tag such as `zh`, or an empty string when unknown.
|
|
57
|
+
*/
|
|
58
|
+
function currentLocale() {
|
|
59
|
+
try {
|
|
60
|
+
return activeLocale();
|
|
61
|
+
} catch {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Host route that drives the screen-wide helper. */
|
|
67
|
+
const OVERLAY_ROUTE = '/dsh-task-pet/overlay';
|
|
68
|
+
|
|
69
|
+
/** How often the roster is pushed to the helper while it is unchanged. */
|
|
70
|
+
const PUSH_INTERVAL_MS = 4000;
|
|
71
|
+
|
|
72
|
+
const DICT = {
|
|
73
|
+
zh: {
|
|
74
|
+
'pet.title': '任务宠物',
|
|
75
|
+
'pet.summary': '{running} 个会话进行中 · {attention} 个待查看',
|
|
76
|
+
'pet.summaryRunning': '{running} 个会话进行中',
|
|
77
|
+
'pet.summaryIdle': '一切安静,宠物在打盹',
|
|
78
|
+
'pet.summaryAttention': '{attention} 个会话待查看',
|
|
79
|
+
'pet.summaryQuiet': '暂无进行中的会话',
|
|
80
|
+
'pet.summaryFailed': '上次运行失败:{count}',
|
|
81
|
+
'pet.open': '展开任务宠物',
|
|
82
|
+
'pet.close': '收起任务列表',
|
|
83
|
+
'pet.minimize': '收起宠物',
|
|
84
|
+
'pet.restore': '展开宠物',
|
|
85
|
+
'pet.badge': '需要关注:{count}',
|
|
86
|
+
'desktop.on': '浮到整个屏幕',
|
|
87
|
+
'desktop.off': '收回窗口内',
|
|
88
|
+
'desktop.unsupported': '这个系统暂不支持桌面浮窗',
|
|
89
|
+
'desktop.hint': '桌面宠物会浮在其它软件之上,点它展开会话清单。',
|
|
90
|
+
'desktop.confirm': '开启桌面浮窗',
|
|
91
|
+
'desktop.cancel': '取消',
|
|
92
|
+
'desktop.explain': '开启后宠物会浮在所有窗口之上,可随时关闭。首次开启需要在后台编译一个小助手(约几秒)。',
|
|
93
|
+
'desktop.conflict': '另一个 Harness 窗口已经在显示桌面宠物,那个窗口关闭后这里会自动接管。',
|
|
94
|
+
'list.running': '进行中',
|
|
95
|
+
'list.attention': '待查看',
|
|
96
|
+
'list.failed': '上次运行失败',
|
|
97
|
+
'list.finished': '已完成',
|
|
98
|
+
'list.idle': '空闲',
|
|
99
|
+
'list.current': '当前会话',
|
|
100
|
+
'list.step': '第 {step} 步',
|
|
101
|
+
'list.goal': '目标:{objective}',
|
|
102
|
+
'list.jump': '打开对话',
|
|
103
|
+
'list.more': '还有 {count} 个会话',
|
|
104
|
+
'list.less': '收起',
|
|
105
|
+
'empty.title': '暂无任务',
|
|
106
|
+
'empty.body': '发一条消息,宠物就会开始跟踪进度。'
|
|
107
|
+
},
|
|
108
|
+
en: {
|
|
109
|
+
'pet.title': 'Task pet',
|
|
110
|
+
'pet.summary': '{running} running · {attention} to review',
|
|
111
|
+
'pet.summaryRunning': '{running} running',
|
|
112
|
+
'pet.summaryIdle': 'All quiet — the pet is napping',
|
|
113
|
+
'pet.summaryAttention': '{attention} to review',
|
|
114
|
+
'pet.summaryQuiet': 'Nothing is running',
|
|
115
|
+
'pet.summaryFailed': 'Last run failed: {count}',
|
|
116
|
+
'pet.open': 'Open the task pet',
|
|
117
|
+
'pet.close': 'Close the task list',
|
|
118
|
+
'pet.minimize': 'Hide the pet',
|
|
119
|
+
'pet.restore': 'Show the pet',
|
|
120
|
+
'pet.badge': 'Needs attention: {count}',
|
|
121
|
+
'desktop.on': 'Float on the whole screen',
|
|
122
|
+
'desktop.off': 'Bring it back into the window',
|
|
123
|
+
'desktop.unsupported': 'Desktop floating is unavailable on this system',
|
|
124
|
+
'desktop.hint': 'The desktop pet floats above other apps; click it to open the session list.',
|
|
125
|
+
'desktop.confirm': 'Turn it on',
|
|
126
|
+
'desktop.cancel': 'Cancel',
|
|
127
|
+
'desktop.explain': 'Turning this on floats the pet above every window; you can turn it off at any time. The first time, a small native helper is compiled in the background (a few seconds).',
|
|
128
|
+
'desktop.conflict': 'Another Harness window is already showing the desktop pet; this one takes over when that window closes.',
|
|
129
|
+
'list.running': 'Running',
|
|
130
|
+
'list.attention': 'Needs review',
|
|
131
|
+
'list.failed': 'Last run failed',
|
|
132
|
+
'list.finished': 'Done',
|
|
133
|
+
'list.idle': 'Idle',
|
|
134
|
+
'list.current': 'Current session',
|
|
135
|
+
'list.step': 'Step {step}',
|
|
136
|
+
'list.goal': 'Goal: {objective}',
|
|
137
|
+
'list.jump': 'Open conversation',
|
|
138
|
+
'list.more': '{count} more sessions',
|
|
139
|
+
'list.less': 'Show less',
|
|
140
|
+
'empty.title': 'No tasks yet',
|
|
141
|
+
'empty.body': 'Send a message and the pet starts tracking progress.'
|
|
142
|
+
},
|
|
143
|
+
ja: {
|
|
144
|
+
'pet.title': 'タスクペット',
|
|
145
|
+
'pet.summary': '実行中 {running} · 確認待ち {attention}',
|
|
146
|
+
'pet.summaryRunning': '実行中 {running}',
|
|
147
|
+
'pet.summaryIdle': '静かです — ペットは昼寝中',
|
|
148
|
+
'pet.summaryAttention': '確認待ち {attention} 件',
|
|
149
|
+
'pet.summaryQuiet': '実行中の会話はありません',
|
|
150
|
+
'pet.summaryFailed': '前回の失敗:{count}',
|
|
151
|
+
'pet.open': 'タスクペットを開く',
|
|
152
|
+
'pet.close': 'タスク一覧を閉じる',
|
|
153
|
+
'pet.minimize': 'ペットを隠す',
|
|
154
|
+
'pet.restore': 'ペットを表示',
|
|
155
|
+
'pet.badge': '対応が必要:{count}',
|
|
156
|
+
'desktop.on': '画面全体に浮かべる',
|
|
157
|
+
'desktop.off': 'ウィンドウ内に戻す',
|
|
158
|
+
'desktop.unsupported': 'この環境ではデスクトップ表示を使えません',
|
|
159
|
+
'desktop.hint': 'デスクトップペットは他のアプリの上に浮かび、クリックで会話一覧を開きます。',
|
|
160
|
+
'desktop.confirm': 'オンにする',
|
|
161
|
+
'desktop.cancel': 'キャンセル',
|
|
162
|
+
'desktop.explain': 'オンにするとペットがすべてのウィンドウの上に浮かびます。いつでもオフにできます。初回は小さなネイティブヘルパーを背後でビルドします(数秒)。',
|
|
163
|
+
'desktop.conflict': '別の Harness ウィンドウがデスクトップペットを表示中です。閉じるとこちらが引き継ぎます。',
|
|
164
|
+
'list.running': '実行中',
|
|
165
|
+
'list.attention': '確認待ち',
|
|
166
|
+
'list.failed': '前回の実行に失敗',
|
|
167
|
+
'list.finished': '完了',
|
|
168
|
+
'list.idle': '待機',
|
|
169
|
+
'list.current': '現在の会話',
|
|
170
|
+
'list.step': 'ステップ {step}',
|
|
171
|
+
'list.goal': '目標:{objective}',
|
|
172
|
+
'list.jump': '会話を開く',
|
|
173
|
+
'list.more': '他 {count} 件',
|
|
174
|
+
'list.less': '折りたたむ',
|
|
175
|
+
'empty.title': 'タスクはまだありません',
|
|
176
|
+
'empty.body': 'メッセージを送ると、ペットが進捗を追跡します。'
|
|
177
|
+
},
|
|
178
|
+
es: {
|
|
179
|
+
'pet.title': 'Mascota de tareas',
|
|
180
|
+
'pet.summary': '{running} en marcha · {attention} por revisar',
|
|
181
|
+
'pet.summaryRunning': '{running} en marcha',
|
|
182
|
+
'pet.summaryIdle': 'Todo tranquilo: la mascota duerme',
|
|
183
|
+
'pet.summaryAttention': '{attention} por revisar',
|
|
184
|
+
'pet.summaryQuiet': 'No hay nada en marcha',
|
|
185
|
+
'pet.summaryFailed': 'Falló la última ejecución: {count}',
|
|
186
|
+
'pet.open': 'Abrir la mascota de tareas',
|
|
187
|
+
'pet.close': 'Cerrar la lista de tareas',
|
|
188
|
+
'pet.minimize': 'Ocultar la mascota',
|
|
189
|
+
'pet.restore': 'Mostrar la mascota',
|
|
190
|
+
'pet.badge': 'Requiere atención: {count}',
|
|
191
|
+
'desktop.on': 'Flotar sobre toda la pantalla',
|
|
192
|
+
'desktop.off': 'Volver a la ventana',
|
|
193
|
+
'desktop.unsupported': 'La ventana flotante no está disponible en este sistema',
|
|
194
|
+
'desktop.hint': 'La mascota flota sobre otras aplicaciones; haz clic para ver la lista de conversaciones.',
|
|
195
|
+
'desktop.confirm': 'Activar',
|
|
196
|
+
'desktop.cancel': 'Cancelar',
|
|
197
|
+
'desktop.explain': 'Al activarlo, la mascota flota sobre todas las ventanas y puedes desactivarlo cuando quieras. La primera vez se compila un pequeño asistente nativo en segundo plano (unos segundos).',
|
|
198
|
+
'desktop.conflict': 'Otra ventana de Harness ya muestra la mascota; esta tomará el relevo cuando se cierre.',
|
|
199
|
+
'list.running': 'En marcha',
|
|
200
|
+
'list.attention': 'Por revisar',
|
|
201
|
+
'list.failed': 'Falló la última ejecución',
|
|
202
|
+
'list.finished': 'Listo',
|
|
203
|
+
'list.idle': 'Inactiva',
|
|
204
|
+
'list.current': 'Conversación actual',
|
|
205
|
+
'list.step': 'Paso {step}',
|
|
206
|
+
'list.goal': 'Objetivo: {objective}',
|
|
207
|
+
'list.jump': 'Abrir conversación',
|
|
208
|
+
'list.more': '{count} conversaciones más',
|
|
209
|
+
'list.less': 'Mostrar menos',
|
|
210
|
+
'empty.title': 'Aún no hay tareas',
|
|
211
|
+
'empty.body': 'Envía un mensaje y la mascota empezará a seguir el progreso.'
|
|
212
|
+
},
|
|
213
|
+
fr: {
|
|
214
|
+
'pet.title': 'Mascotte de tâches',
|
|
215
|
+
'pet.summary': '{running} en cours · {attention} à vérifier',
|
|
216
|
+
'pet.summaryRunning': '{running} en cours',
|
|
217
|
+
'pet.summaryIdle': 'Tout est calme — la mascotte somnole',
|
|
218
|
+
'pet.summaryAttention': '{attention} à vérifier',
|
|
219
|
+
'pet.summaryQuiet': 'Rien en cours',
|
|
220
|
+
'pet.summaryFailed': 'Dernière exécution échouée : {count}',
|
|
221
|
+
'pet.open': 'Ouvrir la mascotte de tâches',
|
|
222
|
+
'pet.close': 'Fermer la liste des tâches',
|
|
223
|
+
'pet.minimize': 'Masquer la mascotte',
|
|
224
|
+
'pet.restore': 'Afficher la mascotte',
|
|
225
|
+
'pet.badge': 'À vérifier : {count}',
|
|
226
|
+
'desktop.on': 'Flotter sur tout l’écran',
|
|
227
|
+
'desktop.off': 'Revenir dans la fenêtre',
|
|
228
|
+
'desktop.unsupported': 'La fenêtre flottante n’est pas disponible sur ce système',
|
|
229
|
+
'desktop.hint': 'La mascotte flotte au-dessus des autres applications ; cliquez pour ouvrir la liste des conversations.',
|
|
230
|
+
'desktop.confirm': 'Activer',
|
|
231
|
+
'desktop.cancel': 'Annuler',
|
|
232
|
+
'desktop.explain': 'En activant ceci, la mascotte flotte au-dessus de toutes les fenêtres ; vous pouvez la désactiver à tout moment. La première fois, un petit assistant natif est compilé en arrière-plan (quelques secondes).',
|
|
233
|
+
'desktop.conflict': 'Une autre fenêtre Harness affiche déjà la mascotte ; celle-ci prendra le relais à sa fermeture.',
|
|
234
|
+
'list.running': 'En cours',
|
|
235
|
+
'list.attention': 'À vérifier',
|
|
236
|
+
'list.failed': 'Dernière exécution échouée',
|
|
237
|
+
'list.finished': 'Terminé',
|
|
238
|
+
'list.idle': 'Inactive',
|
|
239
|
+
'list.current': 'Conversation actuelle',
|
|
240
|
+
'list.step': 'Étape {step}',
|
|
241
|
+
'list.goal': 'Objectif : {objective}',
|
|
242
|
+
'list.jump': 'Ouvrir la conversation',
|
|
243
|
+
'list.more': '{count} autres conversations',
|
|
244
|
+
'list.less': 'Afficher moins',
|
|
245
|
+
'empty.title': 'Aucune tâche pour le moment',
|
|
246
|
+
'empty.body': 'Envoyez un message et la mascotte suivra la progression.'
|
|
247
|
+
},
|
|
248
|
+
de: {
|
|
249
|
+
'pet.title': 'Aufgaben-Haustier',
|
|
250
|
+
'pet.summary': '{running} laufen · {attention} zu prüfen',
|
|
251
|
+
'pet.summaryRunning': '{running} laufen',
|
|
252
|
+
'pet.summaryIdle': 'Alles ruhig — das Haustier schläft',
|
|
253
|
+
'pet.summaryAttention': '{attention} zu prüfen',
|
|
254
|
+
'pet.summaryQuiet': 'Nichts läuft',
|
|
255
|
+
'pet.summaryFailed': 'Letzter Lauf fehlgeschlagen: {count}',
|
|
256
|
+
'pet.open': 'Aufgaben-Haustier öffnen',
|
|
257
|
+
'pet.close': 'Aufgabenliste schließen',
|
|
258
|
+
'pet.minimize': 'Haustier ausblenden',
|
|
259
|
+
'pet.restore': 'Haustier einblenden',
|
|
260
|
+
'pet.badge': 'Zu prüfen: {count}',
|
|
261
|
+
'desktop.on': 'Auf dem ganzen Bildschirm schweben',
|
|
262
|
+
'desktop.off': 'Zurück ins Fenster',
|
|
263
|
+
'desktop.unsupported': 'Schwebefenster ist auf diesem System nicht verfügbar',
|
|
264
|
+
'desktop.hint': 'Das Haustier schwebt über anderen Programmen; klicke darauf, um die Unterhaltungsliste zu öffnen.',
|
|
265
|
+
'desktop.confirm': 'Einschalten',
|
|
266
|
+
'desktop.cancel': 'Abbrechen',
|
|
267
|
+
'desktop.explain': 'Eingeschaltet schwebt das Haustier über allen Fenstern; du kannst es jederzeit ausschalten. Beim ersten Mal wird im Hintergrund ein kleiner nativer Helfer kompiliert (einige Sekunden).',
|
|
268
|
+
'desktop.conflict': 'Ein anderes Harness-Fenster zeigt das Haustier bereits; dieses übernimmt, sobald es schließt.',
|
|
269
|
+
'list.running': 'Läuft',
|
|
270
|
+
'list.attention': 'Zu prüfen',
|
|
271
|
+
'list.failed': 'Letzter Lauf fehlgeschlagen',
|
|
272
|
+
'list.finished': 'Fertig',
|
|
273
|
+
'list.idle': 'Inaktiv',
|
|
274
|
+
'list.current': 'Aktuelle Unterhaltung',
|
|
275
|
+
'list.step': 'Schritt {step}',
|
|
276
|
+
'list.goal': 'Ziel: {objective}',
|
|
277
|
+
'list.jump': 'Unterhaltung öffnen',
|
|
278
|
+
'list.more': '{count} weitere Unterhaltungen',
|
|
279
|
+
'list.less': 'Weniger anzeigen',
|
|
280
|
+
'empty.title': 'Noch keine Aufgaben',
|
|
281
|
+
'empty.body': 'Sende eine Nachricht, dann verfolgt das Haustier den Fortschritt.'
|
|
282
|
+
},
|
|
283
|
+
ru: {
|
|
284
|
+
'pet.title': 'Питомец задач',
|
|
285
|
+
'pet.summary': '{running} выполняется · {attention} проверить',
|
|
286
|
+
'pet.summaryRunning': '{running} выполняется',
|
|
287
|
+
'pet.summaryIdle': 'Всё тихо — питомец дремлет',
|
|
288
|
+
'pet.summaryAttention': '{attention} проверить',
|
|
289
|
+
'pet.summaryQuiet': 'Ничего не выполняется',
|
|
290
|
+
'pet.summaryFailed': 'Прошлый запуск с ошибкой: {count}',
|
|
291
|
+
'pet.open': 'Открыть питомца задач',
|
|
292
|
+
'pet.close': 'Закрыть список задач',
|
|
293
|
+
'pet.minimize': 'Скрыть питомца',
|
|
294
|
+
'pet.restore': 'Показать питомца',
|
|
295
|
+
'pet.badge': 'Требуют внимания: {count}',
|
|
296
|
+
'desktop.on': 'Поверх всего экрана',
|
|
297
|
+
'desktop.off': 'Вернуть в окно',
|
|
298
|
+
'desktop.unsupported': 'Плавающее окно недоступно в этой системе',
|
|
299
|
+
'desktop.hint': 'Питомец парит над другими программами; нажмите, чтобы открыть список диалогов.',
|
|
300
|
+
'desktop.confirm': 'Включить',
|
|
301
|
+
'desktop.cancel': 'Отмена',
|
|
302
|
+
'desktop.explain': 'Если включить, питомец будет парить над всеми окнами; выключить можно в любой момент. В первый раз в фоне собирается небольшой нативный помощник (несколько секунд).',
|
|
303
|
+
'desktop.conflict': 'В другом окне Harness уже показан питомец; это окно подхватит его после закрытия того.',
|
|
304
|
+
'list.running': 'Выполняется',
|
|
305
|
+
'list.attention': 'Проверить',
|
|
306
|
+
'list.failed': 'Прошлый запуск с ошибкой',
|
|
307
|
+
'list.finished': 'Готово',
|
|
308
|
+
'list.idle': 'Простой',
|
|
309
|
+
'list.current': 'Текущий диалог',
|
|
310
|
+
'list.step': 'Шаг {step}',
|
|
311
|
+
'list.goal': 'Цель: {objective}',
|
|
312
|
+
'list.jump': 'Открыть диалог',
|
|
313
|
+
'list.more': 'Ещё диалогов: {count}',
|
|
314
|
+
'list.less': 'Свернуть',
|
|
315
|
+
'empty.title': 'Задач пока нет',
|
|
316
|
+
'empty.body': 'Отправьте сообщение, и питомец начнёт следить за прогрессом.'
|
|
317
|
+
},
|
|
318
|
+
pt: {
|
|
319
|
+
'pet.title': 'Mascote de tarefas',
|
|
320
|
+
'pet.summary': '{running} em execução · {attention} para revisar',
|
|
321
|
+
'pet.summaryRunning': '{running} em execução',
|
|
322
|
+
'pet.summaryIdle': 'Tudo calmo — a mascote cochila',
|
|
323
|
+
'pet.summaryAttention': '{attention} para revisar',
|
|
324
|
+
'pet.summaryQuiet': 'Nada em execução',
|
|
325
|
+
'pet.summaryFailed': 'Última execução falhou: {count}',
|
|
326
|
+
'pet.open': 'Abrir a mascote de tarefas',
|
|
327
|
+
'pet.close': 'Fechar a lista de tarefas',
|
|
328
|
+
'pet.minimize': 'Ocultar a mascote',
|
|
329
|
+
'pet.restore': 'Mostrar a mascote',
|
|
330
|
+
'pet.badge': 'Precisa de atenção: {count}',
|
|
331
|
+
'desktop.on': 'Flutuar sobre toda a tela',
|
|
332
|
+
'desktop.off': 'Voltar para a janela',
|
|
333
|
+
'desktop.unsupported': 'A janela flutuante não está disponível neste sistema',
|
|
334
|
+
'desktop.hint': 'A mascote flutua sobre os outros aplicativos; clique para abrir a lista de conversas.',
|
|
335
|
+
'desktop.confirm': 'Ativar',
|
|
336
|
+
'desktop.cancel': 'Cancelar',
|
|
337
|
+
'desktop.explain': 'Ao ativar, a mascote flutua sobre todas as janelas e pode ser desativada a qualquer momento. Na primeira vez, um pequeno assistente nativo é compilado em segundo plano (alguns segundos).',
|
|
338
|
+
'desktop.conflict': 'Outra janela do Harness já mostra a mascote; esta assume quando ela for fechada.',
|
|
339
|
+
'list.running': 'Em execução',
|
|
340
|
+
'list.attention': 'Para revisar',
|
|
341
|
+
'list.failed': 'Última execução falhou',
|
|
342
|
+
'list.finished': 'Concluído',
|
|
343
|
+
'list.idle': 'Inativa',
|
|
344
|
+
'list.current': 'Conversa atual',
|
|
345
|
+
'list.step': 'Passo {step}',
|
|
346
|
+
'list.goal': 'Meta: {objective}',
|
|
347
|
+
'list.jump': 'Abrir conversa',
|
|
348
|
+
'list.more': 'Mais {count} conversas',
|
|
349
|
+
'list.less': 'Mostrar menos',
|
|
350
|
+
'empty.title': 'Nenhuma tarefa ainda',
|
|
351
|
+
'empty.body': 'Envie uma mensagem e a mascote começa a acompanhar o progresso.'
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Row-level equality so the pet re-renders only when a listed fact changes.
|
|
357
|
+
* @param left - previous selector result.
|
|
358
|
+
* @param right - next selector result.
|
|
359
|
+
* @returns true when both rows arrays describe the same display state.
|
|
360
|
+
*/
|
|
361
|
+
function sameRows(left, right) {
|
|
362
|
+
if (left === right) return true;
|
|
363
|
+
if (left.length !== right.length) return false;
|
|
364
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
365
|
+
const a = left[index];
|
|
366
|
+
const b = right[index];
|
|
367
|
+
if (a.id !== b.id || a.title !== b.title || a.running !== b.running
|
|
368
|
+
|| a.current !== b.current || a.updatedAt !== b.updatedAt
|
|
369
|
+
|| !samePet(a.pet, b.pet)) return false;
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Whether two archived-id snapshots describe the same set.
|
|
376
|
+
* @param left - previous selector result.
|
|
377
|
+
* @param right - next selector result.
|
|
378
|
+
* @returns true when both name the same archived Sessions in the same order.
|
|
379
|
+
*/
|
|
380
|
+
function sameArchived(left, right) {
|
|
381
|
+
if (left === right) return true;
|
|
382
|
+
if (left.length !== right.length) return false;
|
|
383
|
+
for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Repair one `taskPet` wire value into the facts the roster reads.
|
|
389
|
+
*
|
|
390
|
+
* The Host half validates this shape before publishing it, so a value only
|
|
391
|
+
* arrives damaged when the row is stale (a checkpoint written by an older
|
|
392
|
+
* stateVersion, a summary frame that predates a field). Repairing it here
|
|
393
|
+
* costs nothing and keeps one odd row from throwing inside the overlay
|
|
394
|
+
* entry, which would take the whole pet down instead of one label.
|
|
395
|
+
* @param value - candidate row projection value.
|
|
396
|
+
* @returns display facts, or null when the row carries nothing usable.
|
|
397
|
+
*/
|
|
398
|
+
function petOf(value) {
|
|
399
|
+
if (value === null || typeof value !== 'object') return null;
|
|
400
|
+
const count = (input) => (Number.isFinite(input) && input > 0 ? Math.round(input) : 0);
|
|
401
|
+
const todos = value.todos;
|
|
402
|
+
const goal = value.goal;
|
|
403
|
+
const total = todos === null || typeof todos !== 'object' ? 0 : count(todos.total);
|
|
404
|
+
return {
|
|
405
|
+
active: value.active === true,
|
|
406
|
+
startedAt: Number.isFinite(value.startedAt) ? value.startedAt : null,
|
|
407
|
+
turn: count(value.turn),
|
|
408
|
+
step: count(value.step),
|
|
409
|
+
ending: typeof value.ending === 'string' ? value.ending : null,
|
|
410
|
+
lastTool: typeof value.lastTool === 'string' && value.lastTool !== '' ? value.lastTool : null,
|
|
411
|
+
lastToolError: value.lastToolError === true,
|
|
412
|
+
todos: total === 0
|
|
413
|
+
? null
|
|
414
|
+
: { total, completed: Math.min(total, Math.max(0, count(todos.completed))) },
|
|
415
|
+
goal: goal !== null && typeof goal === 'object' && typeof goal.objective === 'string' && goal.objective !== ''
|
|
416
|
+
? { objective: goal.objective }
|
|
417
|
+
: null
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Compare two repaired pet values field by field. `petOf` allocates, so
|
|
423
|
+
* reference equality would report every snapshot as a change and re-render
|
|
424
|
+
* the roster on unrelated Session traffic.
|
|
425
|
+
* @param left - previous value.
|
|
426
|
+
* @param right - next value.
|
|
427
|
+
* @returns true when both describe the same progress facts.
|
|
428
|
+
*/
|
|
429
|
+
function samePet(left, right) {
|
|
430
|
+
if (left === right) return true;
|
|
431
|
+
if (left === null || right === null) return false;
|
|
432
|
+
if (left.active !== right.active || left.startedAt !== right.startedAt
|
|
433
|
+
|| left.turn !== right.turn || left.step !== right.step
|
|
434
|
+
|| left.ending !== right.ending || left.lastTool !== right.lastTool
|
|
435
|
+
|| left.lastToolError !== right.lastToolError) return false;
|
|
436
|
+
const a = left.todos;
|
|
437
|
+
const b = right.todos;
|
|
438
|
+
if ((a === null) !== (b === null)) return false;
|
|
439
|
+
if (a !== null && (a.total !== b.total || a.completed !== b.completed)) return false;
|
|
440
|
+
const x = left.goal;
|
|
441
|
+
const y = right.goal;
|
|
442
|
+
if ((x === null) !== (y === null)) return false;
|
|
443
|
+
return x === null || x.objective === y.objective;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Whether two helper status replies describe the same display state.
|
|
448
|
+
* @param left - previous status, or null before the first reply.
|
|
449
|
+
* @param right - next status.
|
|
450
|
+
* @returns true when the pet should not re-render for it.
|
|
451
|
+
*/
|
|
452
|
+
function sameStatus(left, right) {
|
|
453
|
+
if (left === null || left === undefined) return false;
|
|
454
|
+
return left.supported === right.supported
|
|
455
|
+
&& left.enabled === right.enabled
|
|
456
|
+
&& left.running === right.running
|
|
457
|
+
&& left.compiling === right.compiling
|
|
458
|
+
&& (left.conflict === true) === (right.conflict === true)
|
|
459
|
+
&& (left.error ?? null) === (right.error ?? null);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Drive the screen-wide desktop pet.
|
|
464
|
+
*
|
|
465
|
+
* The page owns the roster; the helper only draws it. Two channels: a POST
|
|
466
|
+
* pushes the current facts, and a long poll brings click intents back. Only
|
|
467
|
+
* loopback reaches this route, and a failure here must never disturb the
|
|
468
|
+
* in-window pet, so every call is best-effort.
|
|
469
|
+
*
|
|
470
|
+
* @param report - current display facts for the helper.
|
|
471
|
+
* @param signal - cancels an in-flight request.
|
|
472
|
+
* @returns the helper status, or null when the route is unavailable.
|
|
473
|
+
*/
|
|
474
|
+
async function pushDesktop(report, signal) {
|
|
475
|
+
try {
|
|
476
|
+
const response = await fetch(OVERLAY_ROUTE, {
|
|
477
|
+
method: 'POST',
|
|
478
|
+
headers: { 'content-type': 'application/json' },
|
|
479
|
+
body: JSON.stringify(report),
|
|
480
|
+
signal
|
|
481
|
+
});
|
|
482
|
+
if (!response.ok) return null;
|
|
483
|
+
const body = await response.json();
|
|
484
|
+
return typeof body === 'object' && body !== null ? body : null;
|
|
485
|
+
} catch {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Wait for one click intent from the helper.
|
|
492
|
+
* @param signal - cancels the poll (including on unmount).
|
|
493
|
+
* @returns the intents and the helper status, or null when the poll failed.
|
|
494
|
+
*/
|
|
495
|
+
async function pollDesktop(signal) {
|
|
496
|
+
try {
|
|
497
|
+
const response = await fetch(OVERLAY_ROUTE, { signal, cache: 'no-store' });
|
|
498
|
+
if (!response.ok) return null;
|
|
499
|
+
const body = await response.json();
|
|
500
|
+
return typeof body === 'object' && body !== null ? body : null;
|
|
501
|
+
} catch {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Build the display roster from the Session list snapshot.
|
|
508
|
+
* @param state - `useSessions` snapshot (`ids`, `byId`).
|
|
509
|
+
* @returns rows for display, in list order.
|
|
510
|
+
*/
|
|
511
|
+
function rosterOf(state) {
|
|
512
|
+
const rows = [];
|
|
513
|
+
for (const id of state.ids) {
|
|
514
|
+
const row = state.byId[id];
|
|
515
|
+
if (row === undefined || row.blank === true || row.origin === 'subagent') continue;
|
|
516
|
+
rows.push({
|
|
517
|
+
id,
|
|
518
|
+
title: typeof row.displayTitle === 'string' && row.displayTitle !== '' ? row.displayTitle : id,
|
|
519
|
+
running: row.running === true,
|
|
520
|
+
current: (row.retainedBy === undefined ? 0 : row.retainedBy.mainView ?? 0) > 0,
|
|
521
|
+
pet: petOf(row.projectionValues === undefined ? null : row.projectionValues.taskPet),
|
|
522
|
+
updatedAt: typeof row.updatedAt === 'number' ? row.updatedAt : 0
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
return rows;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Classify one row for the roster and for the pet's mood.
|
|
530
|
+
* @param row - roster row.
|
|
531
|
+
* @param status - that Session's status record, when known.
|
|
532
|
+
* @returns `running`, `attention`, `progress`, `finished`, or `idle`.
|
|
533
|
+
*/
|
|
534
|
+
function rowKind(row, status) {
|
|
535
|
+
// A Session waiting for an answer outranks a plain completion reminder:
|
|
536
|
+
// the pet taps the user when the agent cannot continue without them.
|
|
537
|
+
if (status?.pendingInteraction !== undefined && status.pendingInteraction !== null) return 'attention';
|
|
538
|
+
if (row.running || row.pet?.active === true) return 'running';
|
|
539
|
+
if (status?.completionUnread === true) return 'attention';
|
|
540
|
+
const todos = row.pet?.todos;
|
|
541
|
+
if (todos !== null && todos !== undefined && todos.completed < todos.total) return 'progress';
|
|
542
|
+
// A failed or blocked turn is worth a red dot, but it must not raise the
|
|
543
|
+
// unread badge: that badge clears only when the user opens the Session,
|
|
544
|
+
// and a permanently stuck counter would train the user to ignore it.
|
|
545
|
+
if (row.pet?.ending === 'error' || row.pet?.ending === 'blocked') return 'failed';
|
|
546
|
+
if (row.pet !== null && row.pet.ending !== null) return 'finished';
|
|
547
|
+
return 'idle';
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** Display priority of one kind; the roster lists the most urgent first. */
|
|
551
|
+
const KIND_ORDER = { running: 0, attention: 1, progress: 2, failed: 3, finished: 4, idle: 5 };
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Format an elapsed duration for the roster.
|
|
555
|
+
* @param milliseconds - non-negative duration.
|
|
556
|
+
* @returns a compact label such as `12s`, `4m`, or `2h`.
|
|
557
|
+
*/
|
|
558
|
+
function elapsedLabel(milliseconds) {
|
|
559
|
+
const seconds = Math.max(0, Math.round(milliseconds / 1000));
|
|
560
|
+
if (seconds < 60) return `${seconds}s`;
|
|
561
|
+
const minutes = Math.floor(seconds / 60);
|
|
562
|
+
if (minutes < 60) return `${minutes}m`;
|
|
563
|
+
return `${Math.floor(minutes / 60)}h`;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* The pet's own drawing. Artwork uses fixed colors so it reads on both
|
|
568
|
+
* themes; the surrounding chrome uses theme tokens.
|
|
569
|
+
* @param props.mood - `working`, `alert`, `idle`, or `sleeping`.
|
|
570
|
+
* @param props.size - rendered size in pixels.
|
|
571
|
+
* @param props.decorated - whether the mood mark is drawn (default true).
|
|
572
|
+
* @returns the pet illustration.
|
|
573
|
+
*/
|
|
574
|
+
function PetArt({ mood, size, decorated = true }) {
|
|
575
|
+
// The same cat the desktop pet draws, in the same 64-unit box, so the two
|
|
576
|
+
// surfaces cannot drift apart.
|
|
577
|
+
// `decorated: false` suppresses the artwork's own alert disc so it cannot
|
|
578
|
+
// fight the DOM badge for the same corner.
|
|
579
|
+
const alert = mood === 'alert' && decorated;
|
|
580
|
+
const working = mood === 'working';
|
|
581
|
+
const asleep = mood === 'sleeping';
|
|
582
|
+
const fur = '#fcfaf7';
|
|
583
|
+
const furShade = '#e8e2da';
|
|
584
|
+
const earInner = '#f6c4cd';
|
|
585
|
+
const blush = 'rgba(249, 179, 180, 0.45)';
|
|
586
|
+
const ink = '#272321';
|
|
587
|
+
const nose = '#ecb0b8';
|
|
588
|
+
return h('svg', {
|
|
589
|
+
viewBox: '0 0 64 64',
|
|
590
|
+
width: size,
|
|
591
|
+
height: size,
|
|
592
|
+
role: 'presentation',
|
|
593
|
+
'aria-hidden': true,
|
|
594
|
+
style: { display: 'block', overflow: 'visible' }
|
|
595
|
+
},
|
|
596
|
+
h('ellipse', { cx: 32, cy: 60.25, rx: 16, ry: 2.75, fill: 'rgba(60, 52, 46, 0.13)' }),
|
|
597
|
+
// tail: a slim curl that sways
|
|
598
|
+
h('g', { className: 'dsh-task-pet-tail' },
|
|
599
|
+
h('path', { d: 'M44 54C55 54 59 46 56 38', fill: 'none', stroke: furShade, strokeWidth: 7, strokeLinecap: 'round' }),
|
|
600
|
+
h('path', { d: 'M44 54C55 54 59 46 56 38', fill: 'none', stroke: fur, strokeWidth: 5, strokeLinecap: 'round' })
|
|
601
|
+
),
|
|
602
|
+
// body, breathing
|
|
603
|
+
h('g', { className: 'dsh-task-pet-breathe' },
|
|
604
|
+
h('rect', { x: 17, y: 34, width: 30, height: 25, rx: 13, fill: fur }),
|
|
605
|
+
h('circle', { cx: 22, cy: 57, r: 4.6, fill: fur }),
|
|
606
|
+
h('circle', { cx: 30, cy: 58.5, r: 5, fill: fur }),
|
|
607
|
+
h('circle', { cx: 38, cy: 58.5, r: 5, fill: fur }),
|
|
608
|
+
h('circle', { cx: 44, cy: 57, r: 4.6, fill: fur }),
|
|
609
|
+
h('ellipse', { cx: 32, cy: 52.5, rx: 5.5, ry: 5, fill: 'rgba(255, 255, 255, 0.85)' })
|
|
610
|
+
),
|
|
611
|
+
// head and its pillow tufts
|
|
612
|
+
h('circle', { cx: 32, cy: 26, r: 17, fill: fur }),
|
|
613
|
+
h('g', { fill: fur },
|
|
614
|
+
h('circle', { cx: 24.5, cy: 12.5, r: 3.8, key: 't1' }),
|
|
615
|
+
h('circle', { cx: 32, cy: 10, r: 4.2, key: 't2' }),
|
|
616
|
+
h('circle', { cx: 39.5, cy: 12.5, r: 3.8, key: 't3' }),
|
|
617
|
+
h('circle', { cx: 18.5, cy: 29.5, r: 3.6, key: 't4' }),
|
|
618
|
+
h('circle', { cx: 45.5, cy: 29.5, r: 3.6, key: 't5' }),
|
|
619
|
+
h('circle', { cx: 20, cy: 21, r: 3.4, key: 't6' }),
|
|
620
|
+
h('circle', { cx: 44, cy: 21, r: 3.4, key: 't7' })
|
|
621
|
+
),
|
|
622
|
+
h('ellipse', { cx: 32, cy: 39.5, rx: 9.5, ry: 2.2, fill: 'rgba(60, 52, 46, 0.05)' }),
|
|
623
|
+
// ears
|
|
624
|
+
h('path', { d: 'M18 17Q22.4 9 24.2 8Q26.4 11 28 17Z', fill: fur }),
|
|
625
|
+
h('path', { d: 'M46 17Q41.6 9 39.8 8Q37.6 11 36 17Z', fill: fur }),
|
|
626
|
+
h('path', { d: 'M20.6 17L24 11.4L25.4 17Z', fill: earInner }),
|
|
627
|
+
h('path', { d: 'M43.4 17L40 11.4L38.6 17Z', fill: earInner }),
|
|
628
|
+
// eyes
|
|
629
|
+
asleep
|
|
630
|
+
? h('path', {
|
|
631
|
+
d: 'M22.4 25.7Q25.6 23.5 28.8 25.7M35.2 25.7Q38.4 23.5 41.6 25.7',
|
|
632
|
+
fill: 'none', stroke: ink, strokeWidth: 2, strokeLinecap: 'round'
|
|
633
|
+
})
|
|
634
|
+
: h('g', { className: 'dsh-task-pet-blink' },
|
|
635
|
+
h('ellipse', { cx: 25.6, cy: 26.5, rx: alert ? 4.3 : 4, ry: alert ? 4.6 : 4.3, fill: ink }),
|
|
636
|
+
h('ellipse', { cx: 38.4, cy: 26.5, rx: alert ? 4.3 : 4, ry: alert ? 4.6 : 4.3, fill: ink }),
|
|
637
|
+
h('circle', { cx: 24.55, cy: 24.55, r: 1.05, fill: '#fff' }),
|
|
638
|
+
h('circle', { cx: 37.35, cy: 24.55, r: 1.05, fill: '#fff' }),
|
|
639
|
+
h('circle', { cx: 27.15, cy: 27.85, r: 0.55, fill: '#fff' }),
|
|
640
|
+
h('circle', { cx: 39.95, cy: 27.85, r: 0.55, fill: '#fff' })
|
|
641
|
+
),
|
|
642
|
+
// blush
|
|
643
|
+
h('ellipse', { cx: 20.75, cy: 31.5, rx: 3.25, ry: 2, fill: blush }),
|
|
644
|
+
h('ellipse', { cx: 43.25, cy: 31.5, rx: 3.25, ry: 2, fill: blush }),
|
|
645
|
+
// nose and the small "w" mouth
|
|
646
|
+
h('path', { d: 'M30.6 32.2Q32 31 33.4 32.2Z', fill: nose }),
|
|
647
|
+
h('path', {
|
|
648
|
+
d: 'M32 33.8Q30.6 35.9 29.4 34M32 33.8Q33.4 35.9 34.6 34',
|
|
649
|
+
fill: 'none', stroke: ink, strokeWidth: 1.25, strokeLinecap: 'round'
|
|
650
|
+
}),
|
|
651
|
+
// whiskers
|
|
652
|
+
h('path', {
|
|
653
|
+
d: 'M24.5 32.5L17.5 31.6M24.5 34.2L18 35.4M39.5 32.5L46.5 31.6M39.5 34.2L46 35.4',
|
|
654
|
+
stroke: 'rgba(115, 107, 99, 0.28)', strokeWidth: 0.9, strokeLinecap: 'round', fill: 'none'
|
|
655
|
+
}),
|
|
656
|
+
// mood marks
|
|
657
|
+
alert ? h('g', null,
|
|
658
|
+
h('circle', { cx: 50, cy: 13, r: 7, fill: earInner }),
|
|
659
|
+
h('path', { d: 'M50 9.4v4.4M50 16.6v.5', fill: 'none', stroke: '#fff', strokeWidth: 2.2, strokeLinecap: 'round' })
|
|
660
|
+
) : null,
|
|
661
|
+
working ? h('g', { fill: '#4c90f2' },
|
|
662
|
+
h('circle', { cx: 50, cy: 12, r: 2.2, opacity: 0.85 }),
|
|
663
|
+
h('circle', { cx: 56, cy: 16, r: 1.6, opacity: 0.55 }),
|
|
664
|
+
h('circle', { cx: 60, cy: 22, r: 1.1, opacity: 0.3 })
|
|
665
|
+
) : null,
|
|
666
|
+
asleep ? h('g', { fill: '#9d968d', fontFamily: 'inherit', fontSize: 8, fontWeight: 600 },
|
|
667
|
+
h('text', { x: 50, y: 18 }, 'z'),
|
|
668
|
+
h('text', { x: 56, y: 12, fontSize: 6 }, 'z')
|
|
669
|
+
) : null);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Pet-relative styles: one component-local `<style>` element, so unmounting
|
|
674
|
+
* the entry removes every rule and keyframe with it.
|
|
675
|
+
* @returns the style element.
|
|
676
|
+
*/
|
|
677
|
+
function PetStyles() {
|
|
678
|
+
const css = `
|
|
679
|
+
/* The frame's own rule for overlay entries is one class on a child selector —
|
|
680
|
+
the same specificity as a single class — so the doubled class keeps this layer
|
|
681
|
+
click-through no matter which stylesheet the browser placed later. */
|
|
682
|
+
.dsh-task-pet-root.dsh-task-pet-root {
|
|
683
|
+
position: fixed;
|
|
684
|
+
z-index: 30;
|
|
685
|
+
display: flex;
|
|
686
|
+
flex-direction: column;
|
|
687
|
+
align-items: flex-end;
|
|
688
|
+
gap: 10px;
|
|
689
|
+
pointer-events: none;
|
|
690
|
+
font-family: inherit;
|
|
691
|
+
}
|
|
692
|
+
/* The anchor is only a stacking column: it must stay click-through, or the
|
|
693
|
+
gap between the panel and the pet would swallow clicks on the app below. */
|
|
694
|
+
/* Column-reverse keeps the panel painted above the trigger while the trigger
|
|
695
|
+
stays first in DOM order for Tab. */
|
|
696
|
+
.dsh-task-pet-anchor { pointer-events: none; display: flex; flex-direction: column-reverse; align-items: flex-end; gap: 8px; }
|
|
697
|
+
.dsh-task-pet-button {
|
|
698
|
+
position: relative;
|
|
699
|
+
width: 64px;
|
|
700
|
+
height: 64px;
|
|
701
|
+
padding: 6px;
|
|
702
|
+
border: none;
|
|
703
|
+
border-radius: 22px;
|
|
704
|
+
background: var(--dsw-alias-button-floating-fill, var(--dsw-alias-bg-layer-1));
|
|
705
|
+
box-shadow: var(--dsw-elevation-soft, 0 0 0 0.5px var(--dsw-alias-border-l1));
|
|
706
|
+
cursor: pointer;
|
|
707
|
+
pointer-events: auto;
|
|
708
|
+
display: grid;
|
|
709
|
+
place-items: center;
|
|
710
|
+
transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
|
|
711
|
+
touch-action: none;
|
|
712
|
+
}
|
|
713
|
+
/* The bob rides the artwork, not the button: an animation on the button would
|
|
714
|
+
own the transform property and win over the hover lift. */
|
|
715
|
+
.dsh-task-pet-button > svg { animation: dsh-task-pet-bob 3.6s ease-in-out infinite; }
|
|
716
|
+
.dsh-task-pet-button[data-working] > svg { animation-duration: 1.8s; }
|
|
717
|
+
.dsh-task-pet-button[data-dragging] > svg { animation: none; }
|
|
718
|
+
.dsh-task-pet-button[data-dragging] { transition: none; }
|
|
719
|
+
@media (hover: hover) {
|
|
720
|
+
.dsh-task-pet-button:hover { transform: translateY(-2px) scale(1.03); }
|
|
721
|
+
}
|
|
722
|
+
.dsh-task-pet-button:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 3px; }
|
|
723
|
+
.dsh-task-pet-badge {
|
|
724
|
+
position: absolute;
|
|
725
|
+
top: -5px;
|
|
726
|
+
right: -6px;
|
|
727
|
+
min-width: 20px;
|
|
728
|
+
height: 20px;
|
|
729
|
+
padding: 0 5px;
|
|
730
|
+
border-radius: 10px;
|
|
731
|
+
background: var(--dsw-alias-brand-primary);
|
|
732
|
+
color: var(--dsw-alias-label-primary-foreground, #fff);
|
|
733
|
+
font-size: 11px;
|
|
734
|
+
font-weight: 600;
|
|
735
|
+
line-height: 20px;
|
|
736
|
+
text-align: center;
|
|
737
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
|
|
738
|
+
}
|
|
739
|
+
.dsh-task-pet-badge[data-attention] { background: var(--dsw-alias-state-warn-primary); color: #1f1a08; }
|
|
740
|
+
.dsh-task-pet-fab { position: relative; }
|
|
741
|
+
.dsh-task-pet-badge-fab { top: -6px; right: -7px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; font-size: 10px; line-height: 17px; }
|
|
742
|
+
.dsh-task-pet-panel {
|
|
743
|
+
width: min(324px, calc(100vw - 32px));
|
|
744
|
+
max-height: min(52vh, 360px);
|
|
745
|
+
box-sizing: border-box;
|
|
746
|
+
display: flex;
|
|
747
|
+
flex-direction: column;
|
|
748
|
+
border-radius: 16px;
|
|
749
|
+
background: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-1));
|
|
750
|
+
box-shadow: var(--dsw-elevation-panel, 0 0 0 0.5px var(--dsw-alias-border-l1));
|
|
751
|
+
backdrop-filter: var(--dsw-menu-backdrop-filter, none);
|
|
752
|
+
overflow: hidden;
|
|
753
|
+
pointer-events: auto;
|
|
754
|
+
animation: dsh-task-pet-rise 160ms ease;
|
|
755
|
+
}
|
|
756
|
+
.dsh-task-pet-head {
|
|
757
|
+
display: flex;
|
|
758
|
+
align-items: center;
|
|
759
|
+
gap: 8px;
|
|
760
|
+
padding: 12px 12px 8px 14px;
|
|
761
|
+
}
|
|
762
|
+
.dsh-task-pet-title { font-size: 13px; font-weight: 600; color: var(--dsw-alias-label-primary); }
|
|
763
|
+
.dsh-task-pet-summary { font-size: 11px; line-height: 15px; color: var(--dsw-alias-label-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
764
|
+
.dsh-task-pet-head-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
|
|
765
|
+
.dsh-task-pet-head-actions { margin-left: auto; display: flex; gap: 2px; flex: none; }
|
|
766
|
+
.dsh-task-pet-icon-button {
|
|
767
|
+
width: 24px; height: 24px; padding: 0;
|
|
768
|
+
display: grid; place-items: center;
|
|
769
|
+
border: none; border-radius: 7px;
|
|
770
|
+
background: transparent;
|
|
771
|
+
color: var(--dsw-alias-label-secondary);
|
|
772
|
+
cursor: pointer;
|
|
773
|
+
}
|
|
774
|
+
.dsh-task-pet-icon-button:hover { background: var(--dsw-alias-bg-layer-2, rgba(127, 127, 127, 0.12)); color: var(--dsw-alias-label-primary); }
|
|
775
|
+
.dsh-task-pet-icon-button[data-desktop-on] { color: var(--dsw-alias-brand-primary); }
|
|
776
|
+
.dsh-task-pet-icon-button:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
|
|
777
|
+
.dsh-task-pet-hint { padding: 0 14px 8px; font-size: 11px; line-height: 15px; color: var(--dsw-alias-label-secondary); }
|
|
778
|
+
.dsh-task-pet-confirm { padding: 0 14px 10px; display: flex; flex-direction: column; gap: 8px; }
|
|
779
|
+
.dsh-task-pet-hint-text { font-size: 11px; line-height: 15px; color: var(--dsw-alias-label-secondary); }
|
|
780
|
+
.dsh-task-pet-confirm-actions { display: flex; gap: 6px; justify-content: flex-end; }
|
|
781
|
+
.dsh-task-pet-action {
|
|
782
|
+
padding: 4px 10px; border: none; border-radius: 8px; cursor: pointer;
|
|
783
|
+
font: inherit; font-size: 11.5px; line-height: 16px;
|
|
784
|
+
background: var(--dsw-alias-brand-primary);
|
|
785
|
+
color: var(--dsw-alias-label-primary-foreground, #fff);
|
|
786
|
+
}
|
|
787
|
+
.dsh-task-pet-action[data-quiet] {
|
|
788
|
+
background: transparent;
|
|
789
|
+
color: var(--dsw-alias-label-secondary);
|
|
790
|
+
}
|
|
791
|
+
.dsh-task-pet-action[data-quiet]:hover { background: var(--dsw-alias-bg-layer-2, rgba(127, 127, 127, 0.12)); color: var(--dsw-alias-label-primary); }
|
|
792
|
+
.dsh-task-pet-action:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
|
|
793
|
+
.dsh-task-pet-list { overflow: auto; padding: 0 6px 8px; display: flex; flex-direction: column; gap: 2px; }
|
|
794
|
+
.dsh-task-pet-row {
|
|
795
|
+
display: flex; align-items: flex-start; gap: 9px;
|
|
796
|
+
width: 100%; box-sizing: border-box;
|
|
797
|
+
padding: 8px 8px; border: none; border-radius: 10px;
|
|
798
|
+
background: transparent; text-align: left; cursor: pointer;
|
|
799
|
+
color: var(--dsw-alias-label-primary); font: inherit;
|
|
800
|
+
}
|
|
801
|
+
.dsh-task-pet-row:hover { background: var(--dsw-alias-bg-layer-2, rgba(127, 127, 127, 0.1)); }
|
|
802
|
+
.dsh-task-pet-row:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }
|
|
803
|
+
.dsh-task-pet-row[data-current] { background: var(--dsw-alias-bg-layer-2, rgba(127, 127, 127, 0.08)); }
|
|
804
|
+
.dsh-task-pet-dot { width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; flex: none; background: var(--dsw-alias-state-idle-primary); }
|
|
805
|
+
.dsh-task-pet-dot[data-running] {
|
|
806
|
+
background: var(--dsw-alias-brand-primary);
|
|
807
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--dsw-alias-brand-primary) 22%, transparent);
|
|
808
|
+
animation: dsh-task-pet-pulse 1.4s ease-in-out infinite;
|
|
809
|
+
}
|
|
810
|
+
.dsh-task-pet-dot[data-attention] { background: var(--dsw-alias-state-warn-primary); }
|
|
811
|
+
.dsh-task-pet-dot[data-failed] { background: var(--dsw-alias-state-error-primary); }
|
|
812
|
+
.dsh-task-pet-dot[data-finished] { background: var(--dsw-alias-state-success-primary); }
|
|
813
|
+
.dsh-task-pet-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
|
|
814
|
+
.dsh-task-pet-row-title { font-size: 12.5px; line-height: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
815
|
+
.dsh-task-pet-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; line-height: 15px; color: var(--dsw-alias-label-secondary); min-width: 0; }
|
|
816
|
+
.dsh-task-pet-meta-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
817
|
+
.dsh-task-pet-progress { height: 3px; border-radius: 2px; background: var(--dsw-alias-border-l2); overflow: hidden; margin-top: 1px; }
|
|
818
|
+
.dsh-task-pet-progress > span { display: block; height: 100%; border-radius: 2px; background: var(--dsw-alias-brand-primary); transition: width 240ms ease; }
|
|
819
|
+
.dsh-task-pet-more {
|
|
820
|
+
width: 100%; margin-top: 2px; padding: 6px 10px;
|
|
821
|
+
border: none; border-radius: 8px; background: transparent;
|
|
822
|
+
color: var(--dsw-alias-label-secondary); font: inherit; font-size: 11px; line-height: 15px;
|
|
823
|
+
text-align: center; cursor: pointer;
|
|
824
|
+
}
|
|
825
|
+
.dsh-task-pet-more:hover { background: var(--dsw-alias-bg-layer-2, rgba(127, 127, 127, 0.1)); color: var(--dsw-alias-label-primary); }
|
|
826
|
+
.dsh-task-pet-more:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }
|
|
827
|
+
.dsh-task-pet-empty { padding: 18px 16px 22px; text-align: center; color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 18px; }
|
|
828
|
+
.dsh-task-pet-empty strong { display: block; color: var(--dsw-alias-label-primary); font-size: 13px; margin-bottom: 4px; }
|
|
829
|
+
.dsh-task-pet-fab {
|
|
830
|
+
width: 34px; height: 34px; padding: 0; display: grid; place-items: center;
|
|
831
|
+
border: none; border-radius: 12px; cursor: pointer; touch-action: none;
|
|
832
|
+
background: var(--dsw-alias-button-floating-fill, var(--dsw-alias-bg-layer-1));
|
|
833
|
+
box-shadow: var(--dsw-elevation-soft, 0 0 0 0.5px var(--dsw-alias-border-l1));
|
|
834
|
+
pointer-events: auto; color: var(--dsw-alias-label-secondary);
|
|
835
|
+
}
|
|
836
|
+
.dsh-task-pet-fab:hover { color: var(--dsw-alias-label-primary); }
|
|
837
|
+
.dsh-task-pet-fab:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
|
|
838
|
+
@keyframes dsh-task-pet-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
|
|
839
|
+
/* The cat keeps moving between state changes: a tail on its own tempo, a slow
|
|
840
|
+
breath, and the occasional blink, all slower than the bob so they never sync. */
|
|
841
|
+
.dsh-task-pet-tail { transform-origin: 44px 54px; animation: dsh-task-pet-tail 3.4s ease-in-out infinite; }
|
|
842
|
+
.dsh-task-pet-button[data-working] .dsh-task-pet-tail { animation-duration: 1.9s; }
|
|
843
|
+
.dsh-task-pet-breathe { transform-origin: 32px 59px; animation: dsh-task-pet-breathe 4.8s ease-in-out infinite; }
|
|
844
|
+
.dsh-task-pet-blink { transform-origin: 32px 26.5px; animation: dsh-task-pet-blink 4.6s ease-in-out infinite; }
|
|
845
|
+
@keyframes dsh-task-pet-tail { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(8deg); } }
|
|
846
|
+
@keyframes dsh-task-pet-breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.02); } }
|
|
847
|
+
@keyframes dsh-task-pet-blink { 0%, 94%, 100% { transform: scaleY(1); } 96%, 98% { transform: scaleY(0.08); } }
|
|
848
|
+
@keyframes dsh-task-pet-rise { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
|
|
849
|
+
@keyframes dsh-task-pet-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
|
|
850
|
+
@media (prefers-reduced-motion: reduce) {
|
|
851
|
+
.dsh-task-pet-button > svg, .dsh-task-pet-dot[data-running], .dsh-task-pet-panel,
|
|
852
|
+
.dsh-task-pet-tail, .dsh-task-pet-breathe, .dsh-task-pet-blink { animation: none; }
|
|
853
|
+
.dsh-task-pet-button, .dsh-task-pet-progress > span { transition: none; }
|
|
854
|
+
}
|
|
855
|
+
`;
|
|
856
|
+
return h('style', { 'data-dsh-task-pet': 'styles' }, css);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* One roster row.
|
|
861
|
+
* @param props.row - roster row.
|
|
862
|
+
* @param props.status - Session status record.
|
|
863
|
+
* @param props.now - current clock for elapsed labels.
|
|
864
|
+
* @param props.open - jump action.
|
|
865
|
+
* @param props.t - translator.
|
|
866
|
+
* @returns the row button.
|
|
867
|
+
*/
|
|
868
|
+
/**
|
|
869
|
+
* The one-line status for a Session: elapsed time, todo progress, the tool
|
|
870
|
+
* it is on, or why it is worth a look. Shared with the desktop pet so both
|
|
871
|
+
* surfaces describe the same row with the same words.
|
|
872
|
+
* @param row - roster row.
|
|
873
|
+
* @param status - live Session status, when known.
|
|
874
|
+
* @param now - render clock for elapsed labels.
|
|
875
|
+
* @param t - translator.
|
|
876
|
+
* @returns the status line.
|
|
877
|
+
*/
|
|
878
|
+
function rowMeta(row, status, now, t) {
|
|
879
|
+
const kind = rowKind(row, status);
|
|
880
|
+
const pet = row.pet;
|
|
881
|
+
const todos = pet === null || pet === undefined ? null : pet.todos;
|
|
882
|
+
const goal = pet === null || pet === undefined ? null : pet.goal;
|
|
883
|
+
if (kind === 'attention') return t('list.attention');
|
|
884
|
+
if (kind === 'running') {
|
|
885
|
+
const parts = [];
|
|
886
|
+
if (pet !== null && pet !== undefined && pet.startedAt !== null) parts.push(elapsedLabel(now - pet.startedAt));
|
|
887
|
+
if (todos !== null) parts.push(`${todos.completed}/${todos.total}`);
|
|
888
|
+
else if (goal !== null) parts.push(t('list.goal', { objective: goal.objective }));
|
|
889
|
+
else if (pet !== null && pet !== undefined && pet.step > 0) parts.push(t('list.step', { step: pet.step }));
|
|
890
|
+
if (pet !== null && pet !== undefined && pet.lastTool !== null) parts.push(pet.lastTool);
|
|
891
|
+
// A failing tool is why the turn sometimes appears stalled; surface the
|
|
892
|
+
// marker beside the tool name instead of inventing a second badge.
|
|
893
|
+
if (pet !== null && pet !== undefined && pet.lastToolError === true) parts.push('⚠');
|
|
894
|
+
return parts.length === 0 ? t('list.running') : parts.join(' · ');
|
|
895
|
+
}
|
|
896
|
+
if (kind === 'failed') return t('list.failed');
|
|
897
|
+
if (kind === 'finished') return todos !== null ? `${todos.completed}/${todos.total}` : t('list.finished');
|
|
898
|
+
if (todos !== null) return `${todos.completed}/${todos.total}`;
|
|
899
|
+
if (goal !== null) return t('list.goal', { objective: goal.objective });
|
|
900
|
+
if (pet !== null && pet !== undefined && pet.step > 0) return t('list.step', { step: pet.step });
|
|
901
|
+
return t('list.idle');
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* Todo completion of one row, when it has a list to report.
|
|
906
|
+
* @param row - roster row.
|
|
907
|
+
* @returns `{done, total}`, or null.
|
|
908
|
+
*/
|
|
909
|
+
function rowProgress(row) {
|
|
910
|
+
const todos = row.pet === null || row.pet === undefined ? null : row.pet.todos;
|
|
911
|
+
if (todos === null || todos === undefined || todos.total === 0) return null;
|
|
912
|
+
return { done: todos.completed, total: todos.total };
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
function PetRow({ row, status, now, open, t }) {
|
|
916
|
+
const kind = rowKind(row, status);
|
|
917
|
+
const meta = rowMeta(row, status, now, t);
|
|
918
|
+
const progress = rowProgress(row);
|
|
919
|
+
const ratio = progress === null ? null : Math.min(1, progress.done / progress.total);
|
|
920
|
+
return h('button', {
|
|
921
|
+
type: 'button',
|
|
922
|
+
className: 'dsh-task-pet-row',
|
|
923
|
+
'data-current': row.current ? '' : undefined,
|
|
924
|
+
title: row.title,
|
|
925
|
+
onClick: () => open(row.id),
|
|
926
|
+
'aria-label': `${row.title} — ${meta}. ${t('list.jump')}`
|
|
927
|
+
},
|
|
928
|
+
h('span', {
|
|
929
|
+
className: 'dsh-task-pet-dot',
|
|
930
|
+
'data-running': kind === 'running' ? '' : undefined,
|
|
931
|
+
'data-attention': kind === 'attention' ? '' : undefined,
|
|
932
|
+
'data-failed': kind === 'failed' ? '' : undefined,
|
|
933
|
+
'data-finished': kind === 'finished' ? '' : undefined
|
|
934
|
+
}),
|
|
935
|
+
h('span', { className: 'dsh-task-pet-body' },
|
|
936
|
+
h('span', { className: 'dsh-task-pet-row-title' }, row.title),
|
|
937
|
+
h('span', { className: 'dsh-task-pet-meta' },
|
|
938
|
+
h('span', { className: 'dsh-task-pet-meta-text' }, meta),
|
|
939
|
+
row.current ? h('span', { className: 'dsh-task-pet-meta-text' }, `· ${t('list.current')}`) : null
|
|
940
|
+
),
|
|
941
|
+
ratio === null ? null : h('span', { className: 'dsh-task-pet-progress' },
|
|
942
|
+
h('span', { style: { width: `${Math.round(ratio * 100)}%` } })
|
|
943
|
+
)
|
|
944
|
+
));
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* The pet entry: floating button, badge, and the expandable roster.
|
|
949
|
+
* @param props.useSessions - Session list selector hook.
|
|
950
|
+
* @param props.useWorkspaces - Workspace selector hook (archived set).
|
|
951
|
+
* @param props.useSessionStatus - Session status selector hook.
|
|
952
|
+
* @param props.openSession - jump action supplied by the plugin.
|
|
953
|
+
* @param props.t - translator for this entry's locale namespace.
|
|
954
|
+
* @returns the overlay content.
|
|
955
|
+
*/
|
|
956
|
+
function TaskPet({ useSessions, useWorkspaces, useSessionStatus, openSession, t }) {
|
|
957
|
+
const listed = useSessions(rosterOf, sameRows);
|
|
958
|
+
const archived = useWorkspaces((state) => state.archivedSessionIds, sameArchived);
|
|
959
|
+
// An archived Session is out of the working set; jumping into one from a
|
|
960
|
+
// floating pet would silently undo the user's tidy-up.
|
|
961
|
+
const rows = archived.length === 0 ? listed : listed.filter((row) => !archived.includes(row.id));
|
|
962
|
+
const statuses = useSessionStatus((value) => value);
|
|
963
|
+
const [open, setOpen] = React.useState(false);
|
|
964
|
+
const [minimized, setMinimized] = React.useState(false);
|
|
965
|
+
const [offset, setOffset] = React.useState({ x: 0, y: 0 });
|
|
966
|
+
const [dragging, setDragging] = React.useState(false);
|
|
967
|
+
const [expanded, setExpanded] = React.useState(false);
|
|
968
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
969
|
+
// What the Host reports about the screen-wide helper: whether this system
|
|
970
|
+
// has one, and whether the user left it on.
|
|
971
|
+
const [desktop, setDesktop] = React.useState(null);
|
|
972
|
+
// Desktop mode compiles a native helper, so the first opt-in asks.
|
|
973
|
+
const [confirmingDesktop, setConfirmingDesktop] = React.useState(false);
|
|
974
|
+
const drag = React.useRef(null);
|
|
975
|
+
const rootRef = React.useRef(null);
|
|
976
|
+
const panelRef = React.useRef(null);
|
|
977
|
+
const reportRef = React.useRef(null);
|
|
978
|
+
const confirmedRef = React.useRef(false);
|
|
979
|
+
|
|
980
|
+
const anyRunning = rows.some((row) => rowKind(row, statuses.get(row.id)) === 'running');
|
|
981
|
+
|
|
982
|
+
React.useEffect(() => {
|
|
983
|
+
if (!anyRunning) return undefined;
|
|
984
|
+
const timer = setInterval(() => { setNow(Date.now()); }, 1000);
|
|
985
|
+
return () => { clearInterval(timer); };
|
|
986
|
+
}, [anyRunning]);
|
|
987
|
+
|
|
988
|
+
React.useEffect(() => {
|
|
989
|
+
// A resize shrinks the room the pet was dragged into, so re-clamp it:
|
|
990
|
+
// otherwise a narrow window leaves the pet (and its only control) off
|
|
991
|
+
// screen with no way back.
|
|
992
|
+
const onResize = () => {
|
|
993
|
+
const root = rootRef.current;
|
|
994
|
+
if (root === null || typeof root.getBoundingClientRect !== 'function') return;
|
|
995
|
+
const box = root.getBoundingClientRect();
|
|
996
|
+
if (box.width === 0 || box.height === 0) return;
|
|
997
|
+
const margin = 8;
|
|
998
|
+
const pull = (start, end, limit) => Math.max(0, margin - start) + Math.min(0, limit - margin - end);
|
|
999
|
+
const dx = pull(box.left, box.right, window.innerWidth);
|
|
1000
|
+
const dy = pull(box.top, box.bottom, window.innerHeight);
|
|
1001
|
+
if (dx === 0 && dy === 0) return;
|
|
1002
|
+
setOffset((value) => ({ x: value.x + dx, y: value.y + dy }));
|
|
1003
|
+
};
|
|
1004
|
+
window.addEventListener('resize', onResize);
|
|
1005
|
+
return () => { window.removeEventListener('resize', onResize); };
|
|
1006
|
+
}, []);
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Close the panel and forget a manual expansion, so reopening always
|
|
1011
|
+
* starts collapsed.
|
|
1012
|
+
*/
|
|
1013
|
+
const close = () => {
|
|
1014
|
+
setOpen(false);
|
|
1015
|
+
setExpanded(false);
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
React.useEffect(() => {
|
|
1019
|
+
if (!open) return undefined;
|
|
1020
|
+
// Move focus into the panel so the next Tab lands on a row instead of
|
|
1021
|
+
// leaving the overlay; the trigger keeps focus when it closes again.
|
|
1022
|
+
const panel = panelRef.current;
|
|
1023
|
+
if (panel !== null && typeof panel.focus === 'function') panel.focus();
|
|
1024
|
+
// Escape is captured so an open panel closes before the app handles the
|
|
1025
|
+
// key; a pointerdown anywhere outside dismisses it, which is what every
|
|
1026
|
+
// other popover in this app does.
|
|
1027
|
+
const onKey = (event) => {
|
|
1028
|
+
if (event.key !== 'Escape') return;
|
|
1029
|
+
event.preventDefault();
|
|
1030
|
+
event.stopPropagation();
|
|
1031
|
+
close();
|
|
1032
|
+
};
|
|
1033
|
+
const onPointerDown = (event) => {
|
|
1034
|
+
const root = rootRef.current;
|
|
1035
|
+
if (root !== null && event.target instanceof Node && root.contains(event.target)) return;
|
|
1036
|
+
close();
|
|
1037
|
+
};
|
|
1038
|
+
window.addEventListener('keydown', onKey, true);
|
|
1039
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
1040
|
+
return () => {
|
|
1041
|
+
window.removeEventListener('keydown', onKey, true);
|
|
1042
|
+
document.removeEventListener('pointerdown', onPointerDown);
|
|
1043
|
+
};
|
|
1044
|
+
}, [open]);
|
|
1045
|
+
|
|
1046
|
+
// Newest first. A freshly opened conversation used to sink to the bottom
|
|
1047
|
+
// of the kind buckets, which is the one place the user is most likely to
|
|
1048
|
+
// look — the badge and the dots still carry urgency.
|
|
1049
|
+
const ranked = rows
|
|
1050
|
+
.map((row) => ({ row, kind: rowKind(row, statuses.get(row.id)) }))
|
|
1051
|
+
.sort((a, b) => (b.row.updatedAt - a.row.updatedAt) || (KIND_ORDER[a.kind] - KIND_ORDER[b.kind]));
|
|
1052
|
+
const running = ranked.filter((entry) => entry.kind === 'running').length;
|
|
1053
|
+
const attention = ranked.filter((entry) => entry.kind === 'attention').length;
|
|
1054
|
+
const failed = ranked.filter((entry) => entry.kind === 'failed').length;
|
|
1055
|
+
|
|
1056
|
+
const mood = attention > 0 ? 'alert' : running > 0 ? 'working' : rows.length > 0 ? 'idle' : 'sleeping';
|
|
1057
|
+
const badge = attention > 0 ? attention : running;
|
|
1058
|
+
|
|
1059
|
+
// One sentence for every combination the badge cannot express: the badge
|
|
1060
|
+
// shows a single number, so the summary names both counts when both exist.
|
|
1061
|
+
const summary = rows.length === 0
|
|
1062
|
+
? t('pet.summaryIdle')
|
|
1063
|
+
: attention > 0 && running > 0
|
|
1064
|
+
? t('pet.summary', { running, attention })
|
|
1065
|
+
: attention > 0
|
|
1066
|
+
? t('pet.summaryAttention', { attention })
|
|
1067
|
+
: running > 0
|
|
1068
|
+
? t('pet.summaryRunning', { running })
|
|
1069
|
+
: failed > 0
|
|
1070
|
+
// "All quiet" over a red failed row reads as a bug report.
|
|
1071
|
+
? t('pet.summaryFailed', { count: failed })
|
|
1072
|
+
: t('pet.summaryQuiet');
|
|
1073
|
+
|
|
1074
|
+
/** The facts the screen-wide helper draws; rebuilt whenever the roster moves. */
|
|
1075
|
+
reportRef.current = {
|
|
1076
|
+
mood,
|
|
1077
|
+
badge,
|
|
1078
|
+
attention,
|
|
1079
|
+
running,
|
|
1080
|
+
summary,
|
|
1081
|
+
locale: currentLocale(),
|
|
1082
|
+
light: surfaceIsLight(),
|
|
1083
|
+
sessions: ranked.slice(0, 12).map((entry) => {
|
|
1084
|
+
const progress = rowProgress(entry.row);
|
|
1085
|
+
return {
|
|
1086
|
+
id: entry.row.id,
|
|
1087
|
+
title: entry.row.title,
|
|
1088
|
+
kind: entry.kind,
|
|
1089
|
+
meta: rowMeta(entry.row, statuses.get(entry.row.id), now, t),
|
|
1090
|
+
done: progress === null ? 0 : progress.done,
|
|
1091
|
+
total: progress === null ? 0 : progress.total,
|
|
1092
|
+
current: entry.row.current === true,
|
|
1093
|
+
currentLabel: t('list.current'),
|
|
1094
|
+
active: entry.row.current === true
|
|
1095
|
+
};
|
|
1096
|
+
})
|
|
1097
|
+
};
|
|
1098
|
+
|
|
1099
|
+
React.useEffect(() => {
|
|
1100
|
+
// One effect owns the whole desktop channel: it publishes the roster and
|
|
1101
|
+
// keeps one long poll open for click intents. A periodic push keeps the
|
|
1102
|
+
// helper honest even when nothing on the page changes.
|
|
1103
|
+
const controller = new AbortController();
|
|
1104
|
+
let stopped = false;
|
|
1105
|
+
|
|
1106
|
+
const interview = (intents) => {
|
|
1107
|
+
for (const intent of intents) {
|
|
1108
|
+
// Same navigation the in-window roster uses.
|
|
1109
|
+
if (intent.type === 'jump' && typeof intent.id === 'string') openSession(intent.id);
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
const publish = () => {
|
|
1114
|
+
const report = reportRef.current;
|
|
1115
|
+
if (report === null) return;
|
|
1116
|
+
void pushDesktop({ state: report }, controller.signal).then((body) => {
|
|
1117
|
+
if (stopped || body === null) return;
|
|
1118
|
+
setDesktop((previous) => (sameStatus(previous, body) ? previous : body));
|
|
1119
|
+
if (Array.isArray(body.intents) && body.intents.length > 0) interview(body.intents);
|
|
1120
|
+
});
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1123
|
+
const loop = async () => {
|
|
1124
|
+
let backoff = 0;
|
|
1125
|
+
while (!stopped) {
|
|
1126
|
+
const body = await pollDesktop(controller.signal);
|
|
1127
|
+
if (stopped) return;
|
|
1128
|
+
if (body === null) {
|
|
1129
|
+
// A reload unregisters the route for a moment, and a dropped
|
|
1130
|
+
// connection says nothing about the Host. Returning here used to
|
|
1131
|
+
// kill the click channel for the rest of the page's life while
|
|
1132
|
+
// pushes kept working, which is exactly how "the menu does
|
|
1133
|
+
// nothing" looked from the outside. Wait and try again.
|
|
1134
|
+
backoff = Math.min(backoff === 0 ? 1000 : backoff * 2, 15000);
|
|
1135
|
+
setDesktop((previous) => (previous === null ? previous : { ...previous, running: false }));
|
|
1136
|
+
await new Promise((resolve) => { setTimeout(resolve, backoff); });
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
backoff = 0;
|
|
1140
|
+
setDesktop((previous) => (sameStatus(previous, body) ? previous : body));
|
|
1141
|
+
if (Array.isArray(body.intents) && body.intents.length > 0) interview(body.intents);
|
|
1142
|
+
// Refresh the helper's liveness clock at least once per poll window.
|
|
1143
|
+
if (body.running === true) publish();
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
|
|
1147
|
+
// Republish on every poll reply: the poll is the one request the browser
|
|
1148
|
+
// keeps alive in a backgrounded document, so the helper's watchdog sees
|
|
1149
|
+
// traffic even while the page's timers are throttled.
|
|
1150
|
+
const push = () => { publish(); };
|
|
1151
|
+
const timer = setInterval(push, PUSH_INTERVAL_MS);
|
|
1152
|
+
// Reconnecting after a suspension: the old poll may have been killed by
|
|
1153
|
+
// the browser without an error we can see.
|
|
1154
|
+
const revive = () => {
|
|
1155
|
+
if (stopped || document.visibilityState === 'hidden') return;
|
|
1156
|
+
publish();
|
|
1157
|
+
};
|
|
1158
|
+
document.addEventListener('visibilitychange', revive);
|
|
1159
|
+
publish();
|
|
1160
|
+
void loop();
|
|
1161
|
+
return () => {
|
|
1162
|
+
stopped = true;
|
|
1163
|
+
clearInterval(timer);
|
|
1164
|
+
document.removeEventListener('visibilitychange', revive);
|
|
1165
|
+
controller.abort();
|
|
1166
|
+
};
|
|
1167
|
+
}, []);
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* Turn the screen-wide pet on or off and adopt the Host's answer.
|
|
1171
|
+
* @param next - explicit target state; the current one is inverted when omitted.
|
|
1172
|
+
* @returns completion once the Host replied.
|
|
1173
|
+
*/
|
|
1174
|
+
const toggleDesktop = async (next) => {
|
|
1175
|
+
const enabled = typeof next === 'boolean' ? next : !(desktop !== null && desktop.enabled);
|
|
1176
|
+
if (enabled && confirmedRef.current !== true) {
|
|
1177
|
+
// A native helper is opt-in: say what this does before doing it.
|
|
1178
|
+
confirmedRef.current = true;
|
|
1179
|
+
setConfirmingDesktop(true);
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
confirmedRef.current = true;
|
|
1183
|
+
setConfirmingDesktop(false);
|
|
1184
|
+
try {
|
|
1185
|
+
const response = await fetch(OVERLAY_ROUTE, {
|
|
1186
|
+
method: 'POST',
|
|
1187
|
+
headers: { 'content-type': 'application/json' },
|
|
1188
|
+
body: JSON.stringify({ action: enabled ? 'enable' : 'disable' })
|
|
1189
|
+
});
|
|
1190
|
+
if (!response.ok) return;
|
|
1191
|
+
const body = await response.json();
|
|
1192
|
+
if (typeof body === 'object' && body !== null) setDesktop(body);
|
|
1193
|
+
} catch {
|
|
1194
|
+
/* The Host is unreachable; the next poll reports the real state. */
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
const jump = (id) => {
|
|
1199
|
+
close();
|
|
1200
|
+
openSession(id);
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
const onPointerDown = (event) => {
|
|
1204
|
+
if (event.button !== undefined && event.button !== 0) return;
|
|
1205
|
+
// Clamp against the pet's measured box, not a hard-coded anchor: the
|
|
1206
|
+
// bottom anchor depends on the composer height, which changes with the
|
|
1207
|
+
// window and with a long draft.
|
|
1208
|
+
const element = event.currentTarget;
|
|
1209
|
+
// Measure the whole cluster, not just the trigger: an open panel sits
|
|
1210
|
+
// above it, so clamping the button alone could push the panel off screen.
|
|
1211
|
+
const cluster = rootRef.current ?? element;
|
|
1212
|
+
drag.current = {
|
|
1213
|
+
pointerId: event.pointerId,
|
|
1214
|
+
startX: event.clientX,
|
|
1215
|
+
startY: event.clientY,
|
|
1216
|
+
box: typeof cluster.getBoundingClientRect === 'function'
|
|
1217
|
+
? cluster.getBoundingClientRect()
|
|
1218
|
+
: null,
|
|
1219
|
+
baseX: offset.x,
|
|
1220
|
+
baseY: offset.y,
|
|
1221
|
+
moved: false,
|
|
1222
|
+
element
|
|
1223
|
+
};
|
|
1224
|
+
if (typeof element.setPointerCapture === 'function') {
|
|
1225
|
+
element.setPointerCapture(event.pointerId);
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
const onPointerMove = (event) => {
|
|
1230
|
+
const state = drag.current;
|
|
1231
|
+
if (state === null || state.pointerId !== event.pointerId) return;
|
|
1232
|
+
const dx = event.clientX - state.startX;
|
|
1233
|
+
const dy = event.clientY - state.startY;
|
|
1234
|
+
if (!state.moved && Math.abs(dx) + Math.abs(dy) > 4) {
|
|
1235
|
+
state.moved = true;
|
|
1236
|
+
setDragging(true);
|
|
1237
|
+
}
|
|
1238
|
+
if (!state.moved) return;
|
|
1239
|
+
const box = state.box;
|
|
1240
|
+
const width = window.innerWidth;
|
|
1241
|
+
const height = window.innerHeight;
|
|
1242
|
+
if (box === null || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
1243
|
+
setOffset({ x: state.baseX + dx, y: state.baseY + dy });
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
// Keep the whole pet on screen: the box already includes the offset it
|
|
1247
|
+
// was measured with, so the correction is what the clamp removed from
|
|
1248
|
+
// this gesture, added to the offset the gesture started from.
|
|
1249
|
+
const margin = 8;
|
|
1250
|
+
const clamp = (start, size, limit) => Math.min(
|
|
1251
|
+
Math.max(start, margin),
|
|
1252
|
+
Math.max(margin, limit - size - margin)
|
|
1253
|
+
);
|
|
1254
|
+
setOffset({
|
|
1255
|
+
x: state.baseX + clamp(box.left + dx, box.width, width) - box.left,
|
|
1256
|
+
y: state.baseY + clamp(box.top + dy, box.height, height) - box.top
|
|
1257
|
+
});
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
const onPointerUp = (event, onTap) => {
|
|
1261
|
+
const state = drag.current;
|
|
1262
|
+
drag.current = null;
|
|
1263
|
+
setDragging(false);
|
|
1264
|
+
if (state === null) return;
|
|
1265
|
+
if (typeof state.element.releasePointerCapture === 'function') {
|
|
1266
|
+
try { state.element.releasePointerCapture(event.pointerId); } catch { /* already released */ }
|
|
1267
|
+
}
|
|
1268
|
+
if (!state.moved) onTap();
|
|
1269
|
+
};
|
|
1270
|
+
|
|
1271
|
+
/**
|
|
1272
|
+
* Pointer props for one surface. A press that travels past the drag
|
|
1273
|
+
* threshold moves the pet; a press that does not is a tap, so a keyboard
|
|
1274
|
+
* activation (`detail === 0`) reaches the same action through `onClick`.
|
|
1275
|
+
* @param onTap - action for one tap.
|
|
1276
|
+
* @returns the pointer handlers plus a click guard.
|
|
1277
|
+
*/
|
|
1278
|
+
const gesture = (onTap) => ({
|
|
1279
|
+
onPointerDown,
|
|
1280
|
+
onPointerMove,
|
|
1281
|
+
onPointerUp: (event) => { onPointerUp(event, onTap); },
|
|
1282
|
+
onClick: (event) => { if (event.detail === 0) onTap(); }
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
// Park above the composer seat (~152px) with a small gap. That height is
|
|
1286
|
+
// published on the Conversation's own scroller, which is a sibling subtree
|
|
1287
|
+
// of this frame-wide layer rather than an ancestor, so it cannot be
|
|
1288
|
+
// inherited here; a taller draft or an open side column is one drag away.
|
|
1289
|
+
const position = {
|
|
1290
|
+
right: 20,
|
|
1291
|
+
bottom: 172,
|
|
1292
|
+
transform: `translate(${offset.x}px, ${offset.y}px)`
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
// While the screen-wide pet is drawing, this one stays but recedes: same
|
|
1296
|
+
// shape, same panel, lower emphasis. Collapsing it to a different control
|
|
1297
|
+
// would hide the roster behind a glyph the user has to learn, and on a
|
|
1298
|
+
// full-screen app this window is the only place the list can open.
|
|
1299
|
+
// Exactly one pet exists. The desktop one is the default; while it is
|
|
1300
|
+
// actually drawing, this window shows nothing at all. A pet that failed to
|
|
1301
|
+
// launch must not leave the window empty, so the test is "really running".
|
|
1302
|
+
if (!confirmingDesktop && desktop !== null && desktop.enabled && desktop.running === true) {
|
|
1303
|
+
// The way back lives on the desktop card and in the menu bar item.
|
|
1304
|
+
return null;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
if (minimized) {
|
|
1308
|
+
return h('div', {
|
|
1309
|
+
className: 'dsh-task-pet-root',
|
|
1310
|
+
style: position
|
|
1311
|
+
},
|
|
1312
|
+
h(PetStyles, null),
|
|
1313
|
+
h('button', {
|
|
1314
|
+
type: 'button',
|
|
1315
|
+
className: 'dsh-task-pet-fab',
|
|
1316
|
+
title: t('pet.restore'),
|
|
1317
|
+
'aria-label': badge > 0 ? `${t('pet.restore')} — ${t('pet.badge', { count: badge })}` : t('pet.restore'),
|
|
1318
|
+
...gesture(() => { setMinimized(false); })
|
|
1319
|
+
},
|
|
1320
|
+
h(PetArt, { mood, size: 24, decorated: badge === 0 }),
|
|
1321
|
+
badge > 0 ? h('span', {
|
|
1322
|
+
className: 'dsh-task-pet-badge dsh-task-pet-badge-fab',
|
|
1323
|
+
'data-attention': attention > 0 ? '' : undefined
|
|
1324
|
+
}, badge > 9 ? '9+' : String(badge)) : null)
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
// The trigger comes first in DOM order so Tab reaches it before the panel
|
|
1329
|
+
// it opens; `column-reverse` keeps the panel painted above it.
|
|
1330
|
+
return h('div', {
|
|
1331
|
+
className: 'dsh-task-pet-root',
|
|
1332
|
+
style: position,
|
|
1333
|
+
ref: rootRef
|
|
1334
|
+
},
|
|
1335
|
+
h(PetStyles, null),
|
|
1336
|
+
h('div', { className: 'dsh-task-pet-anchor' },
|
|
1337
|
+
h('button', {
|
|
1338
|
+
type: 'button',
|
|
1339
|
+
className: 'dsh-task-pet-button',
|
|
1340
|
+
'data-working': anyRunning ? '' : undefined,
|
|
1341
|
+
'data-dragging': dragging ? '' : undefined,
|
|
1342
|
+
title: open ? t('pet.close') : t('pet.open'),
|
|
1343
|
+
'aria-label': badge > 0
|
|
1344
|
+
? `${open ? t('pet.close') : t('pet.open')} — ${t('pet.badge', { count: badge })}`
|
|
1345
|
+
: open ? t('pet.close') : t('pet.open'),
|
|
1346
|
+
'aria-expanded': open,
|
|
1347
|
+
'aria-haspopup': 'dialog',
|
|
1348
|
+
...gesture(() => { if (open) close(); else setOpen(true); })
|
|
1349
|
+
},
|
|
1350
|
+
h(PetArt, { mood, size: 50, decorated: badge === 0 }),
|
|
1351
|
+
badge > 0 ? h('span', {
|
|
1352
|
+
className: 'dsh-task-pet-badge',
|
|
1353
|
+
'data-attention': attention > 0 ? '' : undefined
|
|
1354
|
+
}, badge > 9 ? '9+' : String(badge)) : null),
|
|
1355
|
+
open ? h('div', {
|
|
1356
|
+
className: 'dsh-task-pet-panel',
|
|
1357
|
+
role: 'dialog',
|
|
1358
|
+
'aria-label': t('pet.title'),
|
|
1359
|
+
ref: panelRef,
|
|
1360
|
+
tabIndex: -1,
|
|
1361
|
+
onPointerDown: (event) => { event.stopPropagation(); }
|
|
1362
|
+
},
|
|
1363
|
+
h('div', { className: 'dsh-task-pet-head' },
|
|
1364
|
+
h('div', { className: 'dsh-task-pet-head-text' },
|
|
1365
|
+
h('span', { className: 'dsh-task-pet-title' }, t('pet.title')),
|
|
1366
|
+
h('span', { className: 'dsh-task-pet-summary' }, summary)
|
|
1367
|
+
),
|
|
1368
|
+
h('div', { className: 'dsh-task-pet-head-actions' },
|
|
1369
|
+
desktop !== null && desktop.supported
|
|
1370
|
+
? h('button', {
|
|
1371
|
+
type: 'button',
|
|
1372
|
+
className: 'dsh-task-pet-icon-button',
|
|
1373
|
+
title: desktop.enabled ? t('desktop.off') : t('desktop.on'),
|
|
1374
|
+
'aria-label': desktop.enabled ? t('desktop.off') : t('desktop.on'),
|
|
1375
|
+
'aria-pressed': desktop.enabled,
|
|
1376
|
+
'data-desktop-on': desktop.enabled ? '' : undefined,
|
|
1377
|
+
onClick: () => { void toggleDesktop(); }
|
|
1378
|
+
}, desktop.enabled
|
|
1379
|
+
? h('svg', { viewBox: '0 0 16 16', width: 14, height: 14, 'aria-hidden': true },
|
|
1380
|
+
h('rect', { x: 1.6, y: 2.6, width: 12.8, height: 8.6, rx: 1.6, fill: 'none', stroke: 'currentColor', strokeWidth: 1.4 }),
|
|
1381
|
+
h('path', { d: 'M6 13.6h4', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' }),
|
|
1382
|
+
h('path', { d: 'M8 11.2v2.4', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' }))
|
|
1383
|
+
: h('svg', { viewBox: '0 0 16 16', width: 14, height: 14, 'aria-hidden': true },
|
|
1384
|
+
h('rect', { x: 1.6, y: 2.6, width: 12.8, height: 8.6, rx: 1.6, fill: 'none', stroke: 'currentColor', strokeWidth: 1.4 }),
|
|
1385
|
+
h('path', { d: 'M4.4 5.4l7.2 3.4M4.4 8.8l7.2-3.4', stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round', opacity: 0.0 }),
|
|
1386
|
+
h('path', { d: 'M11 12.6l3 3M14 12.6l-3 3', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' })))
|
|
1387
|
+
: null,
|
|
1388
|
+
h('button', {
|
|
1389
|
+
type: 'button',
|
|
1390
|
+
className: 'dsh-task-pet-icon-button',
|
|
1391
|
+
title: t('pet.minimize'),
|
|
1392
|
+
'aria-label': t('pet.minimize'),
|
|
1393
|
+
onClick: () => { close(); setMinimized(true); }
|
|
1394
|
+
}, h('svg', { viewBox: '0 0 16 16', width: 14, height: 14, 'aria-hidden': true },
|
|
1395
|
+
h('path', { d: 'M3 8h10', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }))),
|
|
1396
|
+
h('button', {
|
|
1397
|
+
type: 'button',
|
|
1398
|
+
className: 'dsh-task-pet-icon-button',
|
|
1399
|
+
title: t('pet.close'),
|
|
1400
|
+
'aria-label': t('pet.close'),
|
|
1401
|
+
onClick: close
|
|
1402
|
+
}, h('svg', { viewBox: '0 0 16 16', width: 14, height: 14, 'aria-hidden': true },
|
|
1403
|
+
h('path', { d: 'M4 4l8 8M12 4l-8 8', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' })))
|
|
1404
|
+
)
|
|
1405
|
+
),
|
|
1406
|
+
confirmingDesktop
|
|
1407
|
+
? h('div', { className: 'dsh-task-pet-confirm' },
|
|
1408
|
+
h('span', { className: 'dsh-task-pet-hint-text' }, t('desktop.explain')),
|
|
1409
|
+
h('div', { className: 'dsh-task-pet-confirm-actions' },
|
|
1410
|
+
h('button', {
|
|
1411
|
+
type: 'button',
|
|
1412
|
+
className: 'dsh-task-pet-action',
|
|
1413
|
+
onClick: () => { void toggleDesktop(true); }
|
|
1414
|
+
}, t('desktop.confirm')),
|
|
1415
|
+
h('button', {
|
|
1416
|
+
type: 'button',
|
|
1417
|
+
className: 'dsh-task-pet-action',
|
|
1418
|
+
'data-quiet': '',
|
|
1419
|
+
onClick: () => { setConfirmingDesktop(false); }
|
|
1420
|
+
}, t('desktop.cancel'))))
|
|
1421
|
+
: null,
|
|
1422
|
+
!confirmingDesktop && desktop !== null && desktop.enabled && desktop.running === true
|
|
1423
|
+
? h('div', { className: 'dsh-task-pet-hint' }, t('desktop.hint'))
|
|
1424
|
+
: null,
|
|
1425
|
+
desktop !== null && desktop.supported === false && desktop.error === undefined
|
|
1426
|
+
? h('div', { className: 'dsh-task-pet-hint' }, t('desktop.unsupported'))
|
|
1427
|
+
: null,
|
|
1428
|
+
desktop !== null && desktop.conflict === true
|
|
1429
|
+
? h('div', { className: 'dsh-task-pet-hint' }, t('desktop.conflict'))
|
|
1430
|
+
: null,
|
|
1431
|
+
desktop !== null && desktop.error !== undefined
|
|
1432
|
+
? h('div', { className: 'dsh-task-pet-hint' }, desktop.error)
|
|
1433
|
+
: null,
|
|
1434
|
+
ranked.length === 0
|
|
1435
|
+
? h('div', { className: 'dsh-task-pet-empty' },
|
|
1436
|
+
h('strong', null, t('empty.title')),
|
|
1437
|
+
h('span', null, t('empty.body')))
|
|
1438
|
+
: h('div', { className: 'dsh-task-pet-list' },
|
|
1439
|
+
(expanded ? ranked : ranked.slice(0, 8)).map((entry) => h(PetRow, {
|
|
1440
|
+
key: entry.row.id,
|
|
1441
|
+
row: entry.row,
|
|
1442
|
+
status: statuses.get(entry.row.id),
|
|
1443
|
+
now,
|
|
1444
|
+
open: jump,
|
|
1445
|
+
t
|
|
1446
|
+
})),
|
|
1447
|
+
ranked.length > 8
|
|
1448
|
+
? h('button', {
|
|
1449
|
+
type: 'button',
|
|
1450
|
+
className: 'dsh-task-pet-more',
|
|
1451
|
+
onClick: () => { setExpanded((value) => !value); }
|
|
1452
|
+
}, expanded ? t('list.less') : t('list.more', { count: ranked.length - 8 }))
|
|
1453
|
+
: null
|
|
1454
|
+
)
|
|
1455
|
+
) : null
|
|
1456
|
+
)
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
return {
|
|
1461
|
+
inject: ['slots', 'locale', 'uiWorkspace'],
|
|
1462
|
+
apply(ctx) {
|
|
1463
|
+
// The helper draws its own menu, outside this document, so it cannot
|
|
1464
|
+
// inherit the page's language: hand it the active locale id.
|
|
1465
|
+
activeLocale = () => {
|
|
1466
|
+
try {
|
|
1467
|
+
const snapshot = ctx.locale.getLocale();
|
|
1468
|
+
return typeof snapshot?.active === 'string' ? snapshot.active : '';
|
|
1469
|
+
} catch {
|
|
1470
|
+
return '';
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
ctx.effect(() => ctx.locale.register(NS, DICT), 'dsh-task-pet: dictionaries');
|
|
1474
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
1475
|
+
name: 'shell.overlay',
|
|
1476
|
+
id: NS,
|
|
1477
|
+
order: 20,
|
|
1478
|
+
locale: NS,
|
|
1479
|
+
inject: () => ({
|
|
1480
|
+
openSession: (sessionId) => { ctx.uiWorkspace.openSession(sessionId); }
|
|
1481
|
+
})
|
|
1482
|
+
}, TaskPet));
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
});
|