@goodandready/dsh-cron 0.1.3 → 0.1.5
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/lib/client.js +95 -22
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -90,6 +90,11 @@ window.__ModuleLoader__.load({
|
|
|
90
90
|
.dsh-cron-modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
|
|
91
91
|
.dsh-cron-btn-primary { background: #ededed; color: #111; border: none; border-radius: 8px; padding: 7px 16px; font-size: 13.5px; font-weight: 500; cursor: pointer; }
|
|
92
92
|
.dsh-cron-btn-secondary { background: transparent; color: #999; border: 1px solid #383838; border-radius: 8px; padding: 7px 16px; font-size: 13.5px; cursor: pointer; }
|
|
93
|
+
|
|
94
|
+
.dsh-cron-card { background: var(--dsw-alias-bg-layer-2, #1f1f1f); border: 1px solid var(--dsw-alias-border-l1, #333); border-radius: 12px; padding: 18px 20px; margin-bottom: 16px; }
|
|
95
|
+
.dsh-cron-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
|
|
96
|
+
.dsh-cron-card-title { font-size: 15px; font-weight: 600; color: var(--dsw-alias-label-primary, #fff); }
|
|
97
|
+
.dsh-cron-card-desc { font-size: 13px; color: var(--dsw-alias-label-secondary, #888); margin-bottom: 16px; line-height: 1.4; }
|
|
93
98
|
`;
|
|
94
99
|
|
|
95
100
|
function ensureStyles() {
|
|
@@ -124,8 +129,27 @@ window.__ModuleLoader__.load({
|
|
|
124
129
|
};
|
|
125
130
|
}
|
|
126
131
|
|
|
132
|
+
function startNewSession(ctx) {
|
|
133
|
+
if (ctx) {
|
|
134
|
+
const uiWorkspace = typeof ctx.get === 'function' ? ctx.get('uiWorkspace') : ctx.uiWorkspace;
|
|
135
|
+
if (uiWorkspace && typeof uiWorkspace.startSession === 'function') {
|
|
136
|
+
uiWorkspace.startSession();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const sessions = typeof ctx.get === 'function' ? ctx.get('sessions') : ctx.sessions;
|
|
140
|
+
if (sessions && typeof sessions.create === 'function') {
|
|
141
|
+
sessions.create({}).then((sessionId) => {
|
|
142
|
+
if (sessions.open) sessions.open(sessionId);
|
|
143
|
+
}).catch(() => {});
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const btn = nativeButton();
|
|
148
|
+
if (btn) btn.click();
|
|
149
|
+
}
|
|
150
|
+
|
|
127
151
|
function CronScreen(props) {
|
|
128
|
-
const { toggle, onClose } = props;
|
|
152
|
+
const { ctx, toggle, onClose } = props;
|
|
129
153
|
const [tab, setTab] = React.useState('all');
|
|
130
154
|
const [query, setQuery] = React.useState('');
|
|
131
155
|
const [tasks, setTasks] = React.useState([]);
|
|
@@ -220,13 +244,24 @@ window.__ModuleLoader__.load({
|
|
|
220
244
|
setDropdownOpen(false);
|
|
221
245
|
if (onClose) onClose();
|
|
222
246
|
else toggle.set(false);
|
|
223
|
-
|
|
224
|
-
|
|
247
|
+
|
|
248
|
+
startNewSession(ctx);
|
|
249
|
+
|
|
250
|
+
const promptText = 'Помоги мне настроить новую запланированную задачу cron: ';
|
|
251
|
+
let attempts = 0;
|
|
252
|
+
const fillTextarea = () => {
|
|
253
|
+
const textarea = document.querySelector('textarea[placeholder*="message"], textarea[class*="prompt"], textarea[placeholder*="сообщение"], textarea[placeholder*="спросить"]');
|
|
225
254
|
if (textarea) {
|
|
226
|
-
textarea.value =
|
|
255
|
+
textarea.value = promptText;
|
|
256
|
+
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
|
227
257
|
textarea.focus();
|
|
258
|
+
textarea.setSelectionRange(promptText.length, promptText.length);
|
|
259
|
+
} else if (attempts < 10) {
|
|
260
|
+
attempts++;
|
|
261
|
+
setTimeout(fillTextarea, 150);
|
|
228
262
|
}
|
|
229
|
-
}
|
|
263
|
+
};
|
|
264
|
+
setTimeout(fillTextarea, 100);
|
|
230
265
|
};
|
|
231
266
|
|
|
232
267
|
return React.createElement('div', { className: 'dsh-cron-overlay' },
|
|
@@ -376,22 +411,27 @@ window.__ModuleLoader__.load({
|
|
|
376
411
|
);
|
|
377
412
|
}
|
|
378
413
|
|
|
414
|
+
function CronSettingsCard(props) {
|
|
415
|
+
const { ctx, toggle } = props;
|
|
416
|
+
return React.createElement('div', { className: 'dsh-cron-card' },
|
|
417
|
+
React.createElement('div', { className: 'dsh-cron-card-head' },
|
|
418
|
+
React.createElement('span', { className: 'dsh-cron-card-title' }, '⏰ Планировщик задач (Cron)'),
|
|
419
|
+
React.createElement('button', {
|
|
420
|
+
type: 'button',
|
|
421
|
+
className: 'dsh-cron-btn-primary',
|
|
422
|
+
onClick: () => { if (toggle) toggle.set(true); }
|
|
423
|
+
}, 'Открыть запланированные задачи')
|
|
424
|
+
),
|
|
425
|
+
React.createElement('div', { className: 'dsh-cron-card-desc' },
|
|
426
|
+
'Автоматическое выполнение задач в фоновом режиме по заданному расписанию (cron/интервалы), отслеживание логов и интеграция с чатом через команду /cron.'
|
|
427
|
+
)
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
379
431
|
function nativeButton() {
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
'
|
|
383
|
-
'[class*="sidebar"] button[class*="sidebar-entry"]',
|
|
384
|
-
'nav button',
|
|
385
|
-
'aside button',
|
|
386
|
-
'[class*="sidebar"] button'
|
|
387
|
-
];
|
|
388
|
-
for (const sel of candidates) {
|
|
389
|
-
const found = document.querySelectorAll(sel);
|
|
390
|
-
for (const el of found) {
|
|
391
|
-
if (el.hasAttribute(ENTRY_ATTR)) continue;
|
|
392
|
-
if (el.dataset && el.dataset.dshPart === 'sidebar-entry') continue;
|
|
393
|
-
if (el.offsetWidth > 0 || el.offsetHeight > 0) return el;
|
|
394
|
-
}
|
|
432
|
+
const nodes = document.querySelectorAll('button[class*="newSession"]');
|
|
433
|
+
for (const node of nodes) {
|
|
434
|
+
if (String(node.className).indexOf('newSessionLabel') === -1) return node;
|
|
395
435
|
}
|
|
396
436
|
return undefined;
|
|
397
437
|
}
|
|
@@ -428,7 +468,7 @@ window.__ModuleLoader__.load({
|
|
|
428
468
|
let anchor = target;
|
|
429
469
|
let next = target.nextElementSibling;
|
|
430
470
|
while (next !== null && next.tagName === 'BUTTON'
|
|
431
|
-
&&
|
|
471
|
+
&& String(next.className).indexOf('sidebar-entry') >= 0) {
|
|
432
472
|
anchor = next;
|
|
433
473
|
next = next.nextElementSibling;
|
|
434
474
|
}
|
|
@@ -523,9 +563,40 @@ window.__ModuleLoader__.load({
|
|
|
523
563
|
};
|
|
524
564
|
}
|
|
525
565
|
|
|
566
|
+
function registerFirst(ctx, candidates, component) {
|
|
567
|
+
if (!ctx || !ctx.slots) return undefined;
|
|
568
|
+
for (const entry of candidates) {
|
|
569
|
+
try {
|
|
570
|
+
let ok = false;
|
|
571
|
+
ctx.slots.inject(entry.name, () => {
|
|
572
|
+
ctx.slots.register(entry, component);
|
|
573
|
+
ok = true;
|
|
574
|
+
});
|
|
575
|
+
if (ok) return entry.name;
|
|
576
|
+
} catch (e) {}
|
|
577
|
+
}
|
|
578
|
+
return undefined;
|
|
579
|
+
}
|
|
580
|
+
|
|
526
581
|
function apply(ctx) {
|
|
527
582
|
ensureStyles();
|
|
528
583
|
const toggle = createToggle();
|
|
584
|
+
|
|
585
|
+
const cardSlot = registerFirst(ctx, [
|
|
586
|
+
{ name: 'settings.plugin.item', key: NS, inject: () => ({ ctx, toggle }) },
|
|
587
|
+
{ name: 'settings.section', id: '@goodandready/dsh-cron', order: 34, label: () => 'Cron Задачи', inject: () => ({ ctx, toggle }) }
|
|
588
|
+
], CronSettingsCard);
|
|
589
|
+
|
|
590
|
+
const chipSlot = registerFirst(ctx, [
|
|
591
|
+
{ name: 'conversation.session.header.utilities', id: '@goodandready/dsh-cron.chip', order: 27, inject: () => ({ ctx, toggle }) }
|
|
592
|
+
], () => React.createElement('button', {
|
|
593
|
+
type: 'button',
|
|
594
|
+
style: { background: 'none', border: 'none', color: 'var(--dsw-alias-label-secondary, #999)', cursor: 'pointer', padding: '4px', display: 'inline-flex', alignItems: 'center' },
|
|
595
|
+
title: 'Запланированные задачи (Cron)',
|
|
596
|
+
onClick: () => toggle.toggle(),
|
|
597
|
+
dangerouslySetInnerHTML: { __html: ICON_TIMER }
|
|
598
|
+
}));
|
|
599
|
+
|
|
529
600
|
ctx.effect(() => {
|
|
530
601
|
const off = [
|
|
531
602
|
mountSidebarEntry(toggle, 'Запланированные задачи'),
|
|
@@ -533,9 +604,11 @@ window.__ModuleLoader__.load({
|
|
|
533
604
|
];
|
|
534
605
|
return () => { for (const dispose of off) dispose(); };
|
|
535
606
|
}, 'dsh-cron: client overlay');
|
|
607
|
+
|
|
608
|
+
exports.slots = { card: cardSlot, chip: chipSlot };
|
|
536
609
|
}
|
|
537
610
|
|
|
538
611
|
module.exports = { apply, inject: ['slots', 'locale', 'settingsScope'] };
|
|
539
612
|
return module.exports;
|
|
540
613
|
}
|
|
541
|
-
});
|
|
614
|
+
});
|