dsh-harness-toolbox 1.6.4 → 1.8.8

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/client.js CHANGED
@@ -18,24 +18,31 @@ window.__ModuleLoader__.load({
18
18
  const GH_NETWORK_API = '/compression-tiers/api/github/network'
19
19
  const GH_ONLINE_API = '/compression-tiers/api/github/online'
20
20
  const GH_BINDING_API = '/compression-tiers/api/github/binding'
21
- const FFMPEG_API = '/compression-tiers/api/ffmpeg'
21
+ const COMPONENTS_API = '/compression-tiers/api/components'
22
+ const TOOLS_API = '/compression-tiers/api/tools'
23
+
24
+ /**
25
+ * The rows the component panel always renders, in this order. The payload
26
+ * fills in state, path and progress; the list itself is fixed so a slow or
27
+ * failed load still shows every button (disabled) instead of an empty panel.
28
+ */
29
+ const COMPONENT_ROWS = [
30
+ { id: 'gh', name: 'GitHub CLI' },
31
+ { id: 'git', name: 'git' },
32
+ { id: 'ffmpeg', name: 'ffmpeg' },
33
+ { id: 'python', name: 'Python' },
34
+ ]
22
35
 
23
36
  const DICTIONARIES = {
24
37
  zh: {
25
38
  sectionLabel: '上下文压缩',
26
39
  title: '上下文压缩',
27
- intro: '五档自动压缩,切换即同步到所有预设引擎;下方还有全局规则、GitHub CLI 与音视频工具。',
28
40
  levelsAria: '压缩档位',
29
41
  levelGentle: '极轻',
30
42
  levelLight: '轻量',
31
43
  levelStandard: '标准',
32
44
  levelAggressive: '积极',
33
45
  levelMax: '最大',
34
- summaryGentle: '最晚触发,与官方默认一致。',
35
- summaryLight: '比官方默认早一档。',
36
- summaryStandard: '默认:长对话更省。',
37
- summaryAggressive: '更早压缩,成本优先。',
38
- summaryMax: '最省:40% 就压缩。',
39
46
  auto: '自动 ',
40
47
  retain: '留 ',
41
48
  sep: ':',
@@ -49,9 +56,7 @@ window.__ModuleLoader__.load({
49
56
  lastCompact: '上次压缩',
50
57
  never: '暂无',
51
58
  settingsPath: '设置文件',
52
- smallWindow: '按 ≥256k 窗口设计;更小的窗口主要差在保留量。',
53
59
  rulesTitle: '全局规则',
54
- rulesIntro: '编辑官方 AGENTS.md,下次会话生效。',
55
60
  rulesLabel: '规则内容',
56
61
  rulesPlaceholder: '例如:回答用中文;改动前先读 AGENTS.md。',
57
62
  rulesSave: '保存',
@@ -63,29 +68,40 @@ window.__ModuleLoader__.load({
63
68
  rulesPathLabel: '文件',
64
69
  rulesLoading: '读取中…',
65
70
  rulesMissing: '不存在,保存后创建。',
66
- ghTitle: 'GitHub CLI',
67
- ghIntro: '官方变更请求面板需要。系统 PATH 里已有会自动使用,也可下载托管版(v2.76.2,可断点续传)。',
68
- ghProbe: '重新检测',
69
- ghInstalled: '已安装',
70
- ghSystem: '系统已安装(PATH)',
71
- ghDownloading: '下载中 ',
72
- ghPartial: '未完成,可续传',
73
- ghFailed: '下载失败',
74
- ghMissing: '未安装',
75
- ghDownload: '下载',
76
- ghKeepDownload: '仍要下载',
77
- ghContinue: '继续下载',
78
- ghRetry: '重试',
79
- ghUnsupported: '当前系统不可用',
80
- ghPathLabel: '路径',
71
+ componentsTitle: '组件管理',
72
+ componentsLoadFailed: '读取组件状态失败:',
73
+ componentsActionFailed: '操作失败:',
74
+ toolsPathLabel: '下载目录',
75
+ toolsPathCurrent: '当前目录',
76
+ toolsPathSave: '迁移',
77
+ toolsPathReset: '恢复默认',
78
+ toolsPathSaved: '已迁移。',
79
+ toolsPathInvalid: '需要绝对路径。',
80
+ toolsPathRunning: '下载中,完成后再迁移。',
81
+ toolsPathFailed: '迁移失败:',
82
+ ghAuthTitle: 'GitHub 登录',
83
+ probe: '重新检测',
84
+ downloadIdle: '下载',
85
+ downloadKeep: '重新下载',
86
+ downloadContinue: '继续下载',
87
+ downloadRetry: '重试',
88
+ downloadRunning: '下载中 ',
89
+ downloadDone: '已安装',
90
+ downloadUnsupported: '当前系统不可用',
91
+ stateMissing: '未安装',
92
+ statePartial: '未完成,可续传',
93
+ stateFailed: '下载失败',
94
+ stateSystem: '系统已安装(PATH)',
95
+ pathLabel: '路径',
81
96
  ghAuthUnknown: '正在读取登录状态…',
82
- ghAuthUnavailable: '下载 GitHub CLI 后可登录。',
97
+ ghAuthUnavailable: '不可登录',
83
98
  ghLoggedIn: '已登录:',
84
99
  ghNotLoggedIn: '未登录',
85
100
  ghLogin: '登录 GitHub',
86
101
  ghRelogin: '重新登录',
87
102
  ghLoginStarting: '正在启动 gh 登录…',
88
- ghLoginNote: '在浏览器里粘贴一次性验证码并授权,完成后这里会自动更新。',
103
+ ghLoginWaiting: '等待授权',
104
+ ghLoginInactive: '未在登录中',
89
105
  ghLoginDone: '授权完成,凭据已由 gh 保存。',
90
106
  ghLoginFailed: '登录没有完成,可以重试。',
91
107
  ghCopy: '复制验证码',
@@ -104,22 +120,9 @@ window.__ModuleLoader__.load({
104
120
  ghNetworkUnknown: '未知',
105
121
  ghDnsOff: 'DNS 不是 GitHub 地址',
106
122
  ghScopeMissing: '令牌缺少 repo scope,私有仓库推送会失败。',
107
- ghToolNote: '发布交给 github_push 工具:默认推本会话的工作目录,先体检网络、扫密钥,再带超时推送。这一栏只管 gh 本身与网络体检。',
108
- toolsTitle: '音视频工具',
109
- toolsIntro: 'ffmpeg 与 ffprobe:可下载托管版(约 110 MB,断点续传),也可直接用系统 PATH 里的版本;托管版优先。',
110
123
  toolsNotFound: '未找到',
111
124
  toolsManaged: '托管版',
112
125
  toolsSystem: '系统 PATH',
113
- toolsLoading: '读取中…',
114
- toolsInstalled: '已安装',
115
- toolsInstall: '下载安装',
116
- toolsContinue: '继续下载',
117
- toolsRetry: '重试',
118
- toolsProbe: '重新检测',
119
- toolsDownloading: '下载中 ',
120
- toolsUnsupported: '当前系统没有托管版',
121
- toolsLoadFailed: '读取音视频工具状态失败:',
122
- toolsActionFailed: '操作失败:',
123
126
  repoSelectLabel: '仓库',
124
127
  repoSelectAria: '在线仓库(github_push 的推送目标)',
125
128
  repoTitle: 'github_push 默认推送到这个在线仓库',
@@ -135,18 +138,12 @@ window.__ModuleLoader__.load({
135
138
  en: {
136
139
  sectionLabel: 'Context compression',
137
140
  title: 'Context compression',
138
- intro: 'Five automatic tiers: switching syncs every preset engine. Global rules, GitHub CLI and video tools are below.',
139
141
  levelsAria: 'Compression tier',
140
142
  levelGentle: 'Gentle',
141
143
  levelLight: 'Light',
142
144
  levelStandard: 'Standard',
143
145
  levelAggressive: 'Aggressive',
144
146
  levelMax: 'Max',
145
- summaryGentle: 'Latest trigger, matches the official default.',
146
- summaryLight: 'One step earlier than the default.',
147
- summaryStandard: 'Default: cheaper long conversations.',
148
- summaryAggressive: 'Compacts sooner, cost first.',
149
- summaryMax: 'Cheapest: compacts at 40% of the window.',
150
147
  auto: 'Auto ',
151
148
  retain: 'keep ',
152
149
  sep: ': ',
@@ -160,9 +157,7 @@ window.__ModuleLoader__.load({
160
157
  lastCompact: 'Last compaction',
161
158
  never: 'none yet',
162
159
  settingsPath: 'Settings file',
163
- smallWindow: 'Designed for windows of at least 256k tokens; smaller windows mostly differ in retain size.',
164
160
  rulesTitle: 'Global rules',
165
- rulesIntro: 'Edits the official AGENTS.md; applies from the next session.',
166
161
  rulesLabel: 'Rules',
167
162
  rulesPlaceholder: 'For example: answer in Chinese; read AGENTS.md before a change.',
168
163
  rulesSave: 'Save',
@@ -174,29 +169,40 @@ window.__ModuleLoader__.load({
174
169
  rulesPathLabel: 'File',
175
170
  rulesLoading: 'Loading…',
176
171
  rulesMissing: 'missing; saving creates it.',
177
- ghTitle: 'GitHub CLI',
178
- ghIntro: 'Needed by the official change-request panel. A gh on PATH is used first; the managed build (v2.76.2) can be downloaded here and resumes after an interruption.',
179
- ghProbe: 'Re-check',
180
- ghInstalled: 'Installed',
181
- ghSystem: 'System install (PATH)',
182
- ghDownloading: 'Downloading ',
183
- ghPartial: 'Incomplete, can resume',
184
- ghFailed: 'Download failed',
185
- ghMissing: 'Not installed',
186
- ghDownload: 'Download',
187
- ghKeepDownload: 'Download anyway',
188
- ghContinue: 'Resume download',
189
- ghRetry: 'Retry',
190
- ghUnsupported: 'Unavailable on this system',
191
- ghPathLabel: 'Path',
172
+ componentsTitle: 'Components',
173
+ componentsLoadFailed: 'Could not read the component state: ',
174
+ componentsActionFailed: 'Action failed: ',
175
+ toolsPathLabel: 'Download directory',
176
+ toolsPathCurrent: 'Current directory',
177
+ toolsPathSave: 'Move here',
178
+ toolsPathReset: 'Reset to default',
179
+ toolsPathSaved: 'Moved.',
180
+ toolsPathInvalid: 'An absolute path is required.',
181
+ toolsPathRunning: 'A download is running; move after it finishes.',
182
+ toolsPathFailed: 'Could not move: ',
183
+ ghAuthTitle: 'GitHub sign-in',
184
+ probe: 'Re-check',
185
+ downloadIdle: 'Download',
186
+ downloadKeep: 'Download again',
187
+ downloadContinue: 'Resume download',
188
+ downloadRetry: 'Retry',
189
+ downloadRunning: 'Downloading ',
190
+ downloadDone: 'Installed',
191
+ downloadUnsupported: 'Unavailable on this system',
192
+ stateMissing: 'Not installed',
193
+ statePartial: 'Incomplete, can resume',
194
+ stateFailed: 'Download failed',
195
+ stateSystem: 'System install (PATH)',
196
+ pathLabel: 'Path',
192
197
  ghAuthUnknown: 'Reading the sign-in state…',
193
- ghAuthUnavailable: 'Download GitHub CLI to sign in.',
198
+ ghAuthUnavailable: 'cannot sign in',
194
199
  ghLoggedIn: 'Signed in: ',
195
200
  ghNotLoggedIn: 'Not signed in',
196
201
  ghLogin: 'Sign in to GitHub',
197
202
  ghRelogin: 'Sign in again',
198
203
  ghLoginStarting: 'Starting gh sign-in…',
199
- ghLoginNote: 'Paste the one-time code on the GitHub page and authorize; this panel updates by itself.',
204
+ ghLoginWaiting: 'Waiting for authorization',
205
+ ghLoginInactive: 'not signing in',
200
206
  ghLoginDone: 'Authorization finished; gh stored the credential.',
201
207
  ghLoginFailed: 'Sign-in did not finish; you can retry.',
202
208
  ghCopy: 'Copy code',
@@ -215,22 +221,9 @@ window.__ModuleLoader__.load({
215
221
  ghNetworkUnknown: 'unknown',
216
222
  ghDnsOff: 'DNS is not a GitHub address',
217
223
  ghScopeMissing: 'The token has no repo scope; pushing a private repository will fail.',
218
- ghToolNote: 'Publishing belongs to the github_push tool: it pushes the session working directory after a network probe and a secret scan. This panel only manages gh and checks the network.',
219
- toolsTitle: 'Video tools',
220
- toolsIntro: 'ffmpeg and ffprobe: download the managed build (about 110 MB, resumes after an interruption) or use the copies on PATH; the managed build wins.',
221
224
  toolsNotFound: 'not found',
222
225
  toolsManaged: 'managed',
223
226
  toolsSystem: 'system PATH',
224
- toolsLoading: 'Loading…',
225
- toolsInstalled: 'Installed',
226
- toolsInstall: 'Download and install',
227
- toolsContinue: 'Resume download',
228
- toolsRetry: 'Retry',
229
- toolsProbe: 'Re-check',
230
- toolsDownloading: 'Downloading ',
231
- toolsUnsupported: 'No managed build for this system',
232
- toolsLoadFailed: 'Could not read the video-tool state: ',
233
- toolsActionFailed: 'Action failed: ',
234
227
  repoSelectLabel: 'Repo',
235
228
  repoSelectAria: 'Online repository (the github_push target)',
236
229
  repoTitle: 'github_push publishes to this online repository by default',
@@ -345,6 +338,12 @@ window.__ModuleLoader__.load({
345
338
  line-height: 18px;
346
339
  color: var(--dsw-alias-label-secondary);
347
340
  }
341
+ /* An empty status or note line is dead space at the bottom of a panel: hide it
342
+ while there is nothing to say, and let it appear together with the message. */
343
+ .ct-status:empty,
344
+ .ct-note:empty {
345
+ display: none;
346
+ }
348
347
  .ct-meta {
349
348
  display: grid;
350
349
  gap: 2px;
@@ -418,30 +417,50 @@ window.__ModuleLoader__.load({
418
417
  align-items: center;
419
418
  gap: 10px;
420
419
  }
421
- .ct-save {
420
+ /* One button standard for the whole page: the ct-btn base is the geometry,
421
+ ct-btn--primary only changes emphasis. Every panel renders its actions in a
422
+ ct-actions row so the GitHub, download-location and video panels cannot
423
+ drift into different-looking buttons. */
424
+ .ct-actions {
425
+ display: flex;
426
+ flex-wrap: wrap;
427
+ align-items: center;
428
+ gap: 8px;
429
+ }
430
+ .ct-btn {
431
+ box-sizing: border-box;
432
+ display: inline-flex;
433
+ align-items: center;
434
+ justify-content: center;
435
+ height: 30px;
422
436
  margin: 0;
423
- border: 1px solid var(--dsw-alias-border-selected);
437
+ padding: 0 12px;
438
+ border: 1px solid var(--dsw-alias-border-l2);
424
439
  border-radius: 10px;
425
- padding: 6px 14px;
426
- background: var(--dsw-alias-bg-module-platform);
440
+ background: transparent;
427
441
  color: var(--dsw-alias-label-primary);
428
442
  font: inherit;
429
443
  font-size: 13px;
430
- line-height: 20px;
444
+ line-height: 18px;
445
+ white-space: nowrap;
431
446
  cursor: pointer;
432
447
  }
448
+ .ct-btn--primary {
449
+ border-color: var(--dsw-alias-border-selected);
450
+ background: var(--dsw-alias-bg-module-platform);
451
+ }
433
452
  @media (hover: hover) {
434
- .ct-save:hover:not(:disabled) {
453
+ .ct-btn:hover:not(:disabled) {
435
454
  background: var(--dsw-alias-interactive-bg-hover);
436
455
  }
437
456
  }
438
- .ct-save:disabled {
457
+ .ct-btn:disabled {
439
458
  border-color: var(--dsw-alias-border-l2);
440
459
  background: transparent;
441
460
  color: var(--dsw-alias-label-tertiary);
442
461
  cursor: default;
443
462
  }
444
- .ct-save:focus-visible {
463
+ .ct-btn:focus-visible {
445
464
  outline: 2px solid var(--dsw-alias-state-business-primary);
446
465
  outline-offset: 2px;
447
466
  }
@@ -488,12 +507,41 @@ window.__ModuleLoader__.load({
488
507
  color: var(--dsw-alias-label-tertiary);
489
508
  word-break: break-all;
490
509
  }
510
+ .ct-component {
511
+ display: grid;
512
+ gap: 6px;
513
+ padding-top: 10px;
514
+ border-top: 1px solid var(--dsw-alias-border-l2);
515
+ }
516
+ .ct-component:first-of-type {
517
+ padding-top: 0;
518
+ border-top: 0;
519
+ }
520
+ .ct-component-head {
521
+ display: flex;
522
+ flex-wrap: wrap;
523
+ align-items: baseline;
524
+ gap: 4px 10px;
525
+ }
526
+ .ct-component-name {
527
+ font-size: 13px;
528
+ font-weight: 600;
529
+ }
530
+ .ct-component-path {
531
+ word-break: break-all;
532
+ }
533
+ /* The pill lives in the tab strip, right after the tabs: that row is the only
534
+ chrome below the title that is not clipped (the title cluster itself is
535
+ overflow:clip with a mask fade), so the capsule reads as session meta instead
536
+ of being stranded at the far right edge. margin-top lines the 24px pill up
537
+ with the tab labels: a .tab starts -10px and pads 10px, so its label centre
538
+ sits 8px below the strip's content top, and 8 - 24/2 = -4. */
491
539
  .ct-repo-slot {
492
540
  display: flex;
493
541
  align-items: center;
542
+ align-self: flex-start;
494
543
  flex: none;
495
- margin-left: auto;
496
- margin-top: 2px;
544
+ margin-top: -4px;
497
545
  }
498
546
  .ct-repo-anchor-wrap {
499
547
  display: contents;
@@ -511,24 +559,25 @@ window.__ModuleLoader__.load({
511
559
  position: relative;
512
560
  display: inline-flex;
513
561
  align-items: center;
514
- gap: 5px;
562
+ gap: 6px;
515
563
  box-sizing: border-box;
516
- height: 26px;
517
- max-width: 260px;
564
+ height: 24px;
565
+ max-width: 300px;
518
566
  min-width: 0;
519
- padding: 0 8px;
567
+ padding: 0 9px 0 8px;
520
568
  border: 1px solid var(--dsw-alias-border-l2);
521
569
  border-radius: 999px;
522
570
  background: transparent;
523
571
  color: var(--dsw-alias-label-secondary);
524
572
  font-size: 12px;
525
- line-height: 16px;
573
+ line-height: 15px;
526
574
  white-space: nowrap;
527
- transition: background-color 120ms ease, border-color 120ms ease;
575
+ transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
528
576
  }
529
577
  @media (hover: hover) {
530
578
  .ct-repo-pill:hover {
531
579
  background: var(--dsw-alias-interactive-bg-hover);
580
+ border-color: var(--dsw-alias-border-l3);
532
581
  }
533
582
  }
534
583
  .ct-repo-pill:focus-within {
@@ -538,6 +587,7 @@ window.__ModuleLoader__.load({
538
587
  .ct-repo-pill[data-bound='true'] {
539
588
  border-color: var(--dsw-alias-border-selected);
540
589
  background: var(--dsw-alias-bg-module-platform);
590
+ color: var(--dsw-alias-label-primary);
541
591
  }
542
592
  .ct-repo-icon {
543
593
  flex: none;
@@ -551,6 +601,7 @@ window.__ModuleLoader__.load({
551
601
  .ct-repo-caption {
552
602
  flex: none;
553
603
  color: var(--dsw-alias-label-tertiary);
604
+ font-size: 11px;
554
605
  }
555
606
  .ct-repo-value {
556
607
  min-width: 0;
@@ -558,12 +609,21 @@ window.__ModuleLoader__.load({
558
609
  text-overflow: ellipsis;
559
610
  white-space: nowrap;
560
611
  color: var(--dsw-alias-label-primary);
612
+ font-weight: 500;
561
613
  }
562
614
  .ct-repo-chevron {
563
615
  flex: none;
564
616
  width: 12px;
565
617
  height: 12px;
566
618
  color: var(--dsw-alias-label-tertiary);
619
+ transition: transform 140ms ease;
620
+ }
621
+ .ct-repo-pill[aria-expanded='true'] .ct-repo-chevron {
622
+ transform: rotate(180deg);
623
+ }
624
+ .ct-repo-pill[aria-expanded='true'] {
625
+ border-color: var(--dsw-alias-border-l2);
626
+ background: var(--dsw-alias-interactive-bg-hover);
567
627
  }
568
628
  .ct-repo-pill {
569
629
  font-family: inherit;
@@ -591,12 +651,23 @@ window.__ModuleLoader__.load({
591
651
  font-size: 12px;
592
652
  line-height: 16px;
593
653
  }
654
+ .ct-repo-menu-head {
655
+ padding: 2px 8px 4px;
656
+ color: var(--dsw-alias-label-tertiary);
657
+ font-size: 11px;
658
+ line-height: 15px;
659
+ }
660
+ .ct-repo-sep {
661
+ height: 1px;
662
+ margin: 4px 8px;
663
+ background: var(--dsw-alias-border-l3);
664
+ }
594
665
  .ct-repo-option {
595
666
  display: flex;
596
667
  align-items: center;
597
668
  gap: 8px;
598
669
  width: 100%;
599
- min-height: 30px;
670
+ min-height: 32px;
600
671
  margin: 0;
601
672
  padding: 0 8px;
602
673
  border: 0;
@@ -619,6 +690,9 @@ window.__ModuleLoader__.load({
619
690
  .ct-repo-option-on {
620
691
  background: var(--dsw-alias-bg-module-platform);
621
692
  }
693
+ .ct-repo-option-on .ct-repo-option-name {
694
+ font-weight: 500;
695
+ }
622
696
  .ct-repo-check {
623
697
  flex: none;
624
698
  width: 12px;
@@ -662,9 +736,39 @@ window.__ModuleLoader__.load({
662
736
  return t(key)
663
737
  }
664
738
 
665
- function summaryOf(t, id) {
666
- const key = 'summary' + id.charAt(0).toUpperCase() + id.slice(1)
667
- return t(key)
739
+ /** Two directory spellings that name the same place, for the move button. */
740
+ function samePathDraft(a, b) {
741
+ const clean = function (value) {
742
+ return String(value || '').trim().replace(/[\\/]+$/, '').toLowerCase()
743
+ }
744
+ return clean(a) === clean(b)
745
+ }
746
+
747
+ /** Absolute on Windows (`C:\x`, `\\host\share`) or POSIX (`/x`). */
748
+ function looksAbsolute(value) {
749
+ return /^([A-Za-z]:[\\/]|\\\\|\/)/.test(String(value || '').trim())
750
+ }
751
+
752
+ /**
753
+ * The one button standard for this page. `ct-btn` is the geometry, the
754
+ * `ct-btn--primary` modifier only adds emphasis, and `data-action` gives
755
+ * tests a stable handle. No panel may style its own button.
756
+ */
757
+ function actionButton(action, label, options) {
758
+ const config = options || {}
759
+ return h('button', {
760
+ type: 'button',
761
+ className: 'ct-btn' + (config.primary ? ' ct-btn--primary' : ''),
762
+ 'data-action': action,
763
+ disabled: config.disabled === true,
764
+ title: config.title || '',
765
+ onClick: config.onClick,
766
+ }, label)
767
+ }
768
+
769
+ /** Every panel renders its buttons in this row and nothing else. */
770
+ function actionRow(children) {
771
+ return h('div', { className: 'ct-actions' }, children)
668
772
  }
669
773
 
670
774
  function timeLabel(value) {
@@ -903,6 +1007,24 @@ window.__ModuleLoader__.load({
903
1007
  }, h('path', { d: 'M4.5 6.25 8 9.75l3.5-3.5' })))
904
1008
 
905
1009
  const at = placement.current || { top: 0, left: 0, width: 240 }
1010
+ // Head line + separator keep "no repository" apart from the real list, so
1011
+ // the menu reads as a titled picker rather than a flat run of names.
1012
+ const menuChildren = [h('div', { key: '__head', className: 'ct-repo-menu-head', role: 'presentation' }, t('repoSelectLabel'))]
1013
+ items.forEach(function (item, index) {
1014
+ if (index === 1) menuChildren.push(h('div', { key: '__sep', className: 'ct-repo-sep', role: 'presentation' }))
1015
+ const selected = item.value === bound
1016
+ menuChildren.push(h('button', {
1017
+ key: item.value || '__none',
1018
+ type: 'button',
1019
+ role: 'option',
1020
+ 'aria-selected': selected ? 'true' : 'false',
1021
+ className: 'ct-repo-option' + (selected ? ' ct-repo-option-on' : ''),
1022
+ onClick: function () { chooseRepo(item.value) },
1023
+ },
1024
+ h('span', { className: 'ct-repo-check' }, selected ? '✓' : ''),
1025
+ h('span', { className: 'ct-repo-option-name' }, item.label),
1026
+ item.private ? h('span', { className: 'ct-repo-tag' }, t('repoPrivate')) : null))
1027
+ })
906
1028
  const menu = open && ReactDOM && typeof ReactDOM.createPortal === 'function'
907
1029
  ? ReactDOM.createPortal(h('div', {
908
1030
  ref: menuRef,
@@ -910,21 +1032,7 @@ window.__ModuleLoader__.load({
910
1032
  role: 'listbox',
911
1033
  'aria-label': t('repoSelectAria'),
912
1034
  style: { top: at.top + 'px', left: at.left + 'px', width: at.width + 'px' },
913
- },
914
- items.map(function (item) {
915
- const selected = item.value === bound
916
- return h('button', {
917
- key: item.value || '__none',
918
- type: 'button',
919
- role: 'option',
920
- 'aria-selected': selected ? 'true' : 'false',
921
- className: 'ct-repo-option' + (selected ? ' ct-repo-option-on' : ''),
922
- onClick: function () { chooseRepo(item.value) },
923
- },
924
- h('span', { className: 'ct-repo-check' }, selected ? '✓' : ''),
925
- h('span', { className: 'ct-repo-option-name' }, item.label),
926
- item.private ? h('span', { className: 'ct-repo-tag' }, t('repoPrivate')) : null)
927
- })), document.body)
1035
+ }, menuChildren), document.body)
928
1036
  : null
929
1037
 
930
1038
  const group = h('span', { className: 'ct-repo-group' },
@@ -947,14 +1055,19 @@ window.__ModuleLoader__.load({
947
1055
  const [rulesText, setRulesText] = React.useState('')
948
1056
  const [rulesMessage, setRulesMessage] = React.useState('')
949
1057
  const [rulesBusy, setRulesBusy] = React.useState(false)
950
- const [gh, setGh] = React.useState(null)
1058
+ // One payload for the whole component panel: the four rows and the shared
1059
+ // download root they all install below.
1060
+ const [components, setComponents] = React.useState(null)
1061
+ const [componentsMessage, setComponentsMessage] = React.useState('')
1062
+ const [componentsBusy, setComponentsBusy] = React.useState(false)
1063
+ const [pathDraft, setPathDraft] = React.useState(null)
1064
+ const [pathBusy, setPathBusy] = React.useState(false)
1065
+ // The gh device-code flow; the gh binary itself is a component row.
1066
+ const [login, setLogin] = React.useState(null)
951
1067
  const [auth, setAuth] = React.useState(null)
952
1068
  const [ghMessage, setGhMessage] = React.useState('')
953
1069
  const [ghBusy, setGhBusy] = React.useState(false)
954
1070
  const [network, setNetwork] = React.useState(null)
955
- const [tools, setTools] = React.useState(null)
956
- const [toolsMessage, setToolsMessage] = React.useState('')
957
- const [toolsBusy, setToolsBusy] = React.useState(false)
958
1071
  const mounted = React.useRef(true)
959
1072
  const buttons = React.useRef({})
960
1073
 
@@ -962,34 +1075,32 @@ window.__ModuleLoader__.load({
962
1075
  mounted.current = true
963
1076
  load()
964
1077
  loadRules()
965
- loadGithub()
1078
+ loadComponents()
1079
+ loadLogin()
966
1080
  loadAuth()
967
1081
  loadNetwork()
968
- loadTools()
969
1082
  return function () {
970
1083
  mounted.current = false
971
1084
  }
972
1085
  }, [])
973
1086
 
974
- const downloading = gh && gh.gh ? gh.gh.state === 'downloading' : false
975
- const loggingIn = gh && gh.login ? gh.login.active === true : false
976
- React.useEffect(function () {
977
- if (!downloading) return undefined
978
- const timer = window.setInterval(function () { loadGithub() }, 900)
979
- return function () { window.clearInterval(timer) }
980
- }, [downloading])
1087
+ const loggingIn = login ? login.active === true : false
981
1088
  React.useEffect(function () {
982
1089
  if (!loggingIn) return undefined
983
- const timer = window.setInterval(function () { loadGithub() }, 1500)
1090
+ const timer = window.setInterval(function () { loadLogin() }, 1500)
984
1091
  return function () { window.clearInterval(timer) }
985
1092
  }, [loggingIn])
986
1093
 
987
- const toolsRunning = tools && tools.download ? tools.download.running === true : false
1094
+ // Any managed install in flight keeps the panel refreshing; the payload
1095
+ // itself reports progress, so no second timer per component is needed.
1096
+ const anyRunning = components && Array.isArray(components.components)
1097
+ ? components.components.some(function (row) { return row && row.running === true })
1098
+ : false
988
1099
  React.useEffect(function () {
989
- if (!toolsRunning) return undefined
990
- const timer = window.setInterval(function () { loadTools() }, 1200)
1100
+ if (!anyRunning) return undefined
1101
+ const timer = window.setInterval(function () { loadComponents({ quiet: true }) }, 1200)
991
1102
  return function () { window.clearInterval(timer) }
992
- }, [toolsRunning])
1103
+ }, [anyRunning])
993
1104
 
994
1105
  function load() {
995
1106
  fetch(API, { credentials: 'same-origin' })
@@ -1024,21 +1135,22 @@ window.__ModuleLoader__.load({
1024
1135
  })
1025
1136
  }
1026
1137
 
1027
- function applyGithub(body) {
1028
- setGh({ gh: body && body.gh ? body.gh : null, login: body && body.login ? body.login : null })
1138
+ /** The device-code flow state; the gh binary lives in the component rows. */
1139
+ function applyLogin(body) {
1140
+ setLogin(body && body.login ? body.login : null)
1029
1141
  }
1030
1142
 
1031
- function loadGithub() {
1143
+ function loadLogin() {
1032
1144
  return fetch(GH_API, { credentials: 'same-origin' })
1033
1145
  .then(readJson)
1034
1146
  .then(function (body) {
1035
1147
  if (!mounted.current) return
1036
- applyGithub(body)
1148
+ applyLogin(body)
1037
1149
  if (body && body.login && body.login.state === 'success') loadAuth()
1038
1150
  })
1039
1151
  .catch(function (error) {
1040
1152
  if (!mounted.current) return
1041
- setGhMessage(t('ghLoadFailed') + (error && error.message ? error.message : String(error)))
1153
+ setGhMessage(t('ghLoadFailed') + messageOf(error))
1042
1154
  })
1043
1155
  }
1044
1156
 
@@ -1064,28 +1176,6 @@ window.__ModuleLoader__.load({
1064
1176
  }).then(readJson)
1065
1177
  }
1066
1178
 
1067
- function applyLogin(body) {
1068
- setGh(function (current) { return { gh: current ? current.gh : null, login: body } })
1069
- }
1070
-
1071
- function downloadGh() {
1072
- if (ghBusy) return
1073
- setGhBusy(true)
1074
- setGhMessage('')
1075
- githubAction({ action: 'download' })
1076
- .then(function (body) {
1077
- if (!mounted.current) return
1078
- setGh(function (current) { return { gh: body.gh || null, login: current ? current.login : null } })
1079
- })
1080
- .catch(function (error) {
1081
- if (!mounted.current) return
1082
- setGhMessage(t('ghActionFailed') + (error && error.message ? error.message : String(error)))
1083
- })
1084
- .then(function () {
1085
- if (mounted.current) setGhBusy(false)
1086
- })
1087
- }
1088
-
1089
1179
  function loginGh() {
1090
1180
  if (ghBusy) return
1091
1181
  setGhBusy(true)
@@ -1123,7 +1213,6 @@ window.__ModuleLoader__.load({
1123
1213
  }
1124
1214
 
1125
1215
  function copyCode() {
1126
- const login = gh && gh.login
1127
1216
  if (!login || !login.code) return
1128
1217
  try {
1129
1218
  if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
@@ -1140,7 +1229,6 @@ window.__ModuleLoader__.load({
1140
1229
  }
1141
1230
 
1142
1231
  function openDevice() {
1143
- const login = gh && gh.login
1144
1232
  const url = login && login.url ? login.url : 'https://github.com/login/device'
1145
1233
  window.open(url, '_blank', 'noopener,noreferrer')
1146
1234
  }
@@ -1158,41 +1246,77 @@ window.__ModuleLoader__.load({
1158
1246
  })
1159
1247
  }
1160
1248
 
1161
- function loadTools() {
1162
- return fetch(FFMPEG_API, { credentials: 'same-origin' })
1249
+ /**
1250
+ * The four component rows plus the shared download root. `quiet` keeps the
1251
+ * current status line (a refetch after an action must not erase its own
1252
+ * "migrated" message).
1253
+ */
1254
+ function loadComponents(options) {
1255
+ const quiet = Boolean(options && options.quiet)
1256
+ return fetch(COMPONENTS_API, { credentials: 'same-origin' })
1163
1257
  .then(readJson)
1164
1258
  .then(function (body) {
1165
1259
  if (!mounted.current) return
1166
- setTools(body)
1167
- setToolsMessage('')
1260
+ setComponents(body)
1261
+ if (!quiet) setComponentsMessage('')
1168
1262
  })
1169
1263
  .catch(function (error) {
1170
1264
  if (!mounted.current) return
1171
- setToolsMessage(t('toolsLoadFailed') + messageOf(error))
1265
+ setComponentsMessage(t('componentsLoadFailed') + messageOf(error))
1172
1266
  })
1173
1267
  }
1174
1268
 
1175
- function downloadTools() {
1176
- if (toolsBusy) return
1177
- setToolsBusy(true)
1178
- setToolsMessage('')
1179
- fetch(FFMPEG_API, {
1269
+ /** Start one component's managed install; the poll shows its progress. */
1270
+ function downloadComponent(id) {
1271
+ if (componentsBusy) return
1272
+ setComponentsBusy(true)
1273
+ setComponentsMessage('')
1274
+ fetch(COMPONENTS_API, {
1180
1275
  method: 'POST',
1181
1276
  credentials: 'same-origin',
1182
1277
  headers: { 'content-type': 'application/json' },
1183
- body: JSON.stringify({ action: 'download' }),
1278
+ body: JSON.stringify({ id: id, action: 'download' }),
1184
1279
  })
1185
1280
  .then(readJson)
1186
1281
  .then(function (body) {
1187
1282
  if (!mounted.current) return
1188
- setTools(body)
1283
+ setComponents(body)
1189
1284
  })
1190
1285
  .catch(function (error) {
1191
1286
  if (!mounted.current) return
1192
- setToolsMessage(t('toolsActionFailed') + messageOf(error))
1287
+ setComponentsMessage(t('componentsActionFailed') + messageOf(error))
1193
1288
  })
1194
1289
  .then(function () {
1195
- if (mounted.current) setToolsBusy(false)
1290
+ if (mounted.current) setComponentsBusy(false)
1291
+ })
1292
+ }
1293
+
1294
+ /** Move every managed component to `target` and persist it. */
1295
+ function migratePath(target) {
1296
+ if (pathBusy) return
1297
+ setPathBusy(true)
1298
+ setComponentsMessage('')
1299
+ fetch(TOOLS_API, {
1300
+ method: 'POST',
1301
+ credentials: 'same-origin',
1302
+ headers: { 'content-type': 'application/json' },
1303
+ body: JSON.stringify({ action: 'migrate', path: target }),
1304
+ })
1305
+ .then(readJson)
1306
+ .then(function (body) {
1307
+ if (!mounted.current) return
1308
+ setPathDraft(null)
1309
+ setComponentsMessage(t('toolsPathSaved'))
1310
+ // Every binary location changed, so every row is stale.
1311
+ loadComponents({ quiet: true })
1312
+ })
1313
+ .catch(function (error) {
1314
+ if (!mounted.current) return
1315
+ setComponentsMessage(t('toolsPathFailed') + messageOf(error))
1316
+ loadComponents({ quiet: true })
1317
+ })
1318
+ .then(function () {
1319
+ if (mounted.current) setPathBusy(false)
1196
1320
  })
1197
1321
  }
1198
1322
 
@@ -1262,11 +1386,46 @@ window.__ModuleLoader__.load({
1262
1386
  if (node && typeof node.focus === 'function') node.focus()
1263
1387
  }
1264
1388
 
1389
+ /**
1390
+ * The one download control shared by every component row: identical state
1391
+ * line and button label for identical states, so the four rows (and any
1392
+ * component added later) cannot drift into different-looking controls.
1393
+ */
1394
+ function downloadControl(model) {
1395
+ const loading = model.loading === true
1396
+ const unsupported = model.unsupported === true
1397
+ const running = model.running === true
1398
+ const system = model.system === true
1399
+ const installed = model.installed === true && !system
1400
+ const percent = model.percent == null ? '' : model.percent + '%'
1401
+ const stateText = loading
1402
+ ? t('loading')
1403
+ : unsupported ? t('downloadUnsupported')
1404
+ : running ? t('downloadRunning') + percent
1405
+ : system ? t('stateSystem')
1406
+ : installed ? t('downloadDone')
1407
+ : model.failed === true ? t('stateFailed')
1408
+ : model.partial === true ? t('statePartial')
1409
+ : t('stateMissing')
1410
+ const label = loading
1411
+ ? t('loading')
1412
+ : unsupported ? t('downloadUnsupported')
1413
+ : running ? t('downloadRunning')
1414
+ : system ? t('downloadKeep')
1415
+ : installed ? t('downloadDone')
1416
+ : model.failed === true ? t('downloadRetry')
1417
+ : model.partial === true ? t('downloadContinue')
1418
+ : t('downloadIdle')
1419
+ return {
1420
+ stateText,
1421
+ label,
1422
+ disabled: loading || unsupported || running || installed,
1423
+ }
1424
+ }
1265
1425
  const levels = state && Array.isArray(state.levels) && state.levels.length ? state.levels : LEVELS.map(function (id) {
1266
1426
  return { id: id }
1267
1427
  })
1268
1428
  const current = state ? state.level : ''
1269
- const currentSummary = current ? summaryOf(t, current) : ''
1270
1429
  const engineCount = state && typeof state.engines === 'number' ? state.engines : 0
1271
1430
  const last = state && state.lastCompact
1272
1431
  const lastText = last && last.at
@@ -1286,7 +1445,6 @@ window.__ModuleLoader__.load({
1286
1445
  'aria-checked': selected ? 'true' : 'false',
1287
1446
  tabIndex: selected ? 0 : -1,
1288
1447
  disabled: busy,
1289
- title: summaryOf(t, id),
1290
1448
  ref: function (node) { buttons.current[id] = node },
1291
1449
  className: 'ct-level' + (selected ? ' ct-level-on' : ''),
1292
1450
  onClick: function () { select(id) },
@@ -1295,7 +1453,7 @@ window.__ModuleLoader__.load({
1295
1453
  h('strong', null, labelOf(t, id)),
1296
1454
  h('span', null, t('auto') + percent(level.thresholdRatio) + ' · ' + t('retain') + percent(level.retainRatio)))
1297
1455
  })),
1298
- h('p', { className: 'ct-summary' }, t('currentLabel') + t('sep') + labelOf(t, current) + (currentSummary ? ' — ' + currentSummary : '')),
1456
+ h('p', { className: 'ct-summary' }, t('currentLabel') + t('sep') + labelOf(t, current)),
1299
1457
  h('p', { className: 'ct-status', role: 'status', 'aria-live': 'polite' }, message))
1300
1458
  : h('p', { className: 'ct-intro', role: 'status' }, message || t('loading'))
1301
1459
 
@@ -1304,8 +1462,7 @@ window.__ModuleLoader__.load({
1304
1462
  const rulesLimit = rules && typeof rules.maxChars === 'number' ? rules.maxChars : 0
1305
1463
  const rulesPanel = h('section', { className: 'ct-panel' },
1306
1464
  h('div', { className: 'ct-rules-head' },
1307
- h('h3', null, t('rulesTitle')),
1308
- h('p', { className: 'ct-note' }, t('rulesIntro'))),
1465
+ h('h3', null, t('rulesTitle'))),
1309
1466
  h('label', { className: 'ct-field' },
1310
1467
  h('span', null, t('rulesLabel')),
1311
1468
  h('textarea', {
@@ -1317,51 +1474,148 @@ window.__ModuleLoader__.load({
1317
1474
  disabled: rulesBusy || !rules,
1318
1475
  onChange: function (event) { setRulesText(event.target.value) },
1319
1476
  })),
1320
- h('div', { className: 'ct-row' },
1321
- h('button', {
1322
- type: 'button',
1323
- className: 'ct-save',
1477
+ h('p', { className: 'ct-note' }, rules
1478
+ ? t('rulesChars') + ' ' + rulesCount + ' / ' + rulesLimit
1479
+ : (rulesMessage ? '' : t('rulesLoading'))),
1480
+ actionRow([
1481
+ actionButton('rulesSave', rulesBusy ? t('rulesSaving') : t('rulesSave'), {
1324
1482
  disabled: rulesBusy || !rules || !dirty,
1325
1483
  onClick: saveRules,
1326
- }, rulesBusy ? t('rulesSaving') : t('rulesSave')),
1327
- h('span', { className: 'ct-note' }, rules
1328
- ? t('rulesChars') + ' ' + rulesCount + ' / ' + rulesLimit
1329
- : (rulesMessage ? '' : t('rulesLoading')))),
1484
+ primary: true,
1485
+ }),
1486
+ ]),
1330
1487
  h('p', { className: 'ct-status', role: 'status', 'aria-live': 'polite' }, rulesMessage),
1331
1488
  rules && rules.path
1332
1489
  ? h('p', { className: 'ct-note' }, t('rulesPathLabel') + t('sep') + rules.path + (rules.exists === false ? ' — ' + t('rulesMissing') : ''))
1333
1490
  : null)
1334
1491
 
1335
- const ghItem = gh && gh.gh ? gh.gh : null
1336
- const login = gh && gh.login ? gh.login : null
1337
- const ghSupported = ghItem ? ghItem.supported !== false : false
1338
- const ghBusyNow = ghBusy || (ghItem ? ghItem.state === 'downloading' : false)
1339
- const ghStateText = !ghItem
1340
- ? t('loading')
1341
- : ghItem.state === 'installed'
1342
- ? t('ghInstalled')
1343
- : ghItem.state === 'system'
1344
- ? t('ghSystem')
1345
- : ghItem.state === 'downloading'
1346
- ? t('ghDownloading') + (ghItem.percent == null ? '' : ghItem.percent + '%')
1347
- : ghItem.state === 'partial'
1348
- ? t('ghPartial')
1349
- : ghItem.state === 'error'
1350
- ? t('ghFailed')
1351
- : t('ghMissing')
1352
- const downloadLabel = !ghItem || ghItem.supported === false
1353
- ? t('ghUnsupported')
1354
- : ghItem.state === 'installed'
1355
- ? t('ghInstalled')
1356
- : ghItem.state === 'system'
1357
- ? t('ghKeepDownload')
1358
- : ghItem.state === 'downloading'
1359
- ? t('ghDownloading')
1360
- : ghItem.state === 'partial'
1361
- ? t('ghContinue')
1362
- : ghItem.state === 'error'
1363
- ? t('ghRetry')
1364
- : t('ghDownload')
1492
+ /**
1493
+ * The binaries of a multi-binary component: one line per found binary.
1494
+ * Nothing is listed when none is found — the title already names the pair
1495
+ * and the state line already says 未安装, so a "未找到" line would only
1496
+ * repeat it. A single missing binary gets one line naming just that one.
1497
+ */
1498
+ function componentToolLines(row) {
1499
+ if (!row || !row.tools) return null
1500
+ const found = row.tools.filter(function (tool) { return Boolean(tool.path) })
1501
+ if (found.length === 0) return null
1502
+ const missing = row.tools.filter(function (tool) { return !tool.path })
1503
+ const lines = found.map(function (tool) {
1504
+ return h('div', { className: 'ct-tool', key: tool.name },
1505
+ h('span', { className: 'ct-tool-name' }, tool.name),
1506
+ h('span', { className: 'ct-note' }, (tool.managed ? t('toolsManaged') : t('toolsSystem')) + (tool.version ? ' v' + tool.version : '')),
1507
+ tool.path ? h('span', { className: 'ct-tool-path' }, tool.path) : null)
1508
+ })
1509
+ if (missing.length > 0) {
1510
+ lines.push(h('div', { className: 'ct-tool', key: 'missing' },
1511
+ h('span', { className: 'ct-tool-name' }, missing.map(function (tool) { return tool.name }).join(' / ')),
1512
+ h('span', { className: 'ct-note' }, t('toolsNotFound'))))
1513
+ }
1514
+ return h('div', { className: 'ct-tools-list' }, lines)
1515
+ }
1516
+
1517
+ // ---- component panel: four rows plus the download root they share ----
1518
+ const rootInfo = components && components.root ? components.root : null
1519
+ const rootPath = rootInfo && rootInfo.path ? String(rootInfo.path) : ''
1520
+ const rootDefault = rootInfo && rootInfo.defaultPath ? String(rootInfo.defaultPath) : ''
1521
+ const rootRunning = Boolean(rootInfo && rootInfo.running && COMPONENT_ROWS.some(function (def) {
1522
+ return rootInfo.running[def.id] === true
1523
+ }))
1524
+ const rowsById = {}
1525
+ if (components && Array.isArray(components.components)) {
1526
+ components.components.forEach(function (row) {
1527
+ if (row && row.id) rowsById[row.id] = row
1528
+ })
1529
+ }
1530
+ // Every row renders through the one download control and the one button
1531
+ // standard; a component whose payload has not arrived still renders its
1532
+ // two buttons, disabled, instead of vanishing from the panel.
1533
+ const componentNodes = COMPONENT_ROWS.map(function (def) {
1534
+ const row = rowsById[def.id] || null
1535
+ const control = downloadControl({
1536
+ loading: !row,
1537
+ unsupported: Boolean(row && row.supported === false),
1538
+ running: Boolean(row && row.state === 'downloading'),
1539
+ installed: Boolean(row && row.state === 'installed'),
1540
+ partial: Boolean(row && row.state === 'partial'),
1541
+ failed: Boolean(row && row.state === 'error'),
1542
+ system: Boolean(row && row.state === 'system'),
1543
+ percent: row ? row.percent : null,
1544
+ })
1545
+ const pinned = row && row.version ? ' · v' + row.version : ''
1546
+ const used = row && row.toolVersion ? ' (' + row.toolVersion + ')' : ''
1547
+ // A row that covers several binaries says so in its title, so "ffprobe
1548
+ // is part of this row" stays visible even when there is nothing to list.
1549
+ const title = row && row.tools
1550
+ ? row.tools.map(function (tool) { return tool.name }).join(' / ')
1551
+ : (row && row.name ? row.name : def.name)
1552
+ const bar = Boolean(row) && row.percent != null
1553
+ && (row.state === 'downloading' || row.state === 'partial' || row.state === 'error')
1554
+ return h('div', { className: 'ct-component', key: def.id },
1555
+ h('div', { className: 'ct-component-head' },
1556
+ h('strong', { className: 'ct-component-name' }, title),
1557
+ h('span', { className: 'ct-note' }, control.stateText + pinned + used)),
1558
+ bar ? h('div', { className: 'ct-progress' }, h('span', { style: { width: (row.percent || 0) + '%' } })) : null,
1559
+ row && row.path ? h('p', { className: 'ct-note ct-component-path' }, t('pathLabel') + t('sep') + row.path) : null,
1560
+ componentToolLines(row),
1561
+ row && row.error ? h('p', { className: 'ct-status', role: 'alert' }, row.error) : null,
1562
+ actionRow([
1563
+ actionButton('download:' + def.id, control.label, {
1564
+ disabled: componentsBusy || control.disabled,
1565
+ onClick: function () { downloadComponent(def.id) },
1566
+ primary: true,
1567
+ }),
1568
+ actionButton('probe:' + def.id, t('probe'), { onClick: function () { loadComponents(); loadAuth() } }),
1569
+ ]))
1570
+ })
1571
+
1572
+ // The shared download root sits in the same panel: it is what a component
1573
+ // installs below, so moving it is a component action. Both buttons stay
1574
+ // rendered and go disabled while a download runs or the draft is unchanged.
1575
+ const pathValue = pathDraft === null ? rootPath : pathDraft
1576
+ const pathClean = String(pathValue == null ? '' : pathValue).trim()
1577
+ const pathInvalid = pathClean.length > 0 && !looksAbsolute(pathClean)
1578
+ const pathChanged = rootPath !== '' && !samePathDraft(pathClean, rootPath)
1579
+ const pathDisabled = pathBusy || rootRunning || !rootPath || !pathClean || pathInvalid || !pathChanged
1580
+ const pathTitle = rootRunning ? t('toolsPathRunning') : pathInvalid ? t('toolsPathInvalid') : ''
1581
+ const pathBlock = h('div', { className: 'ct-rules-head' },
1582
+ h('label', { className: 'ct-field' },
1583
+ h('span', null, t('toolsPathLabel')),
1584
+ h('div', { className: 'ct-row' },
1585
+ h('input', {
1586
+ className: 'ct-input',
1587
+ type: 'text',
1588
+ spellCheck: false,
1589
+ value: pathValue,
1590
+ placeholder: rootDefault,
1591
+ disabled: pathBusy,
1592
+ onChange: function (event) { setPathDraft(event.target.value) },
1593
+ }))),
1594
+ h('p', { className: 'ct-note' }, rootPath
1595
+ ? t('toolsPathCurrent') + t('sep') + rootPath
1596
+ : (componentsMessage ? '' : t('loading'))),
1597
+ rootRunning ? h('p', { className: 'ct-note' }, t('toolsPathRunning')) : null,
1598
+ actionRow([
1599
+ actionButton('toolsPathMigrate', pathBusy ? t('rulesSaving') : t('toolsPathSave'), {
1600
+ disabled: pathDisabled,
1601
+ title: pathTitle,
1602
+ onClick: function () { migratePath(pathClean) },
1603
+ primary: true,
1604
+ }),
1605
+ actionButton('toolsPathReset', t('toolsPathReset'), {
1606
+ disabled: pathBusy || rootRunning || !rootDefault || samePathDraft(rootPath, rootDefault),
1607
+ title: rootRunning ? t('toolsPathRunning') : '',
1608
+ onClick: function () { migratePath(rootDefault) },
1609
+ }),
1610
+ ]))
1611
+
1612
+ const componentsPanel = h('section', { className: 'ct-panel' },
1613
+ h('div', { className: 'ct-rules-head' },
1614
+ h('h3', null, t('componentsTitle'))),
1615
+ componentNodes,
1616
+ pathBlock,
1617
+ h('p', { className: 'ct-status', role: 'status', 'aria-live': 'polite' }, componentsMessage))
1618
+
1365
1619
  const authText = auth === null
1366
1620
  ? t('ghAuthUnknown')
1367
1621
  : !auth.available
@@ -1369,27 +1623,39 @@ window.__ModuleLoader__.load({
1369
1623
  : auth.authenticated
1370
1624
  ? t('ghLoggedIn') + (auth.account || 'GitHub')
1371
1625
  : t('ghNotLoggedIn')
1372
- const ghLoginVisible = Boolean(login && (login.active || login.state === 'success' || login.state === 'error'))
1373
- const ghLoginLead = !login
1626
+ // The sign-in block is always rendered: a button that only exists while a
1627
+ // condition holds makes the panel jump. Unusable actions go disabled with
1628
+ // the reason in `title` instead.
1629
+ const loginActive = Boolean(login && login.active)
1630
+ const loginCode = login && login.code ? login.code : ''
1631
+ const loginLead = !login
1374
1632
  ? ''
1375
- : login.active
1376
- ? (login.code ? t('ghLoginNote') : (login.note || t('ghLoginStarting')))
1377
- : login.state === 'success' ? t('ghLoginDone') : t('ghLoginFailed')
1378
- const ghLoginBlock = ghLoginVisible
1379
- ? h('div', { className: 'ct-rules-head' },
1380
- h('p', { className: 'ct-note' }, ghLoginLead),
1381
- login.active && login.code
1382
- ? h('div', { className: 'ct-row' },
1383
- h('code', { className: 'ct-code' }, login.code),
1384
- h('button', { type: 'button', className: 'ct-save', onClick: copyCode }, t('ghCopy')))
1385
- : null,
1386
- login.active
1387
- ? h('div', { className: 'ct-row' },
1388
- h('button', { type: 'button', className: 'ct-save', onClick: openDevice }, t('ghOpenDevice')),
1389
- h('button', { type: 'button', className: 'ct-save', disabled: ghBusy, onClick: cancelLogin }, t('ghCancel')))
1390
- : null,
1391
- login.error ? h('p', { className: 'ct-status', role: 'alert' }, login.error) : null)
1392
- : null
1633
+ : loginActive
1634
+ ? (loginCode ? t('ghLoginWaiting') : (login.note || t('ghLoginStarting')))
1635
+ : login.state === 'success' ? t('ghLoginDone') : login.state === 'error' ? t('ghLoginFailed') : ''
1636
+ const loginInactiveTitle = loginActive ? '' : t('ghLoginInactive')
1637
+ const ghLoginBlock = h('div', { className: 'ct-rules-head' },
1638
+ h('p', { className: 'ct-note' }, loginLead),
1639
+ h('div', { className: 'ct-row' }, h('code', { className: 'ct-code' }, loginCode || '—')),
1640
+ actionRow([
1641
+ actionButton('ghCopy', t('ghCopy'), {
1642
+ disabled: ghBusy || !loginCode,
1643
+ title: loginCode ? '' : t('ghLoginInactive'),
1644
+ onClick: copyCode,
1645
+ }),
1646
+ actionButton('ghOpenDevice', t('ghOpenDevice'), {
1647
+ disabled: ghBusy || !loginActive,
1648
+ title: loginInactiveTitle,
1649
+ onClick: openDevice,
1650
+ primary: true,
1651
+ }),
1652
+ actionButton('ghCancel', t('ghCancel'), {
1653
+ disabled: ghBusy || !loginActive,
1654
+ title: loginInactiveTitle,
1655
+ onClick: cancelLogin,
1656
+ }),
1657
+ ]),
1658
+ login && login.error ? h('p', { className: 'ct-status', role: 'alert' }, login.error) : null)
1393
1659
  const networkText = !network
1394
1660
  ? ''
1395
1661
  : network.verdict === 'direct' ? t('ghNetworkDirect')
@@ -1404,47 +1670,23 @@ window.__ModuleLoader__.load({
1404
1670
  networkText
1405
1671
  ? h('p', { className: 'ct-note' }, t('ghNetworkLabel') + t('sep') + networkText + (dnsNote ? ' · ' + dnsNote : ''))
1406
1672
  : null,
1407
- h('p', { className: 'ct-note' }, t('ghToolNote')),
1408
- h('div', { className: 'ct-row' },
1409
- h('button', {
1410
- type: 'button',
1411
- className: 'ct-save',
1412
- onClick: function () { loadNetwork() },
1413
- }, t('ghNetwork'))))
1673
+ actionRow([
1674
+ actionButton('ghNetwork', t('ghNetwork'), { onClick: function () { loadNetwork() } }),
1675
+ ]))
1414
1676
 
1415
- const ghPanel = h('section', { className: 'ct-panel' },
1677
+ // The signed-in account, the device flow and the network probe. The `gh`
1678
+ // binary itself is one row in the component panel above.
1679
+ const ghAuthPanel = h('section', { className: 'ct-panel' },
1416
1680
  h('div', { className: 'ct-rules-head' },
1417
- h('h3', null, t('ghTitle')),
1418
- h('p', { className: 'ct-note' }, t('ghIntro'))),
1419
- h('div', { className: 'ct-row' },
1420
- h('span', { className: 'ct-note' }, ghStateText),
1421
- ghItem && ghItem.version ? h('span', { className: 'ct-note' }, 'v' + ghItem.version) : null,
1422
- h('button', {
1423
- type: 'button',
1424
- className: 'ct-save',
1425
- disabled: ghBusyNow || !ghItem || ghItem.state === 'installed' || !ghSupported,
1426
- onClick: downloadGh,
1427
- }, downloadLabel),
1428
- h('button', {
1429
- type: 'button',
1430
- className: 'ct-save',
1431
- onClick: function () { loadGithub(); loadAuth() },
1432
- }, t('ghProbe'))),
1433
- ghItem && (ghItem.state === 'downloading' || ghItem.state === 'partial') && ghItem.percent != null
1434
- ? h('div', { className: 'ct-progress' }, h('span', { style: { width: ghItem.percent + '%' } }))
1435
- : null,
1436
- ghItem && ghItem.binaryPath
1437
- ? h('p', { className: 'ct-note' }, t('ghPathLabel') + t('sep') + ghItem.binaryPath)
1438
- : null,
1439
- ghItem && ghItem.error ? h('p', { className: 'ct-status', role: 'alert' }, ghItem.error) : null,
1440
- h('div', { className: 'ct-row' },
1441
- h('span', { className: 'ct-note' }, authText),
1442
- h('button', {
1443
- type: 'button',
1444
- className: 'ct-save',
1681
+ h('h3', null, t('ghAuthTitle'))),
1682
+ h('p', { className: 'ct-note' }, authText),
1683
+ actionRow([
1684
+ actionButton('ghLogin', auth && auth.authenticated ? t('ghRelogin') : t('ghLogin'), {
1445
1685
  disabled: ghBusy || loggingIn || !auth || !auth.available,
1446
1686
  onClick: loginGh,
1447
- }, auth && auth.authenticated ? t('ghRelogin') : t('ghLogin'))),
1687
+ primary: true,
1688
+ }),
1689
+ ]),
1448
1690
  auth && auth.missingRepoScope
1449
1691
  ? h('p', { className: 'ct-status', role: 'alert' }, t('ghScopeMissing'))
1450
1692
  : null,
@@ -1452,75 +1694,20 @@ window.__ModuleLoader__.load({
1452
1694
  networkBlock,
1453
1695
  ghMessage ? h('p', { className: 'ct-status', role: 'status', 'aria-live': 'polite' }, ghMessage) : null)
1454
1696
 
1455
- const toolsItem = tools
1456
- const toolsDownload = toolsItem && toolsItem.download ? toolsItem.download : null
1457
- const toolsSupported = toolsItem ? toolsItem.supported !== false : false
1458
- const toolsRunningNow = toolsDownload ? toolsDownload.running === true : false
1459
- const toolsInstalled = toolsItem ? toolsItem.state === 'installed' : false
1460
- const toolsButton = !toolsItem
1461
- ? t('toolsLoading')
1462
- : !toolsSupported
1463
- ? t('toolsUnsupported')
1464
- : toolsRunningNow
1465
- ? t('toolsDownloading') + (toolsDownload.percent == null ? '' : toolsDownload.percent + '%')
1466
- : toolsInstalled
1467
- ? t('toolsInstalled')
1468
- : toolsDownload && toolsDownload.error
1469
- ? t('toolsRetry')
1470
- : toolsItem.state === 'missing' ? t('toolsInstall') : t('toolsContinue')
1471
- const toolRow = function (name, info) {
1472
- const version = info && info.version ? ' v' + info.version : ''
1473
- const origin = !info
1474
- ? t('toolsNotFound')
1475
- : (info.managed ? t('toolsManaged') : t('toolsSystem')) + version
1476
- return h('div', { className: 'ct-tool', key: name },
1477
- h('span', { className: 'ct-tool-name' }, name),
1478
- h('span', { className: 'ct-note' }, origin),
1479
- info && info.path ? h('span', { className: 'ct-tool-path' }, info.path) : null)
1480
- }
1481
- const toolsPanel = h('section', { className: 'ct-panel' },
1482
- h('div', { className: 'ct-rules-head' },
1483
- h('h3', null, t('toolsTitle')),
1484
- h('p', { className: 'ct-note' }, t('toolsIntro'))),
1485
- h('div', { className: 'ct-tools-list' },
1486
- toolRow('ffmpeg', toolsItem ? toolsItem.ffmpeg : null),
1487
- toolRow('ffprobe', toolsItem ? toolsItem.ffprobe : null)),
1488
- h('div', { className: 'ct-row' },
1489
- h('button', {
1490
- type: 'button',
1491
- className: 'ct-save',
1492
- disabled: toolsBusy || !toolsItem || !toolsSupported || toolsRunningNow || toolsInstalled,
1493
- onClick: downloadTools,
1494
- }, toolsButton),
1495
- h('button', {
1496
- type: 'button',
1497
- className: 'ct-save',
1498
- onClick: function () { loadTools() },
1499
- }, t('toolsProbe'))),
1500
- toolsRunningNow || (toolsDownload && toolsDownload.error && toolsDownload.percent != null)
1501
- ? h('div', { className: 'ct-progress' }, h('span', { style: { width: (toolsDownload.percent || 0) + '%' } }))
1502
- : null,
1503
- toolsDownload && toolsDownload.error
1504
- ? h('p', { className: 'ct-status', role: 'alert' }, toolsDownload.error)
1505
- : null,
1506
- toolsMessage ? h('p', { className: 'ct-status', role: 'status', 'aria-live': 'polite' }, toolsMessage) : null)
1507
-
1508
1697
  return h('section', { className: 'ct-page' },
1509
1698
  h('header', { className: 'ct-head' },
1510
- h('h2', null, t('title')),
1511
- h('p', { className: 'ct-intro' }, t('intro'))),
1699
+ h('h2', null, t('title'))),
1512
1700
  panel,
1513
1701
  rulesPanel,
1514
- ghPanel,
1515
- toolsPanel,
1702
+ componentsPanel,
1703
+ ghAuthPanel,
1516
1704
  state
1517
1705
  ? h('div', { className: 'ct-meta' },
1518
1706
  h('span', null, t('engines') + t('sep') + engineCount),
1519
1707
  h('span', null, t('lastCompact') + t('sep') + lastText),
1520
1708
  state.paths && state.paths.settings
1521
1709
  ? h('span', null, t('settingsPath') + t('sep') + state.paths.settings)
1522
- : null,
1523
- h('span', null, t('smallWindow')))
1710
+ : null)
1524
1711
  : null)
1525
1712
  }
1526
1713