@vibedev-si/dsh-island 0.0.0-stage → 0.2.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/CHANGELOG.md +63 -0
- package/LICENSE +27 -0
- package/THIRD-PARTY-NOTICES.txt +8458 -0
- package/approvals.js +125 -0
- package/attention.js +123 -0
- package/bin/win32-x64/vibedev-island.exe +0 -0
- package/changelog.js +80 -0
- package/client.js +2809 -0
- package/contributions.js +261 -0
- package/contributor-display.js +68 -0
- package/contributor-entry.js +49 -0
- package/cordis.patch.yml +6 -0
- package/diagnostics.js +92 -0
- package/events.js +89 -0
- package/executable.js +37 -0
- package/icon.svg +21 -0
- package/index.js +1291 -0
- package/island-items.js +191 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/log.js +53 -0
- package/openers.js +77 -0
- package/outbox.js +78 -0
- package/package.json +80 -4
- package/recent.js +194 -0
- package/requests.js +84 -0
- package/routes.js +201 -0
- package/selection.js +78 -0
- package/sessions.js +258 -0
- package/settings.js +344 -0
- package/third-party.json +1666 -0
- package/translate.js +53 -0
- package/wechat.js +53 -0
- package/README.md +0 -3
package/client.js
ADDED
|
@@ -0,0 +1,2809 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件页里的岛屿设置(`plugins.bundle.config`,以包名为 key)。
|
|
3
|
+
*
|
|
4
|
+
* 和 VibeDev 自己的插件一样,界面通过同源 `fetch` 读写宿主路由,不依赖宿主的内部组件包;
|
|
5
|
+
* 样式只用 `--dsw-alias-*` 主题 token,浅色/深色跟随 VibeDev。
|
|
6
|
+
*
|
|
7
|
+
* 样式以组件树内的 <style> 渲染,而不是插到 document.head:插件页可能把它渲染在
|
|
8
|
+
* 自己的容器里,写进树里才一定能命中。
|
|
9
|
+
*/
|
|
10
|
+
window.__ModuleLoader__.load({
|
|
11
|
+
id: '@vibedev-si/dsh-island',
|
|
12
|
+
factory(require) {
|
|
13
|
+
const React = require('react')
|
|
14
|
+
const h = React.createElement
|
|
15
|
+
|
|
16
|
+
const PACKAGE_NAME = '@vibedev-si/dsh-island'
|
|
17
|
+
const STATUS_URL = '/api/dsh-island/status'
|
|
18
|
+
const SETTINGS_URL = '/api/dsh-island/settings'
|
|
19
|
+
const CONTROL_URL = '/api/dsh-island/control'
|
|
20
|
+
const EVENTS_URL = '/api/dsh-island/events'
|
|
21
|
+
const CHANGELOG_URL = '/api/dsh-island/changelog'
|
|
22
|
+
const SELECTION_URL = '/api/dsh-island/selection'
|
|
23
|
+
const OUTBOX_URL = '/api/dsh-island/outbox'
|
|
24
|
+
const THEME_URL = '/api/dsh-island/theme'
|
|
25
|
+
/** 报 VibeDev 的深浅失败时(宿主还没起来)隔多久再试、最多试几次。 */
|
|
26
|
+
const THEME_RETRY_MS = 3000
|
|
27
|
+
const THEME_RETRIES = 10
|
|
28
|
+
const LICENSES_URL = '/api/dsh-island/licenses'
|
|
29
|
+
|
|
30
|
+
/** 提示音:设置里的值和设置页上的说法(文件见 native/src-tauri/src/sound.rs)。 */
|
|
31
|
+
const SOUND_CHOICES = [
|
|
32
|
+
['exclamation', '系统提示(默认)'],
|
|
33
|
+
['notify', '轻提示'],
|
|
34
|
+
['message', '消息'],
|
|
35
|
+
['calendar', '日历'],
|
|
36
|
+
['chimes', '风铃'],
|
|
37
|
+
['chord', '和弦'],
|
|
38
|
+
['tada', '完成'],
|
|
39
|
+
]
|
|
40
|
+
/** 截完之后的默认动作:设置里的值和设置页上的说法。 */
|
|
41
|
+
const SCREENSHOT_ACTIONS = [
|
|
42
|
+
['copy', '复制到剪贴板'],
|
|
43
|
+
['save', '复制并保存到文件夹'],
|
|
44
|
+
['send', '发给会话(在小岛上选)'],
|
|
45
|
+
]
|
|
46
|
+
/** 运行状态多久读一次。 */
|
|
47
|
+
const STATUS_POLL_MS = 5000
|
|
48
|
+
/** 长轮询出错后隔多久再试;连续失败时翻倍,直到上限。 */
|
|
49
|
+
const EVENTS_RETRY_MS = 3000
|
|
50
|
+
const EVENTS_RETRY_MAX_MS = 30000
|
|
51
|
+
const NO_EVENTS = Object.freeze(Array.of())
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 宿主页面侧的 `uiWorkspace` 服务:打开会话、选文件夹都靠它。`apply` 里才拿得到上下文,
|
|
55
|
+
* 所以这里先放一个占位,届时换成真的。
|
|
56
|
+
*/
|
|
57
|
+
let workspaceOf = () => undefined
|
|
58
|
+
/** 页面的 `layout` 服务(切主区域的面板);插件接上之前没有。 */
|
|
59
|
+
let layoutOf = () => undefined
|
|
60
|
+
/** 页面的 sessions 服务(发送到会话用);插件加载后才有。 */
|
|
61
|
+
let sessionsOf = () => undefined
|
|
62
|
+
|
|
63
|
+
/** 宿主能选文件夹时返回一个 `() => Promise<string | null>`,否则 undefined。 */
|
|
64
|
+
function directoryPicker() {
|
|
65
|
+
const workspace = workspaceOf()
|
|
66
|
+
return typeof workspace?.pickDirectory === 'function' ? () => workspace.pickDirectory() : undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const CSS = `
|
|
70
|
+
.vdi { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 0; color: var(--dsw-alias-label-primary); font-size: 14px; line-height: 22px; }
|
|
71
|
+
.vdi * { box-sizing: border-box; }
|
|
72
|
+
.vdi__nav { display: flex; flex-direction: column; gap: 1px; padding: 4px 8px 4px 0; }
|
|
73
|
+
.vdi__nav button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px; border: 0; border-radius: 8px; background: none; font: inherit; font-size: 13px; color: var(--dsw-alias-label-secondary); text-align: left; cursor: pointer; }
|
|
74
|
+
.vdi__nav svg { flex: none; }
|
|
75
|
+
.vdi__nav button:hover { background: color-mix(in srgb, var(--dsw-alias-label-primary) 6%, transparent); }
|
|
76
|
+
.vdi__nav button[aria-current="true"] { background: color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent); color: var(--dsw-alias-label-primary); font-weight: 500; }
|
|
77
|
+
.vdi__body { min-width: 0; padding: 2px 0 8px 20px; max-width: 860px; }
|
|
78
|
+
.vdi__title { font-size: 18px; line-height: 26px; font-weight: 600; }
|
|
79
|
+
.vdi__desc { margin-top: 2px; font-size: 13px; color: var(--dsw-alias-label-secondary); }
|
|
80
|
+
|
|
81
|
+
.vdi-card { margin-top: 12px; border: .5px solid var(--dsw-alias-border-l1); border-radius: 12px; background: var(--dsw-alias-bg-layer-1); padding: 14px 16px; }
|
|
82
|
+
.vdi-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
|
83
|
+
.vdi-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--dsw-alias-state-idle-primary); }
|
|
84
|
+
.vdi-dot--ok { background: var(--dsw-alias-state-success-primary); }
|
|
85
|
+
.vdi-dot--bad { background: var(--dsw-alias-state-error-primary); }
|
|
86
|
+
.vdi-licenses { margin: 4px 0 2px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
|
|
87
|
+
.vdi-licenses summary { cursor: pointer; }
|
|
88
|
+
.vdi-licenses ul { max-height: 260px; overflow: auto; margin: 8px 0 0; padding-left: 18px; columns: 2; column-gap: 24px; }
|
|
89
|
+
.vdi-status__text { font-weight: 600; }
|
|
90
|
+
.vdi-status__meta { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
|
|
91
|
+
.vdi-status__actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
|
|
92
|
+
|
|
93
|
+
.vdi-facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 12px 0 0; padding: 0; }
|
|
94
|
+
.vdi-facts dt { font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
95
|
+
.vdi-facts dd { margin: 0; font-size: 13px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
96
|
+
|
|
97
|
+
.vdi-ov { margin-top: 12px; }
|
|
98
|
+
.vdi-ov__card { border: .5px solid var(--dsw-alias-border-l1); border-radius: 12px; background: var(--dsw-alias-bg-layer-1); padding: 16px; }
|
|
99
|
+
|
|
100
|
+
.vdi-group { margin-top: 20px; }
|
|
101
|
+
.vdi-group__head h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--dsw-alias-label-secondary); }
|
|
102
|
+
.vdi-group__head p { margin: 1px 0 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
|
|
103
|
+
.vdi-group__body { margin-top: 8px; padding: 0 16px; border: .5px solid var(--dsw-alias-border-l1); border-radius: 12px; background: var(--dsw-alias-bg-layer-1); }
|
|
104
|
+
.vdi-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 13px 0; border-bottom: .5px solid var(--dsw-alias-border-l2); }
|
|
105
|
+
.vdi-row:last-child { border-bottom: 0; }
|
|
106
|
+
.vdi-row__text { min-width: 0; }
|
|
107
|
+
.vdi-row__label { font-size: 14px; line-height: 22px; }
|
|
108
|
+
.vdi-row__desc { margin-top: 1px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
|
|
109
|
+
.vdi-row__ctl { flex: none; display: flex; align-items: center; gap: 8px; }
|
|
110
|
+
.vdi-row--dim .vdi-row__label, .vdi-row--dim .vdi-row__ctl { opacity: .45; }
|
|
111
|
+
|
|
112
|
+
.vdi-sw { position: relative; width: 36px; height: 20px; flex: none; border: 0; border-radius: 999px; background: var(--dsw-alias-state-idle-primary); cursor: pointer; transition: background .15s; }
|
|
113
|
+
.vdi-sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
|
|
114
|
+
.vdi-sw[aria-checked="true"] { background: var(--dsw-alias-brand-primary); }
|
|
115
|
+
.vdi-sw[aria-checked="true"]::after { transform: translateX(16px); }
|
|
116
|
+
|
|
117
|
+
.vdi-seg { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--dsw-alias-bg-layer-2); }
|
|
118
|
+
.vdi-seg button { padding: 3px 12px; border: 0; border-radius: 7px; background: none; font: inherit; font-size: 13px; color: var(--dsw-alias-label-secondary); white-space: nowrap; cursor: pointer; }
|
|
119
|
+
.vdi-seg button[aria-checked="true"] { background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
|
|
120
|
+
|
|
121
|
+
.vdi-sel { min-width: 168px; padding: 4px 10px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 8px; background: var(--dsw-alias-bg-base); font: inherit; font-size: 13px; color: inherit; }
|
|
122
|
+
|
|
123
|
+
.vdi-range { display: flex; align-items: center; gap: 10px; }
|
|
124
|
+
.vdi-range input { width: 160px; accent-color: var(--dsw-alias-brand-primary); }
|
|
125
|
+
.vdi-range output { min-width: 62px; text-align: right; font-size: 13px; color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
|
|
126
|
+
|
|
127
|
+
.vdi-num { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dsw-alias-label-secondary); }
|
|
128
|
+
.vdi-num input { width: 76px; padding: 4px 8px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 8px; background: var(--dsw-alias-bg-base); font: inherit; font-size: 13px; color: var(--dsw-alias-label-primary); text-align: right; }
|
|
129
|
+
|
|
130
|
+
.vdi-keys { display: inline-flex; align-items: center; gap: 4px; }
|
|
131
|
+
.vdi-shortcut { display: inline-flex; align-items: center; gap: 8px; }
|
|
132
|
+
.vdi-shortcut__hint { font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
133
|
+
.vdi-keys kbd { min-width: 22px; padding: 1px 6px; border: .5px solid var(--dsw-alias-border-l2); border-bottom-width: 1.5px; border-radius: 6px; background: var(--dsw-alias-bg-base); font: inherit; font-size: 12px; text-align: center; }
|
|
134
|
+
.vdi-keys i { font-style: normal; font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
135
|
+
|
|
136
|
+
.vdi-path { display: flex; gap: 6px; }
|
|
137
|
+
.vdi-path input { width: 240px; padding: 4px 8px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 8px; background: var(--dsw-alias-bg-base); font: inherit; font-size: 13px; color: var(--dsw-alias-label-secondary); }
|
|
138
|
+
|
|
139
|
+
.vdi-color { display: flex; align-items: center; gap: 8px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; color: var(--dsw-alias-label-secondary); }
|
|
140
|
+
.vdi-color input { width: 26px; height: 26px; padding: 0; border: .5px solid var(--dsw-alias-border-l2); border-radius: 7px; background: none; cursor: pointer; }
|
|
141
|
+
|
|
142
|
+
.vdi-btn { padding: 4px 14px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 8px; background: var(--dsw-alias-bg-base); font: inherit; font-size: 13px; color: inherit; white-space: nowrap; cursor: pointer; }
|
|
143
|
+
.vdi-btn:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-2); }
|
|
144
|
+
.vdi-btn:disabled { opacity: .45; cursor: default; }
|
|
145
|
+
.vdi-btn--primary { background: var(--dsw-alias-brand-primary); border-color: transparent; color: #fff; }
|
|
146
|
+
.vdi-btn--danger { color: var(--dsw-alias-state-error-primary); }
|
|
147
|
+
|
|
148
|
+
.vdi-chip { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
|
|
149
|
+
.vdi-chip--ok { color: var(--dsw-alias-state-success-primary); background: color-mix(in srgb, var(--dsw-alias-state-success-primary) 13%, transparent); }
|
|
150
|
+
.vdi-chip--warn { color: var(--dsw-alias-state-warn-primary); background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 14%, transparent); }
|
|
151
|
+
.vdi-chip--idle { color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-bg-layer-2); }
|
|
152
|
+
.vdi-info { font-size: 13px; color: var(--dsw-alias-label-secondary); }
|
|
153
|
+
.vdi-error { margin-top: 10px; font-size: 12px; color: var(--dsw-alias-state-error-primary); }
|
|
154
|
+
|
|
155
|
+
.vdi-list { display: flex; flex-direction: column; }
|
|
156
|
+
.vdi-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: .5px solid var(--dsw-alias-border-l2); }
|
|
157
|
+
.vdi-item:last-child { border-bottom: 0; }
|
|
158
|
+
.vdi-item__main { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
|
159
|
+
.vdi-item__sub { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
|
|
160
|
+
.vdi-item__act { display: flex; align-items: center; gap: 6px; }
|
|
161
|
+
.vdi-rank { width: 20px; text-align: center; font-size: 12px; color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
|
|
162
|
+
.vdi-swatches { display: flex; flex: none; }
|
|
163
|
+
.vdi-swatches i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--dsw-alias-bg-layer-1); margin-left: -4px; }
|
|
164
|
+
.vdi-swatches i:first-child { margin-left: 0; }
|
|
165
|
+
.vdi-move { width: 26px; height: 24px; padding: 0; border: .5px solid var(--dsw-alias-border-l2); border-radius: 6px; background: var(--dsw-alias-bg-base); color: inherit; font: inherit; font-size: 12px; line-height: 1; cursor: pointer; }
|
|
166
|
+
.vdi-move:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-2); }
|
|
167
|
+
.vdi-move:disabled { opacity: .35; cursor: default; }
|
|
168
|
+
.vdi-item--off .vdi-item__main { opacity: .5; }
|
|
169
|
+
.vdi-grip { width: 14px; color: var(--dsw-alias-label-secondary); font-size: 12px; }
|
|
170
|
+
|
|
171
|
+
@media (max-width: 900px) {
|
|
172
|
+
.vdi { grid-template-columns: 1fr; }
|
|
173
|
+
.vdi__nav { flex-direction: row; flex-wrap: wrap; padding: 0 0 8px; }
|
|
174
|
+
.vdi__nav button { width: auto; }
|
|
175
|
+
.vdi__body { padding-left: 0; }
|
|
176
|
+
.vdi-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
177
|
+
}
|
|
178
|
+
@media (prefers-reduced-motion: reduce) { .vdi-sw, .vdi-sw::after { transition: none; } }
|
|
179
|
+
.vdi-log { display: flex; flex-direction: column; }
|
|
180
|
+
.vdi-log__release { padding: 12px 0; border-bottom: .5px solid var(--dsw-alias-border-l2); }
|
|
181
|
+
.vdi-log__release:first-child { padding-top: 4px; }
|
|
182
|
+
.vdi-log__release:last-child { border-bottom: 0; }
|
|
183
|
+
.vdi-log__head { display: flex; align-items: baseline; gap: 8px; font-size: 13px; cursor: pointer; }
|
|
184
|
+
.vdi-log__version { font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
185
|
+
.vdi-log__note { font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
186
|
+
.vdi-log__summary { margin: 8px 0 0; font-size: 13px; color: var(--dsw-alias-label-secondary); }
|
|
187
|
+
.vdi-log__group { margin: 10px 0 0; font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
188
|
+
.vdi-log__items { margin: 4px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.7; }
|
|
189
|
+
`
|
|
190
|
+
|
|
191
|
+
/* ---------------------------------------------------------------- 工具 */
|
|
192
|
+
|
|
193
|
+
const getAt = (target, path) =>
|
|
194
|
+
path.split('.').reduce((value, key) => (value === undefined || value === null ? undefined : value[key]), target)
|
|
195
|
+
function setAt(target, path, value) {
|
|
196
|
+
const next = JSON.parse(JSON.stringify(target ?? {}))
|
|
197
|
+
const keys = path.split('.')
|
|
198
|
+
const last = keys.pop()
|
|
199
|
+
let owner = next
|
|
200
|
+
for (const key of keys) {
|
|
201
|
+
if (owner[key] === null || typeof owner[key] !== 'object') owner[key] = {}
|
|
202
|
+
owner = owner[key]
|
|
203
|
+
}
|
|
204
|
+
owner[last] = value
|
|
205
|
+
return next
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function readJson(url, init) {
|
|
209
|
+
const response = await fetch(url, init)
|
|
210
|
+
const body = await response.json().catch(() => undefined)
|
|
211
|
+
if (!response.ok || body?.ok !== true) throw new Error(body?.error ?? `Request failed with ${response.status}`)
|
|
212
|
+
return body.data
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const postJson = (url, body) =>
|
|
216
|
+
readJson(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
|
|
217
|
+
|
|
218
|
+
/* -------------------------------------------------------------- 控件 */
|
|
219
|
+
|
|
220
|
+
function Toggle({ label, checked, onChange, disabled }) {
|
|
221
|
+
return h('button', {
|
|
222
|
+
className: 'vdi-sw',
|
|
223
|
+
role: 'switch',
|
|
224
|
+
type: 'button',
|
|
225
|
+
'aria-checked': checked ? 'true' : 'false',
|
|
226
|
+
'aria-label': label,
|
|
227
|
+
disabled: disabled === true,
|
|
228
|
+
onClick: () => onChange(!checked),
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function Segmented({ label, options, value, onChange }) {
|
|
233
|
+
return h(
|
|
234
|
+
'div',
|
|
235
|
+
{ className: 'vdi-seg', role: 'radiogroup', 'aria-label': label },
|
|
236
|
+
options.map((option) =>
|
|
237
|
+
h(
|
|
238
|
+
'button',
|
|
239
|
+
{
|
|
240
|
+
key: option,
|
|
241
|
+
type: 'button',
|
|
242
|
+
role: 'radio',
|
|
243
|
+
'aria-checked': option === value ? 'true' : 'false',
|
|
244
|
+
onClick: () => onChange(option),
|
|
245
|
+
},
|
|
246
|
+
option,
|
|
247
|
+
),
|
|
248
|
+
),
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function Select({ label, options, value, onChange }) {
|
|
253
|
+
return h(
|
|
254
|
+
'select',
|
|
255
|
+
{
|
|
256
|
+
className: 'vdi-sel',
|
|
257
|
+
'aria-label': label,
|
|
258
|
+
value,
|
|
259
|
+
onChange: (event) => onChange(event.target.value),
|
|
260
|
+
},
|
|
261
|
+
options.map((option) => h('option', { key: option, value: option }, option)),
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function Slider({ label, value, min, max, step, unit, onChange }) {
|
|
266
|
+
return h(
|
|
267
|
+
'div',
|
|
268
|
+
{ className: 'vdi-range' },
|
|
269
|
+
h('input', {
|
|
270
|
+
type: 'range',
|
|
271
|
+
min,
|
|
272
|
+
max,
|
|
273
|
+
step: step ?? 1,
|
|
274
|
+
value,
|
|
275
|
+
'aria-label': label,
|
|
276
|
+
onChange: (event) => onChange(Number(event.target.value)),
|
|
277
|
+
}),
|
|
278
|
+
h('output', null, `${value}${unit ?? ''}`),
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function NumberInput({ label, value, unit, min, max, onChange }) {
|
|
283
|
+
return h(
|
|
284
|
+
'div',
|
|
285
|
+
{ className: 'vdi-num' },
|
|
286
|
+
h('input', {
|
|
287
|
+
type: 'number',
|
|
288
|
+
value,
|
|
289
|
+
min,
|
|
290
|
+
max,
|
|
291
|
+
'aria-label': label,
|
|
292
|
+
onChange: (event) => {
|
|
293
|
+
const next = Number(event.target.value)
|
|
294
|
+
if (Number.isFinite(next)) onChange(next)
|
|
295
|
+
},
|
|
296
|
+
}),
|
|
297
|
+
unit === undefined ? null : h('span', null, unit),
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function ShortcutKeys({ value }) {
|
|
302
|
+
return h(
|
|
303
|
+
'div',
|
|
304
|
+
{ className: 'vdi-keys' },
|
|
305
|
+
value
|
|
306
|
+
.split('+')
|
|
307
|
+
.flatMap((key, index) =>
|
|
308
|
+
index === 0 ? [h('kbd', { key }, key)] : [h('i', { key: `sep${index}` }, '+'), h('kbd', { key }, key)],
|
|
309
|
+
),
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** 浏览器给的按键名换成存下来的写法。 */
|
|
314
|
+
const NAMED_KEYS = {
|
|
315
|
+
' ': 'Space',
|
|
316
|
+
ArrowUp: 'ArrowUp',
|
|
317
|
+
ArrowDown: 'ArrowDown',
|
|
318
|
+
ArrowLeft: 'ArrowLeft',
|
|
319
|
+
ArrowRight: 'ArrowRight',
|
|
320
|
+
Escape: 'Escape',
|
|
321
|
+
Enter: 'Enter',
|
|
322
|
+
Tab: 'Tab',
|
|
323
|
+
Backspace: 'Backspace',
|
|
324
|
+
Delete: 'Delete',
|
|
325
|
+
Home: 'Home',
|
|
326
|
+
End: 'End',
|
|
327
|
+
PageUp: 'PageUp',
|
|
328
|
+
PageDown: 'PageDown',
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function toShortcutPart(event) {
|
|
332
|
+
if (['Control', 'Shift', 'Alt', 'Meta'].includes(event.key)) return undefined
|
|
333
|
+
if (NAMED_KEYS[event.key] !== undefined) return NAMED_KEYS[event.key]
|
|
334
|
+
if (/^F([1-9]|1[0-2])$/.test(event.key)) return event.key
|
|
335
|
+
// 数字和字母用 code:按住 Shift 时 event.key 会变成符号(Shift+1 是 "!"),
|
|
336
|
+
// 用它判断会把这个组合整个丢掉。
|
|
337
|
+
const code = event.code ?? ''
|
|
338
|
+
if (/^Key[A-Z]$/.test(code)) return code.slice(3)
|
|
339
|
+
// 小键盘要和小键盘区分开:两者是同一个数字,但键码不同(0x61 vs 0x31),
|
|
340
|
+
// 而且按住 Shift 时小键盘会变成导航键,只能靠钩子接。
|
|
341
|
+
if (/^Numpad[0-9]$/.test(code)) return `Numpad${code.slice(6)}`
|
|
342
|
+
if (/^Digit[0-9]$/.test(code)) return code.slice(5)
|
|
343
|
+
if (/^[A-Za-z0-9]$/.test(event.key)) return event.key.toUpperCase()
|
|
344
|
+
return undefined
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* 可录制的快捷键:点「修改」后按下新组合。
|
|
349
|
+
* 必须带修饰键,否则会和普通打字抢;Esc 取消。
|
|
350
|
+
*/
|
|
351
|
+
function ShortcutField({ label, value, onChange, optional }) {
|
|
352
|
+
const [recording, setRecording] = React.useState(false)
|
|
353
|
+
|
|
354
|
+
// 录制期间挂起岛屿的截图热键,否则按下新组合会立刻触发一次截图。
|
|
355
|
+
React.useEffect(() => {
|
|
356
|
+
if (!recording) return
|
|
357
|
+
void postJson(CONTROL_URL, { action: 'suspend', suspended: true }).catch(() => undefined)
|
|
358
|
+
return () => {
|
|
359
|
+
void postJson(CONTROL_URL, { action: 'suspend', suspended: false }).catch(() => undefined)
|
|
360
|
+
}
|
|
361
|
+
}, [recording])
|
|
362
|
+
|
|
363
|
+
React.useEffect(() => {
|
|
364
|
+
if (!recording) return
|
|
365
|
+
const handler = (event) => {
|
|
366
|
+
event.preventDefault()
|
|
367
|
+
event.stopPropagation()
|
|
368
|
+
if (event.key === 'Escape') {
|
|
369
|
+
setRecording(false)
|
|
370
|
+
return
|
|
371
|
+
}
|
|
372
|
+
const part = toShortcutPart(event)
|
|
373
|
+
if (part === undefined) return
|
|
374
|
+
const modifiers = []
|
|
375
|
+
if (event.ctrlKey) modifiers.push('Ctrl')
|
|
376
|
+
if (event.shiftKey) modifiers.push('Shift')
|
|
377
|
+
if (event.altKey) modifiers.push('Alt')
|
|
378
|
+
if (event.metaKey) modifiers.push('Win')
|
|
379
|
+
if (modifiers.length === 0) return
|
|
380
|
+
setRecording(false)
|
|
381
|
+
onChange([...modifiers, part].join('+'))
|
|
382
|
+
}
|
|
383
|
+
window.addEventListener('keydown', handler, true)
|
|
384
|
+
return () => window.removeEventListener('keydown', handler, true)
|
|
385
|
+
}, [onChange, recording])
|
|
386
|
+
|
|
387
|
+
const empty = value === ''
|
|
388
|
+
return h(
|
|
389
|
+
'div',
|
|
390
|
+
{ className: 'vdi-shortcut' },
|
|
391
|
+
recording
|
|
392
|
+
? h('span', { className: 'vdi-shortcut__hint' }, '按下新的组合键,Esc 取消')
|
|
393
|
+
: empty
|
|
394
|
+
? h('span', { className: 'vdi-shortcut__hint' }, '未设置')
|
|
395
|
+
: h(ShortcutKeys, { value }),
|
|
396
|
+
h(
|
|
397
|
+
'button',
|
|
398
|
+
{
|
|
399
|
+
className: 'vdi-btn',
|
|
400
|
+
type: 'button',
|
|
401
|
+
'aria-label': `${label}:${empty ? '设置' : '修改'}`,
|
|
402
|
+
onClick: () => setRecording((current) => !current),
|
|
403
|
+
},
|
|
404
|
+
recording ? '取消' : empty ? '设置' : '修改',
|
|
405
|
+
),
|
|
406
|
+
// 可以不设的快捷键:设了之后能清掉,清掉就是不注册。
|
|
407
|
+
optional === true && !empty && !recording
|
|
408
|
+
? h(
|
|
409
|
+
'button',
|
|
410
|
+
{ className: 'vdi-btn', type: 'button', 'aria-label': `${label}:清除`, onClick: () => onChange('') },
|
|
411
|
+
'清除',
|
|
412
|
+
)
|
|
413
|
+
: null,
|
|
414
|
+
)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* 路径框。传了 onChange 就可编辑(失焦或回车时提交),否则只读。
|
|
419
|
+
* 可编辑的框在宿主能选文件夹时(`uiWorkspace.pickDirectory()`)多一个「选择…」按钮;
|
|
420
|
+
* 没有这个服务时仍然可以直接粘贴路径。
|
|
421
|
+
*/
|
|
422
|
+
function PathInput({ label, value, placeholder, onChange }) {
|
|
423
|
+
const [draft, setDraft] = React.useState(value)
|
|
424
|
+
const [picking, setPicking] = React.useState(false)
|
|
425
|
+
React.useEffect(() => {
|
|
426
|
+
setDraft(value)
|
|
427
|
+
}, [value])
|
|
428
|
+
const commit = () => {
|
|
429
|
+
const next = draft.trim()
|
|
430
|
+
if (onChange !== undefined && next !== value) onChange(next)
|
|
431
|
+
}
|
|
432
|
+
const pick = onChange === undefined ? undefined : directoryPicker()
|
|
433
|
+
const choose = async () => {
|
|
434
|
+
setPicking(true)
|
|
435
|
+
try {
|
|
436
|
+
const picked = await pick()
|
|
437
|
+
if (typeof picked === 'string' && picked.trim() !== '' && picked.trim() !== value) onChange(picked.trim())
|
|
438
|
+
} catch (cause) {
|
|
439
|
+
// 选择器出错不影响别的:路径还可以直接粘贴。
|
|
440
|
+
console.error('Picking a folder failed', cause)
|
|
441
|
+
} finally {
|
|
442
|
+
setPicking(false)
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return h(
|
|
446
|
+
'div',
|
|
447
|
+
{ className: 'vdi-path' },
|
|
448
|
+
h('input', {
|
|
449
|
+
type: 'text',
|
|
450
|
+
value: onChange === undefined ? value : draft,
|
|
451
|
+
readOnly: onChange === undefined,
|
|
452
|
+
placeholder,
|
|
453
|
+
'aria-label': label,
|
|
454
|
+
title: value,
|
|
455
|
+
onChange: (event) => setDraft(event.target.value),
|
|
456
|
+
onBlur: commit,
|
|
457
|
+
onKeyDown: (event) => {
|
|
458
|
+
if (event.key === 'Enter') event.currentTarget.blur()
|
|
459
|
+
},
|
|
460
|
+
}),
|
|
461
|
+
pick === undefined
|
|
462
|
+
? null
|
|
463
|
+
: h(
|
|
464
|
+
'button',
|
|
465
|
+
{
|
|
466
|
+
className: 'vdi-btn',
|
|
467
|
+
type: 'button',
|
|
468
|
+
disabled: picking,
|
|
469
|
+
'aria-label': `${label}:选择文件夹`,
|
|
470
|
+
onClick: () => void choose(),
|
|
471
|
+
},
|
|
472
|
+
'选择…',
|
|
473
|
+
),
|
|
474
|
+
)
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function ColorInput({ label, value, onChange }) {
|
|
478
|
+
return h(
|
|
479
|
+
'label',
|
|
480
|
+
{ className: 'vdi-color' },
|
|
481
|
+
h('input', { type: 'color', value, 'aria-label': label, onChange: (event) => onChange(event.target.value) }),
|
|
482
|
+
h('span', null, String(value).toUpperCase()),
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function Row({ label, desc, children, dim }) {
|
|
487
|
+
return h(
|
|
488
|
+
'div',
|
|
489
|
+
{ className: `vdi-row${dim === true ? ' vdi-row--dim' : ''}` },
|
|
490
|
+
h(
|
|
491
|
+
'div',
|
|
492
|
+
{ className: 'vdi-row__text' },
|
|
493
|
+
h('div', { className: 'vdi-row__label' }, label),
|
|
494
|
+
desc === undefined ? null : h('div', { className: 'vdi-row__desc' }, desc),
|
|
495
|
+
),
|
|
496
|
+
h('div', { className: 'vdi-row__ctl' }, children),
|
|
497
|
+
)
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function Group({ title, desc, children }) {
|
|
501
|
+
return h(
|
|
502
|
+
'section',
|
|
503
|
+
{ className: 'vdi-group' },
|
|
504
|
+
h(
|
|
505
|
+
'div',
|
|
506
|
+
{ className: 'vdi-group__head' },
|
|
507
|
+
h('h3', null, title),
|
|
508
|
+
desc === undefined ? null : h('p', null, desc),
|
|
509
|
+
),
|
|
510
|
+
h('div', { className: 'vdi-group__body' }, children),
|
|
511
|
+
)
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/* --------------------------------------------------------- 设置页 */
|
|
515
|
+
|
|
516
|
+
const SECTIONS = [
|
|
517
|
+
{ id: 'overview', title: '概览', icon: 'gauge' },
|
|
518
|
+
{ id: 'appearance', title: '外观', icon: 'palette' },
|
|
519
|
+
{ id: 'behavior', title: '行为', icon: 'cursor' },
|
|
520
|
+
{ id: 'pages', title: '岛上页面', icon: 'layers' },
|
|
521
|
+
{ id: 'sessions', title: 'VibeDev 会话', icon: 'chat' },
|
|
522
|
+
{ id: 'todos', title: '待办', icon: 'list' },
|
|
523
|
+
{ id: 'clipboard', title: '剪贴板', icon: 'clipboard' },
|
|
524
|
+
{ id: 'screenshot', title: '截图', icon: 'crop' },
|
|
525
|
+
{ id: 'messages', title: '消息', icon: 'mail' },
|
|
526
|
+
{ id: 'translation', title: '翻译', icon: 'translate' },
|
|
527
|
+
{ id: 'about', title: '关于', icon: 'info' },
|
|
528
|
+
]
|
|
529
|
+
|
|
530
|
+
/** 子导航图标,16px 描边;自绘,不依赖图标库。 */
|
|
531
|
+
const ICON_PATHS = {
|
|
532
|
+
gauge: ['M12 20a8 8 0 1 1 8-8', 'M12 12l4-3', 'M4 12a8 8 0 0 1 8-8'],
|
|
533
|
+
palette: [
|
|
534
|
+
'M12 20a8 8 0 1 1 8-8c0 2-1.5 3-3 3h-2a2 2 0 0 0-1 3.7c.4.7 0 1.3-2 1.3Z',
|
|
535
|
+
'M9 10h.01',
|
|
536
|
+
'M14 8h.01',
|
|
537
|
+
'M16 12h.01',
|
|
538
|
+
],
|
|
539
|
+
cursor: ['M6 4l12 7-5 1.4L10.6 18z'],
|
|
540
|
+
layers: ['M12 4l8 4-8 4-8-4z', 'M4 12l8 4 8-4', 'M4 16l8 4 8-4'],
|
|
541
|
+
chat: ['M5 6h14v9H10l-4 3v-3H5z', 'M9 10.5h6'],
|
|
542
|
+
puzzle: ['M9 4h3v2a1.5 1.5 0 1 0 3 0V4h3v4h2a1.5 1.5 0 1 1 0 3h-2v9H4v-9h2a1.5 1.5 0 1 1 0-3H9z'],
|
|
543
|
+
list: ['M5 7l2 2 3-3', 'M12 8h7', 'M5 15l2 2 3-3', 'M12 16h7'],
|
|
544
|
+
clipboard: ['M6 5h12v15H6z', 'M9.5 5V4h5v1', 'M9 11h6', 'M9 15h4'],
|
|
545
|
+
crop: ['M7 3v14h14', 'M3 7h14v14'],
|
|
546
|
+
inbox: ['M4 13l2-7h12l2 7v5H4z', 'M4 13h5l1 2h4l1-2h5'],
|
|
547
|
+
mail: ['M4 6h16v12H4z', 'M4 8l8 5 8-5'],
|
|
548
|
+
translate: ['M4 6h9', 'M8.5 4v2', 'M6 6c1 4 4 6 6 7', 'M11 6c-1 4-4 7-6 8', 'M13 20l4-9 4 9', 'M14.5 17h5'],
|
|
549
|
+
info: ['M12 20a8 8 0 1 0 0-16 8 8 0 0 0 0 16Z', 'M12 11v5', 'M12 8h.01'],
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function Icon({ name }) {
|
|
553
|
+
const paths = ICON_PATHS[name] ?? []
|
|
554
|
+
return h(
|
|
555
|
+
'svg',
|
|
556
|
+
{
|
|
557
|
+
viewBox: '0 0 24 24',
|
|
558
|
+
width: 16,
|
|
559
|
+
height: 16,
|
|
560
|
+
'aria-hidden': 'true',
|
|
561
|
+
fill: 'none',
|
|
562
|
+
stroke: 'currentColor',
|
|
563
|
+
strokeWidth: 1.6,
|
|
564
|
+
strokeLinecap: 'round',
|
|
565
|
+
strokeLinejoin: 'round',
|
|
566
|
+
},
|
|
567
|
+
paths.map((d, index) => h('path', { key: index, d })),
|
|
568
|
+
)
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/** 新消息怎么出现。 */
|
|
572
|
+
const NOTICE_CHOICES = ['line', 'banner', 'panel']
|
|
573
|
+
const NOTICE_LABELS = { line: '一行', banner: '横幅', panel: '面板' }
|
|
574
|
+
|
|
575
|
+
/** 翻译通道:自动,或者宿主的两个不需要会话的通道。 */
|
|
576
|
+
const TRANSLATION_CHOICES = ['auto', 'google', 'bing']
|
|
577
|
+
const TRANSLATION_LABELS = { auto: '自动选择', google: 'Google', bing: '必应' }
|
|
578
|
+
|
|
579
|
+
/** 「测试一下」下面的那句话:上一次测试的结果,如实显示。 */
|
|
580
|
+
function translationTestNote(test) {
|
|
581
|
+
if (test === undefined || test === null) return '用上面选的通道把一句英文翻成中文,看这条路通不通。'
|
|
582
|
+
const chosen = TRANSLATION_LABELS[test.provider] ?? TRANSLATION_LABELS.auto
|
|
583
|
+
// 选的是「自动」时,说清楚宿主实际挑了谁。
|
|
584
|
+
const actual = test.via === test.provider ? undefined : TRANSLATION_LABELS[test.via]
|
|
585
|
+
const route = actual === undefined ? chosen : `${chosen},实际用的是${actual}`
|
|
586
|
+
return test.ok === true ? `通了(${route},${test.ms} 毫秒):${test.text}` : `没通(${chosen}):${test.error}`
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** 岛屿页头那一排按钮对应的页面;消息页的入口是右上角的铃铛,不在这一排。 */
|
|
590
|
+
const TAB_PAGES = ['vibedev', 'todo', 'music', 'clipboard']
|
|
591
|
+
const MESSAGES_PAGE = 'qq'
|
|
592
|
+
const PAGE_LABELS = { vibedev: 'VibeDev 会话', todo: '待办', music: '音乐', clipboard: '剪贴板', qq: '消息' }
|
|
593
|
+
|
|
594
|
+
/** 把 `id` 这一页往前(step = -1)或往后(step = 1)挪一格;挪不动就原样返回。 */
|
|
595
|
+
function movePage(order, id, step) {
|
|
596
|
+
const from = order.indexOf(id)
|
|
597
|
+
const to = from + step
|
|
598
|
+
if (from < 0 || to < 0 || to >= order.length) return order
|
|
599
|
+
const next = order.slice()
|
|
600
|
+
next[from] = order[to]
|
|
601
|
+
next[to] = id
|
|
602
|
+
return next
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** 隐藏列表里加上或去掉 `id`。 */
|
|
606
|
+
function setPageShown(hidden, id, visible) {
|
|
607
|
+
const rest = hidden.filter((item) => item !== id)
|
|
608
|
+
return visible ? rest : [...rest, id]
|
|
609
|
+
}
|
|
610
|
+
/** 岛屿回报的 QQ 通知状态 → 概览里的一个小标签:[文字, 色调]。 */
|
|
611
|
+
const QQ_CHIPS = {
|
|
612
|
+
listening: ['正常', 'ok'],
|
|
613
|
+
waiting: ['等待消息', 'ok'],
|
|
614
|
+
disabled: ['已关闭', 'idle'],
|
|
615
|
+
permissionRequired: ['需要授权', 'warn'],
|
|
616
|
+
permissionDenied: ['被拒绝', 'warn'],
|
|
617
|
+
error: ['出错', 'warn'],
|
|
618
|
+
}
|
|
619
|
+
const NO_CHIP = ['—', 'idle']
|
|
620
|
+
const qqChip = (state) => QQ_CHIPS[state] ?? NO_CHIP
|
|
621
|
+
/** QQ 邮箱的状态 → 状态行上的一句话和色调。 */
|
|
622
|
+
const mailChip = (mail) => {
|
|
623
|
+
if (mail === undefined || mail === null) return NO_CHIP
|
|
624
|
+
if (mail.configured !== true) return ['没设置', 'idle']
|
|
625
|
+
if (mail.enabled !== true) return ['已关闭', 'idle']
|
|
626
|
+
if (typeof mail.error === 'string' && mail.error !== '') return ['出错', 'warn']
|
|
627
|
+
if (mail.status === 'connected') {
|
|
628
|
+
return [typeof mail.unreadCount === 'number' ? `已连接 · 未读 ${mail.unreadCount}` : '已连接', 'ok']
|
|
629
|
+
}
|
|
630
|
+
const words = {
|
|
631
|
+
connecting: '正在连接',
|
|
632
|
+
disconnected: '没连上',
|
|
633
|
+
paused: '暂停了',
|
|
634
|
+
authRequired: '需要重新授权',
|
|
635
|
+
error: '出错',
|
|
636
|
+
}
|
|
637
|
+
return [words[mail.status] ?? '未知', 'warn']
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* 岛屿的运行状态。设置页、页头的状态标签和页头的操作按钮都要看它,共用一份轮询:
|
|
642
|
+
* 有人在看时(`retain`)才读,都不看了就停。
|
|
643
|
+
*/
|
|
644
|
+
function createStatusStore() {
|
|
645
|
+
let snapshot
|
|
646
|
+
let watchers = 0
|
|
647
|
+
let timer
|
|
648
|
+
const listeners = new Set()
|
|
649
|
+
const publish = (next) => {
|
|
650
|
+
snapshot = next
|
|
651
|
+
for (const listener of listeners) listener()
|
|
652
|
+
}
|
|
653
|
+
// 读失败就留着旧的:出错的提示由设置页自己那次读取给出。
|
|
654
|
+
const refresh = () => readJson(STATUS_URL).then(publish, () => undefined)
|
|
655
|
+
return {
|
|
656
|
+
get: () => snapshot,
|
|
657
|
+
set: publish,
|
|
658
|
+
subscribe(listener) {
|
|
659
|
+
listeners.add(listener)
|
|
660
|
+
return () => listeners.delete(listener)
|
|
661
|
+
},
|
|
662
|
+
retain() {
|
|
663
|
+
watchers += 1
|
|
664
|
+
if (watchers === 1) {
|
|
665
|
+
void refresh()
|
|
666
|
+
timer = setInterval(refresh, STATUS_POLL_MS)
|
|
667
|
+
}
|
|
668
|
+
return () => {
|
|
669
|
+
watchers -= 1
|
|
670
|
+
if (watchers === 0) clearInterval(timer)
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const statusStore = createStatusStore()
|
|
677
|
+
|
|
678
|
+
/** 当前的运行状态,变了会重新渲染。第一次读到之前用 `initial`(测试靠它渲染指定状态)。 */
|
|
679
|
+
function useIslandStatus(initial) {
|
|
680
|
+
React.useEffect(() => statusStore.retain(), [])
|
|
681
|
+
return React.useSyncExternalStore(statusStore.subscribe, statusStore.get, statusStore.get) ?? initial
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* 页头用的样式。页头在设置页的组件树外面,不能指望设置页那份 <style> 已经渲染出来。
|
|
686
|
+
*/
|
|
687
|
+
const HEADER_CSS = `
|
|
688
|
+
.vdi-head-chip { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
|
|
689
|
+
.vdi-head-chip--ok { color: var(--dsw-alias-state-success-primary); background: color-mix(in srgb, var(--dsw-alias-state-success-primary) 13%, transparent); }
|
|
690
|
+
.vdi-head-chip--warn { color: var(--dsw-alias-state-warn-primary); background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 14%, transparent); }
|
|
691
|
+
.vdi-head-chip--idle { color: var(--dsw-alias-label-secondary); background: var(--dsw-alias-bg-layer-2); }
|
|
692
|
+
.vdi-head-btn { padding: 4px 12px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 8px; background: var(--dsw-alias-bg-base); font: inherit; font-size: 13px; color: inherit; white-space: nowrap; cursor: pointer; }
|
|
693
|
+
.vdi-head-btn:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-2); }
|
|
694
|
+
.vdi-head-btn:disabled { opacity: .45; cursor: default; }
|
|
695
|
+
.vdi-head-btn--primary { background: var(--dsw-alias-brand-primary); border-color: transparent; color: #fff; }
|
|
696
|
+
`
|
|
697
|
+
|
|
698
|
+
/** 详情页是不是这个插件自己的那一页。别的插件的页面上什么都不画。 */
|
|
699
|
+
const isOwnPage = (subject) => subject?.kind === 'bundle' && subject.pkg?.name === PACKAGE_NAME
|
|
700
|
+
|
|
701
|
+
/** 运行状态 → 页头标签的 [文字, 色调]。 */
|
|
702
|
+
function headerState(status) {
|
|
703
|
+
if (status?.configured === false) return ['未找到程序', 'warn']
|
|
704
|
+
return status?.running === true ? ['运行中', 'ok'] : ['已停止', 'idle']
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function OwnHeaderBadge(props) {
|
|
708
|
+
const status = useIslandStatus(props.initialStatus)
|
|
709
|
+
if (status === undefined) return null
|
|
710
|
+
const [text, tone] = headerState(status)
|
|
711
|
+
return h(
|
|
712
|
+
React.Fragment,
|
|
713
|
+
null,
|
|
714
|
+
h('style', null, HEADER_CSS),
|
|
715
|
+
h('span', { className: `vdi-head-chip vdi-head-chip--${tone}` }, text),
|
|
716
|
+
)
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/** 页头标题旁的状态标签(`plugins.detail.badge`)。 */
|
|
720
|
+
function HeaderBadge(props) {
|
|
721
|
+
return isOwnPage(props?.subject) ? h(OwnHeaderBadge, { initialStatus: props.initialStatus }) : null
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
function OwnHeaderActions(props) {
|
|
725
|
+
const status = useIslandStatus(props.initialStatus)
|
|
726
|
+
const [busy, setBusy] = React.useState(false)
|
|
727
|
+
const [failure, setFailure] = React.useState(undefined)
|
|
728
|
+
const run = async (action) => {
|
|
729
|
+
setBusy(true)
|
|
730
|
+
try {
|
|
731
|
+
statusStore.set(await postJson(CONTROL_URL, { action }))
|
|
732
|
+
setFailure(undefined)
|
|
733
|
+
} catch (cause) {
|
|
734
|
+
setFailure(String(cause?.message ?? cause))
|
|
735
|
+
} finally {
|
|
736
|
+
setBusy(false)
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (status === undefined) return null
|
|
740
|
+
const running = status.running === true
|
|
741
|
+
return h(
|
|
742
|
+
React.Fragment,
|
|
743
|
+
null,
|
|
744
|
+
h('style', null, HEADER_CSS),
|
|
745
|
+
running
|
|
746
|
+
? h(
|
|
747
|
+
'button',
|
|
748
|
+
{
|
|
749
|
+
className: 'vdi-head-btn',
|
|
750
|
+
type: 'button',
|
|
751
|
+
disabled: busy,
|
|
752
|
+
title: failure,
|
|
753
|
+
onClick: () => void run('restart'),
|
|
754
|
+
},
|
|
755
|
+
failure === undefined ? '重启小岛' : '没重启成,再试一次',
|
|
756
|
+
)
|
|
757
|
+
: h(
|
|
758
|
+
'button',
|
|
759
|
+
{
|
|
760
|
+
className: 'vdi-head-btn vdi-head-btn--primary',
|
|
761
|
+
type: 'button',
|
|
762
|
+
disabled: busy || status.configured === false,
|
|
763
|
+
title: failure,
|
|
764
|
+
onClick: () => void run('start'),
|
|
765
|
+
},
|
|
766
|
+
failure === undefined ? '启动小岛' : '没启动成,再试一次',
|
|
767
|
+
),
|
|
768
|
+
)
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/** 页头的操作按钮(`plugins.detail.actions`):在哪个分区都能重启或启动小岛。 */
|
|
772
|
+
function HeaderActions(props) {
|
|
773
|
+
return isOwnPage(props?.subject) ? h(OwnHeaderActions, { initialStatus: props.initialStatus }) : null
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/** 「关于」里的更新记录:最新一版展开,旧的收起。内容来自 `CHANGELOG.md`。 */
|
|
777
|
+
/** 第三方许可:岛屿用到的 Rust 和前端依赖(`native/scripts/third-party.mjs` 生成的清单)。 */
|
|
778
|
+
function ThirdParty() {
|
|
779
|
+
const [list, setList] = React.useState(undefined)
|
|
780
|
+
const [failure, setFailure] = React.useState(undefined)
|
|
781
|
+
React.useEffect(() => {
|
|
782
|
+
let alive = true
|
|
783
|
+
readJson(LICENSES_URL).then(
|
|
784
|
+
(next) => alive && setList(next),
|
|
785
|
+
(cause) => alive && setFailure(String(cause?.message ?? cause)),
|
|
786
|
+
)
|
|
787
|
+
return () => {
|
|
788
|
+
alive = false
|
|
789
|
+
}
|
|
790
|
+
}, [])
|
|
791
|
+
if (failure !== undefined) return h('div', { className: 'vdi-info' }, `读不到第三方清单:${failure}`)
|
|
792
|
+
if (list === undefined) return h('div', { className: 'vdi-info' }, '读取中…')
|
|
793
|
+
const all = [...(list.rust ?? NO_EVENTS), ...(list.web ?? NO_EVENTS)]
|
|
794
|
+
const counts = new Map()
|
|
795
|
+
for (const item of all) counts.set(item.license, (counts.get(item.license) ?? 0) + 1)
|
|
796
|
+
const summary = Array.from(counts)
|
|
797
|
+
.sort((left, right) => right[1] - left[1])
|
|
798
|
+
.slice(0, 5)
|
|
799
|
+
.map(([license, count]) => `${license}(${count})`)
|
|
800
|
+
.join('、')
|
|
801
|
+
return h(
|
|
802
|
+
'details',
|
|
803
|
+
{ className: 'vdi-licenses' },
|
|
804
|
+
h(
|
|
805
|
+
'summary',
|
|
806
|
+
null,
|
|
807
|
+
`Rust 依赖 ${list.rust?.length ?? 0} 个、前端依赖 ${list.web?.length ?? 0} 个;最多的许可:${summary}。展开看全部`,
|
|
808
|
+
),
|
|
809
|
+
h(
|
|
810
|
+
'ul',
|
|
811
|
+
null,
|
|
812
|
+
all.map((item) =>
|
|
813
|
+
h('li', { key: `${item.name}@${item.version}` }, `${item.name} ${item.version} — ${item.license}`),
|
|
814
|
+
),
|
|
815
|
+
),
|
|
816
|
+
)
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function Changelog(props) {
|
|
820
|
+
const [releases, setReleases] = React.useState(props.initial)
|
|
821
|
+
const [failure, setFailure] = React.useState(undefined)
|
|
822
|
+
React.useEffect(() => {
|
|
823
|
+
if (props.initial !== undefined) return undefined
|
|
824
|
+
let alive = true
|
|
825
|
+
readJson(CHANGELOG_URL).then(
|
|
826
|
+
(next) => alive && setReleases(Array.isArray(next) ? next : NO_EVENTS),
|
|
827
|
+
(cause) => alive && setFailure(String(cause?.message ?? cause)),
|
|
828
|
+
)
|
|
829
|
+
return () => {
|
|
830
|
+
alive = false
|
|
831
|
+
}
|
|
832
|
+
}, [props.initial])
|
|
833
|
+
|
|
834
|
+
if (failure !== undefined) return h('div', { className: 'vdi-info' }, `读不到更新记录:${failure}`)
|
|
835
|
+
if (releases === undefined) return h('div', { className: 'vdi-info' }, '读取中…')
|
|
836
|
+
if (releases.length === 0) return h('div', { className: 'vdi-info' }, '还没有更新记录')
|
|
837
|
+
return h(
|
|
838
|
+
'div',
|
|
839
|
+
{ className: 'vdi-log' },
|
|
840
|
+
releases.map((release, index) =>
|
|
841
|
+
h(
|
|
842
|
+
'details',
|
|
843
|
+
{ className: 'vdi-log__release', key: release.version, open: index === 0 },
|
|
844
|
+
h(
|
|
845
|
+
'summary',
|
|
846
|
+
{ className: 'vdi-log__head' },
|
|
847
|
+
h('span', { className: 'vdi-log__version' }, release.version),
|
|
848
|
+
release.note === '' ? null : h('span', { className: 'vdi-log__note' }, release.note),
|
|
849
|
+
),
|
|
850
|
+
release.summary === '' ? null : h('p', { className: 'vdi-log__summary' }, release.summary),
|
|
851
|
+
release.groups.map((group, at) =>
|
|
852
|
+
h(
|
|
853
|
+
React.Fragment,
|
|
854
|
+
{ key: `${group.title}-${at}` },
|
|
855
|
+
group.title === '' ? null : h('div', { className: 'vdi-log__group' }, group.title),
|
|
856
|
+
h(
|
|
857
|
+
'ul',
|
|
858
|
+
{ className: 'vdi-log__items' },
|
|
859
|
+
group.items.map((item) => h('li', { key: item }, item)),
|
|
860
|
+
),
|
|
861
|
+
),
|
|
862
|
+
),
|
|
863
|
+
),
|
|
864
|
+
),
|
|
865
|
+
)
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/** 点第二下才执行的按钮,给收不回来的操作用。几秒内没点第二下就回到原样。 */
|
|
869
|
+
function ConfirmButton({ label, confirmLabel, disabled, onConfirm }) {
|
|
870
|
+
const [armed, setArmed] = React.useState(false)
|
|
871
|
+
React.useEffect(() => {
|
|
872
|
+
if (!armed) return undefined
|
|
873
|
+
const timer = setTimeout(() => setArmed(false), 4000)
|
|
874
|
+
return () => clearTimeout(timer)
|
|
875
|
+
}, [armed])
|
|
876
|
+
return h(
|
|
877
|
+
'button',
|
|
878
|
+
{
|
|
879
|
+
className: `vdi-btn${armed ? ' vdi-btn--danger' : ''}`,
|
|
880
|
+
type: 'button',
|
|
881
|
+
disabled,
|
|
882
|
+
onClick: () => {
|
|
883
|
+
if (!armed) {
|
|
884
|
+
setArmed(true)
|
|
885
|
+
return
|
|
886
|
+
}
|
|
887
|
+
setArmed(false)
|
|
888
|
+
onConfirm()
|
|
889
|
+
},
|
|
890
|
+
},
|
|
891
|
+
armed ? confirmLabel : label,
|
|
892
|
+
)
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function IslandSettingsPage(props) {
|
|
896
|
+
const [section, setSection] = React.useState(props?.initialSection ?? 'overview')
|
|
897
|
+
const status = useIslandStatus(props?.initialStatus)
|
|
898
|
+
const [settings, setSettings] = React.useState(props?.initialSettings)
|
|
899
|
+
const [error, setError] = React.useState(undefined)
|
|
900
|
+
const [busy, setBusy] = React.useState(false)
|
|
901
|
+
|
|
902
|
+
React.useEffect(() => {
|
|
903
|
+
let alive = true
|
|
904
|
+
const refresh = async () => {
|
|
905
|
+
try {
|
|
906
|
+
const nextSettings = await readJson(SETTINGS_URL)
|
|
907
|
+
if (!alive) return
|
|
908
|
+
setSettings(nextSettings)
|
|
909
|
+
setError(undefined)
|
|
910
|
+
} catch (cause) {
|
|
911
|
+
if (alive) setError(String(cause?.message ?? cause))
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
void refresh()
|
|
915
|
+
const timer = setInterval(refresh, 5000)
|
|
916
|
+
return () => {
|
|
917
|
+
alive = false
|
|
918
|
+
clearInterval(timer)
|
|
919
|
+
}
|
|
920
|
+
}, [])
|
|
921
|
+
|
|
922
|
+
const save = React.useCallback(async (next) => {
|
|
923
|
+
setSettings(next)
|
|
924
|
+
try {
|
|
925
|
+
setSettings(await postJson(SETTINGS_URL, next))
|
|
926
|
+
setError(undefined)
|
|
927
|
+
} catch (cause) {
|
|
928
|
+
setError(String(cause?.message ?? cause))
|
|
929
|
+
}
|
|
930
|
+
}, [])
|
|
931
|
+
|
|
932
|
+
const update = React.useCallback(
|
|
933
|
+
(path, value) => {
|
|
934
|
+
if (settings === undefined) return
|
|
935
|
+
void save(setAt(settings, path, value))
|
|
936
|
+
},
|
|
937
|
+
[save, settings],
|
|
938
|
+
)
|
|
939
|
+
|
|
940
|
+
const control = React.useCallback(async (action) => {
|
|
941
|
+
setBusy(true)
|
|
942
|
+
try {
|
|
943
|
+
statusStore.set(await postJson(CONTROL_URL, { action }))
|
|
944
|
+
setError(undefined)
|
|
945
|
+
} catch (cause) {
|
|
946
|
+
setError(String(cause?.message ?? cause))
|
|
947
|
+
} finally {
|
|
948
|
+
setBusy(false)
|
|
949
|
+
}
|
|
950
|
+
}, [])
|
|
951
|
+
|
|
952
|
+
// 恢复默认设置:宿主改完之后马上把新的设置读回来,不等下一次轮询。
|
|
953
|
+
const resetSettings = React.useCallback(async () => {
|
|
954
|
+
await control('reset-settings')
|
|
955
|
+
try {
|
|
956
|
+
setSettings(await readJson(SETTINGS_URL))
|
|
957
|
+
} catch (cause) {
|
|
958
|
+
setError(String(cause?.message ?? cause))
|
|
959
|
+
}
|
|
960
|
+
}, [control])
|
|
961
|
+
|
|
962
|
+
// 插件列表里只渲染一行摘要。放在所有 hook 之后:hook 的调用顺序不能随视图变。
|
|
963
|
+
if (props?.view === 'summary') {
|
|
964
|
+
const running = status?.running === true
|
|
965
|
+
return h('span', { className: 'vdi-status__meta' }, running ? '岛屿运行中' : '岛屿已停止')
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
const value = (path, fallback) => {
|
|
969
|
+
const found = getAt(settings, path)
|
|
970
|
+
return found === undefined ? fallback : found
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/** 岛屿回报的快捷键注册失败原因;成功或还没回报时是 undefined。 */
|
|
974
|
+
const shortcutNote = (key) => {
|
|
975
|
+
const entry = status?.shortcuts?.[key]
|
|
976
|
+
if (entry === undefined || entry.ok !== false) return undefined
|
|
977
|
+
return `⚠ 注册失败:${entry.error ?? '被占用'}`
|
|
978
|
+
}
|
|
979
|
+
const withNote = (...parts) => parts.filter((part) => part !== undefined && part !== '').join(' · ')
|
|
980
|
+
|
|
981
|
+
const PRESET_FIELDS = [
|
|
982
|
+
'taskTextColor',
|
|
983
|
+
'accentColor',
|
|
984
|
+
'islandBackgroundColor',
|
|
985
|
+
'todoPaperColor',
|
|
986
|
+
'accentBrightness',
|
|
987
|
+
]
|
|
988
|
+
const rawPresets = value('appearance.presets', [])
|
|
989
|
+
const presets = Array.isArray(rawPresets) ? rawPresets : []
|
|
990
|
+
|
|
991
|
+
const savePreset = async () => {
|
|
992
|
+
const suggested = `样式预设 ${presets.length + 1}`
|
|
993
|
+
const name = window.prompt('样式预设名称', suggested)
|
|
994
|
+
if (name === null) return
|
|
995
|
+
const draft = { id: `preset-${Date.now()}`, name: name.trim() === '' ? suggested : name.trim() }
|
|
996
|
+
for (const field of PRESET_FIELDS) draft[field] = getAt(settings, `appearance.${field}`)
|
|
997
|
+
await save(setAt(settings, 'appearance.presets', [...presets, draft]))
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
const applyPreset = async (preset) => {
|
|
1001
|
+
let next = settings
|
|
1002
|
+
for (const field of PRESET_FIELDS) {
|
|
1003
|
+
if (preset[field] !== undefined) next = setAt(next, `appearance.${field}`, preset[field])
|
|
1004
|
+
}
|
|
1005
|
+
await save(next)
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
const renamePreset = async (preset) => {
|
|
1009
|
+
const name = window.prompt('重命名样式预设', preset.name)
|
|
1010
|
+
if (name === null || name.trim() === '') return
|
|
1011
|
+
await save(
|
|
1012
|
+
setAt(
|
|
1013
|
+
settings,
|
|
1014
|
+
'appearance.presets',
|
|
1015
|
+
presets.map((item) => (item.id === preset.id ? { ...item, name: name.trim() } : item)),
|
|
1016
|
+
),
|
|
1017
|
+
)
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
const removePreset = async (preset) => {
|
|
1021
|
+
await save(
|
|
1022
|
+
setAt(
|
|
1023
|
+
settings,
|
|
1024
|
+
'appearance.presets',
|
|
1025
|
+
presets.filter((item) => item.id !== preset.id),
|
|
1026
|
+
),
|
|
1027
|
+
)
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
const running = status?.running === true
|
|
1031
|
+
const ready = settings !== undefined
|
|
1032
|
+
|
|
1033
|
+
const uptime = () => {
|
|
1034
|
+
if (!running || status?.startedAt === undefined) return '—'
|
|
1035
|
+
const elapsed = Date.now() - new Date(status.startedAt).getTime()
|
|
1036
|
+
if (!Number.isFinite(elapsed) || elapsed < 0) return '—'
|
|
1037
|
+
const minutes = Math.floor(elapsed / 60000)
|
|
1038
|
+
if (minutes < 60) return `${minutes} 分钟`
|
|
1039
|
+
return `${Math.floor(minutes / 60)} 小时 ${minutes % 60} 分`
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// 插件此刻送到小岛上的:只说数目,不写会话标题(设置页可能被别人看到)。小岛自己的待办、音乐、消息插件不知道。
|
|
1043
|
+
const surface = (() => {
|
|
1044
|
+
const sent = status?.surface
|
|
1045
|
+
if (!running) return '—'
|
|
1046
|
+
if (sent?.state === 'approval') return `${sent.approvals} 项等你批准`
|
|
1047
|
+
if (sent?.state === 'running') return `${sent.running} 个会话在运行`
|
|
1048
|
+
return '空闲'
|
|
1049
|
+
})()
|
|
1050
|
+
|
|
1051
|
+
const overview = () => [
|
|
1052
|
+
h(
|
|
1053
|
+
'div',
|
|
1054
|
+
{ className: 'vdi-ov', key: 'ov' },
|
|
1055
|
+
h(
|
|
1056
|
+
'div',
|
|
1057
|
+
{ className: 'vdi-ov__card' },
|
|
1058
|
+
h(
|
|
1059
|
+
'div',
|
|
1060
|
+
{ className: 'vdi-status' },
|
|
1061
|
+
h('span', {
|
|
1062
|
+
className: `vdi-dot${running ? ' vdi-dot--ok' : status?.configured === false ? ' vdi-dot--bad' : ''}`,
|
|
1063
|
+
}),
|
|
1064
|
+
h('span', { className: 'vdi-status__text' }, running ? '运行中' : '已停止'),
|
|
1065
|
+
),
|
|
1066
|
+
h(
|
|
1067
|
+
'dl',
|
|
1068
|
+
{ className: 'vdi-facts' },
|
|
1069
|
+
fact('版本', status?.version ?? '—'),
|
|
1070
|
+
fact('通信', '标准输入输出'),
|
|
1071
|
+
fact('已运行', uptime()),
|
|
1072
|
+
fact('小岛上', surface),
|
|
1073
|
+
),
|
|
1074
|
+
h(
|
|
1075
|
+
'div',
|
|
1076
|
+
{ className: 'vdi-status__actions', style: { marginTop: 14 } },
|
|
1077
|
+
running
|
|
1078
|
+
? h(
|
|
1079
|
+
'button',
|
|
1080
|
+
{ className: 'vdi-btn', type: 'button', disabled: busy, onClick: () => void control('stop') },
|
|
1081
|
+
'停止',
|
|
1082
|
+
)
|
|
1083
|
+
: h(
|
|
1084
|
+
'button',
|
|
1085
|
+
{
|
|
1086
|
+
className: 'vdi-btn vdi-btn--primary',
|
|
1087
|
+
type: 'button',
|
|
1088
|
+
disabled: busy || status?.configured === false,
|
|
1089
|
+
onClick: () => void control('start'),
|
|
1090
|
+
},
|
|
1091
|
+
'启动小岛',
|
|
1092
|
+
),
|
|
1093
|
+
h(
|
|
1094
|
+
'button',
|
|
1095
|
+
{ className: 'vdi-btn', type: 'button', disabled: busy, onClick: () => void control('open-logs') },
|
|
1096
|
+
'打开日志目录',
|
|
1097
|
+
),
|
|
1098
|
+
),
|
|
1099
|
+
status?.lastError === undefined ? null : h('div', { className: 'vdi-error' }, status.lastError),
|
|
1100
|
+
),
|
|
1101
|
+
),
|
|
1102
|
+
h(
|
|
1103
|
+
Group,
|
|
1104
|
+
{ title: '各功能状态', key: 'features', desc: '某项出问题时会在这里提示。' },
|
|
1105
|
+
statusRow('QQ 通知', ...qqChip(status?.qq?.status)),
|
|
1106
|
+
statusRow('微信提醒', ...(status?.wechat?.summary?.chip ?? NO_CHIP)),
|
|
1107
|
+
statusRow(
|
|
1108
|
+
'翻译',
|
|
1109
|
+
...(status?.translation?.available === undefined
|
|
1110
|
+
? NO_CHIP
|
|
1111
|
+
: status.translation.available
|
|
1112
|
+
? ['VibeDev 翻译可用', 'ok']
|
|
1113
|
+
: ['用本地密钥', 'warn']),
|
|
1114
|
+
),
|
|
1115
|
+
statusRow('QQ 邮箱', ...mailChip(status?.mail)),
|
|
1116
|
+
statusRow(
|
|
1117
|
+
'WebView2',
|
|
1118
|
+
...(typeof status?.webview2 === 'string'
|
|
1119
|
+
? [status.webview2, 'ok']
|
|
1120
|
+
: status?.running === true
|
|
1121
|
+
? ['没读到版本', 'warn']
|
|
1122
|
+
: NO_CHIP),
|
|
1123
|
+
),
|
|
1124
|
+
),
|
|
1125
|
+
h(
|
|
1126
|
+
Group,
|
|
1127
|
+
{ title: '更新', key: 'update' },
|
|
1128
|
+
infoRow('当前版本', status?.version ?? '—'),
|
|
1129
|
+
infoRow('更新方式', '手动', '自动下载和更新还没做:新版本要把可执行文件放到安装目录,再重启岛屿。'),
|
|
1130
|
+
),
|
|
1131
|
+
]
|
|
1132
|
+
|
|
1133
|
+
const fact = (label, text) => h('div', { key: label }, h('dt', null, label), h('dd', null, text))
|
|
1134
|
+
const statusRow = (label, text, tone) =>
|
|
1135
|
+
h(Row, { key: label, label }, h('span', { className: `vdi-chip vdi-chip--${tone}` }, text))
|
|
1136
|
+
const infoRow = (label, text, desc) =>
|
|
1137
|
+
h(Row, { key: label, label, desc }, h('span', { className: 'vdi-info' }, text))
|
|
1138
|
+
|
|
1139
|
+
const sections = {
|
|
1140
|
+
overview,
|
|
1141
|
+
|
|
1142
|
+
appearance: () => [
|
|
1143
|
+
h(
|
|
1144
|
+
Group,
|
|
1145
|
+
{ title: '外观模式', key: 'mode' },
|
|
1146
|
+
h(
|
|
1147
|
+
Row,
|
|
1148
|
+
{
|
|
1149
|
+
label: '深浅',
|
|
1150
|
+
desc: '「跟随 VibeDev」:VibeDev 用浅色主题时,小岛和翻译面板也换成浅色版。浅色版不用下面的「岛屿底色」。',
|
|
1151
|
+
},
|
|
1152
|
+
h(Segmented, {
|
|
1153
|
+
label: '深浅',
|
|
1154
|
+
options: ['跟随 VibeDev', '深色', '浅色'],
|
|
1155
|
+
value:
|
|
1156
|
+
{ vibedev: '跟随 VibeDev', dark: '深色', light: '浅色' }[value('appearance.theme', 'vibedev')] ??
|
|
1157
|
+
'跟随 VibeDev',
|
|
1158
|
+
onChange: (option) =>
|
|
1159
|
+
update('appearance.theme', option === '深色' ? 'dark' : option === '浅色' ? 'light' : 'vibedev'),
|
|
1160
|
+
}),
|
|
1161
|
+
),
|
|
1162
|
+
h(
|
|
1163
|
+
Row,
|
|
1164
|
+
{ label: '外观模式' },
|
|
1165
|
+
h(Segmented, {
|
|
1166
|
+
label: '外观模式',
|
|
1167
|
+
options: ['经典', '液态玻璃'],
|
|
1168
|
+
value: value('appearance.mode', 'classic') === 'liquidGlass' ? '液态玻璃' : '经典',
|
|
1169
|
+
onChange: (option) => update('appearance.mode', option === '液态玻璃' ? 'liquidGlass' : 'classic'),
|
|
1170
|
+
}),
|
|
1171
|
+
),
|
|
1172
|
+
h(
|
|
1173
|
+
Row,
|
|
1174
|
+
{ label: '字体' },
|
|
1175
|
+
h(Select, {
|
|
1176
|
+
label: '字体',
|
|
1177
|
+
options: ['默认字体', '像素字体'],
|
|
1178
|
+
value: value('appearance.font', 'system') === 'pixel' ? '像素字体' : '默认字体',
|
|
1179
|
+
onChange: (option) => update('appearance.font', option === '像素字体' ? 'pixel' : 'system'),
|
|
1180
|
+
}),
|
|
1181
|
+
),
|
|
1182
|
+
h(
|
|
1183
|
+
Row,
|
|
1184
|
+
{ label: '玻璃强度', desc: '液态玻璃模式下生效。' },
|
|
1185
|
+
h(Slider, {
|
|
1186
|
+
label: '玻璃强度',
|
|
1187
|
+
value: value('appearance.glassIntensity', 72),
|
|
1188
|
+
min: 0,
|
|
1189
|
+
max: 100,
|
|
1190
|
+
onChange: (next) => update('appearance.glassIntensity', next),
|
|
1191
|
+
}),
|
|
1192
|
+
),
|
|
1193
|
+
),
|
|
1194
|
+
h(
|
|
1195
|
+
Group,
|
|
1196
|
+
{ title: '尺寸与位置', key: 'size' },
|
|
1197
|
+
h(
|
|
1198
|
+
Row,
|
|
1199
|
+
{ label: '不透明度' },
|
|
1200
|
+
h(Slider, {
|
|
1201
|
+
label: '不透明度',
|
|
1202
|
+
value: value('appearance.opacity', 100),
|
|
1203
|
+
min: 50,
|
|
1204
|
+
max: 100,
|
|
1205
|
+
unit: '%',
|
|
1206
|
+
onChange: (next) => update('appearance.opacity', next),
|
|
1207
|
+
}),
|
|
1208
|
+
),
|
|
1209
|
+
h(
|
|
1210
|
+
Row,
|
|
1211
|
+
{ label: '折叠岛屿大小' },
|
|
1212
|
+
h(Slider, {
|
|
1213
|
+
label: '折叠岛屿大小',
|
|
1214
|
+
value: Math.round(value('appearance.collapsedScale', 1) * 100),
|
|
1215
|
+
min: 70,
|
|
1216
|
+
max: 130,
|
|
1217
|
+
unit: '%',
|
|
1218
|
+
onChange: (next) => update('appearance.collapsedScale', next / 100),
|
|
1219
|
+
}),
|
|
1220
|
+
),
|
|
1221
|
+
h(
|
|
1222
|
+
Row,
|
|
1223
|
+
{ label: '展开面板大小' },
|
|
1224
|
+
h(Slider, {
|
|
1225
|
+
label: '展开面板大小',
|
|
1226
|
+
value: Math.round(value('appearance.expandedScale', 1) * 100),
|
|
1227
|
+
min: 70,
|
|
1228
|
+
max: 130,
|
|
1229
|
+
unit: '%',
|
|
1230
|
+
onChange: (next) => update('appearance.expandedScale', next / 100),
|
|
1231
|
+
}),
|
|
1232
|
+
),
|
|
1233
|
+
h(
|
|
1234
|
+
Row,
|
|
1235
|
+
{ label: '顶部距离' },
|
|
1236
|
+
h(Slider, {
|
|
1237
|
+
label: '顶部距离',
|
|
1238
|
+
value: value('appearance.marginY', 0),
|
|
1239
|
+
min: 0,
|
|
1240
|
+
max: 40,
|
|
1241
|
+
unit: ' px',
|
|
1242
|
+
onChange: (next) => update('appearance.marginY', next),
|
|
1243
|
+
}),
|
|
1244
|
+
),
|
|
1245
|
+
),
|
|
1246
|
+
h(
|
|
1247
|
+
Group,
|
|
1248
|
+
{ title: '颜色', key: 'color' },
|
|
1249
|
+
h(
|
|
1250
|
+
Row,
|
|
1251
|
+
{ label: '任务文字' },
|
|
1252
|
+
h(ColorInput, {
|
|
1253
|
+
label: '任务文字',
|
|
1254
|
+
value: value('appearance.taskTextColor', '#ffffff'),
|
|
1255
|
+
onChange: (next) => update('appearance.taskTextColor', next),
|
|
1256
|
+
}),
|
|
1257
|
+
),
|
|
1258
|
+
h(
|
|
1259
|
+
Row,
|
|
1260
|
+
{ label: '亮点颜色' },
|
|
1261
|
+
h(ColorInput, {
|
|
1262
|
+
label: '亮点颜色',
|
|
1263
|
+
value: value('appearance.accentColor', '#3ae489'),
|
|
1264
|
+
onChange: (next) => update('appearance.accentColor', next),
|
|
1265
|
+
}),
|
|
1266
|
+
),
|
|
1267
|
+
h(
|
|
1268
|
+
Row,
|
|
1269
|
+
{ label: '岛屿背景' },
|
|
1270
|
+
h(ColorInput, {
|
|
1271
|
+
label: '岛屿背景',
|
|
1272
|
+
value: value('appearance.islandBackgroundColor', '#030303'),
|
|
1273
|
+
onChange: (next) => update('appearance.islandBackgroundColor', next),
|
|
1274
|
+
}),
|
|
1275
|
+
),
|
|
1276
|
+
h(
|
|
1277
|
+
Row,
|
|
1278
|
+
{ label: '待办纸张' },
|
|
1279
|
+
h(ColorInput, {
|
|
1280
|
+
label: '待办纸张',
|
|
1281
|
+
value: value('appearance.todoPaperColor', '#f6f1e7'),
|
|
1282
|
+
onChange: (next) => update('appearance.todoPaperColor', next),
|
|
1283
|
+
}),
|
|
1284
|
+
),
|
|
1285
|
+
h(
|
|
1286
|
+
Row,
|
|
1287
|
+
{ label: '亮点亮度' },
|
|
1288
|
+
h(Slider, {
|
|
1289
|
+
label: '亮点亮度',
|
|
1290
|
+
value: value('appearance.accentBrightness', 160),
|
|
1291
|
+
min: 50,
|
|
1292
|
+
max: 200,
|
|
1293
|
+
unit: '%',
|
|
1294
|
+
onChange: (next) => update('appearance.accentBrightness', next),
|
|
1295
|
+
}),
|
|
1296
|
+
),
|
|
1297
|
+
),
|
|
1298
|
+
h(
|
|
1299
|
+
Group,
|
|
1300
|
+
{ title: '样式预设', key: 'presets', desc: '保存一套外观,随时切换。' },
|
|
1301
|
+
h(
|
|
1302
|
+
'div',
|
|
1303
|
+
{ className: 'vdi-list' },
|
|
1304
|
+
presets.map((preset) =>
|
|
1305
|
+
h(
|
|
1306
|
+
'div',
|
|
1307
|
+
{ className: 'vdi-item', key: preset.id },
|
|
1308
|
+
h(
|
|
1309
|
+
'div',
|
|
1310
|
+
{ className: 'vdi-item__main' },
|
|
1311
|
+
h(
|
|
1312
|
+
'span',
|
|
1313
|
+
{ className: 'vdi-swatches' },
|
|
1314
|
+
[preset.islandBackgroundColor, preset.accentColor, preset.taskTextColor]
|
|
1315
|
+
.filter(Boolean)
|
|
1316
|
+
.map((color, index) => h('i', { key: index, style: { background: color } })),
|
|
1317
|
+
),
|
|
1318
|
+
h('span', null, preset.name),
|
|
1319
|
+
preset.isDefault === true ? h('span', { className: 'vdi-chip vdi-chip--ok' }, '使用中') : null,
|
|
1320
|
+
),
|
|
1321
|
+
h(
|
|
1322
|
+
'div',
|
|
1323
|
+
{ className: 'vdi-item__act' },
|
|
1324
|
+
h(
|
|
1325
|
+
'button',
|
|
1326
|
+
{
|
|
1327
|
+
className: 'vdi-btn',
|
|
1328
|
+
type: 'button',
|
|
1329
|
+
onClick: () => void applyPreset(preset),
|
|
1330
|
+
},
|
|
1331
|
+
'启用',
|
|
1332
|
+
),
|
|
1333
|
+
h(
|
|
1334
|
+
'button',
|
|
1335
|
+
{
|
|
1336
|
+
className: 'vdi-btn',
|
|
1337
|
+
type: 'button',
|
|
1338
|
+
onClick: () => void renamePreset(preset),
|
|
1339
|
+
},
|
|
1340
|
+
'重命名',
|
|
1341
|
+
),
|
|
1342
|
+
h(
|
|
1343
|
+
'button',
|
|
1344
|
+
{
|
|
1345
|
+
className: 'vdi-btn vdi-btn--danger',
|
|
1346
|
+
type: 'button',
|
|
1347
|
+
onClick: () => void removePreset(preset),
|
|
1348
|
+
},
|
|
1349
|
+
'删除',
|
|
1350
|
+
),
|
|
1351
|
+
),
|
|
1352
|
+
),
|
|
1353
|
+
),
|
|
1354
|
+
presets.length === 0
|
|
1355
|
+
? h('div', { className: 'vdi-item' }, h('span', { className: 'vdi-item__sub' }, '还没有样式预设'))
|
|
1356
|
+
: null,
|
|
1357
|
+
h(
|
|
1358
|
+
'div',
|
|
1359
|
+
{ className: 'vdi-item' },
|
|
1360
|
+
h(
|
|
1361
|
+
'button',
|
|
1362
|
+
{ className: 'vdi-btn', type: 'button', onClick: () => void savePreset() },
|
|
1363
|
+
'保存当前为预设',
|
|
1364
|
+
),
|
|
1365
|
+
),
|
|
1366
|
+
),
|
|
1367
|
+
),
|
|
1368
|
+
],
|
|
1369
|
+
|
|
1370
|
+
behavior: () => [
|
|
1371
|
+
h(
|
|
1372
|
+
Group,
|
|
1373
|
+
{ title: '展开与收起', key: 'expand' },
|
|
1374
|
+
h(
|
|
1375
|
+
Row,
|
|
1376
|
+
{ label: '展开方式', desc: '悬停:鼠标停在小岛上就展开;点击:点一下才展开。' },
|
|
1377
|
+
h(Segmented, {
|
|
1378
|
+
label: '展开方式',
|
|
1379
|
+
options: ['悬停', '点击'],
|
|
1380
|
+
value: value('behavior.expandOnHover', true) === false ? '点击' : '悬停',
|
|
1381
|
+
onChange: (option) => update('behavior.expandOnHover', option === '悬停'),
|
|
1382
|
+
}),
|
|
1383
|
+
),
|
|
1384
|
+
h(
|
|
1385
|
+
Row,
|
|
1386
|
+
{ label: '悬停多久后展开' },
|
|
1387
|
+
h(Slider, {
|
|
1388
|
+
label: '悬停多久后展开',
|
|
1389
|
+
value: value('behavior.hoverExpandDelayMs', 150),
|
|
1390
|
+
min: 0,
|
|
1391
|
+
max: 1000,
|
|
1392
|
+
step: 50,
|
|
1393
|
+
unit: ' ms',
|
|
1394
|
+
onChange: (next) => update('behavior.hoverExpandDelayMs', next),
|
|
1395
|
+
}),
|
|
1396
|
+
),
|
|
1397
|
+
h(
|
|
1398
|
+
Row,
|
|
1399
|
+
{ label: '离开多久后收起' },
|
|
1400
|
+
h(Slider, {
|
|
1401
|
+
label: '离开多久后收起',
|
|
1402
|
+
value: value('behavior.hoverCollapseDelayMs', 300),
|
|
1403
|
+
min: 0,
|
|
1404
|
+
max: 2000,
|
|
1405
|
+
step: 100,
|
|
1406
|
+
unit: ' ms',
|
|
1407
|
+
onChange: (next) => update('behavior.hoverCollapseDelayMs', next),
|
|
1408
|
+
}),
|
|
1409
|
+
),
|
|
1410
|
+
h(
|
|
1411
|
+
Row,
|
|
1412
|
+
{ label: '无操作时贴边收起', desc: '收起后只在屏幕顶部露出一条细线。' },
|
|
1413
|
+
h(Toggle, {
|
|
1414
|
+
label: '无操作时贴边收起',
|
|
1415
|
+
checked: value('behavior.autoTuck', false) === true,
|
|
1416
|
+
onChange: (next) => update('behavior.autoTuck', next),
|
|
1417
|
+
}),
|
|
1418
|
+
),
|
|
1419
|
+
h(
|
|
1420
|
+
Row,
|
|
1421
|
+
{ label: '闲置多久后收起', dim: value('behavior.autoTuck', false) !== true },
|
|
1422
|
+
h(NumberInput, {
|
|
1423
|
+
label: '闲置多久后收起',
|
|
1424
|
+
value: value('behavior.autoTuckSeconds', 30),
|
|
1425
|
+
unit: '秒',
|
|
1426
|
+
min: 5,
|
|
1427
|
+
max: 600,
|
|
1428
|
+
onChange: (next) => update('behavior.autoTuckSeconds', next),
|
|
1429
|
+
}),
|
|
1430
|
+
),
|
|
1431
|
+
h(
|
|
1432
|
+
Row,
|
|
1433
|
+
{
|
|
1434
|
+
label: '全屏时保持安静',
|
|
1435
|
+
desc: '前台是盖住小岛那块屏的全屏程序(游戏、全屏视频)时:鼠标经过不展开、不弹消息横幅、不出翻译按钮,等你批准的操作直接交给 VibeDev。',
|
|
1436
|
+
},
|
|
1437
|
+
h(Toggle, {
|
|
1438
|
+
label: '全屏时保持安静',
|
|
1439
|
+
checked: value('behavior.quietInFullscreen', true) === true,
|
|
1440
|
+
onChange: (next) => update('behavior.quietInFullscreen', next),
|
|
1441
|
+
}),
|
|
1442
|
+
),
|
|
1443
|
+
),
|
|
1444
|
+
h(
|
|
1445
|
+
Group,
|
|
1446
|
+
{ title: '折叠时显示', key: 'collapsed' },
|
|
1447
|
+
h(
|
|
1448
|
+
Row,
|
|
1449
|
+
{ label: '显示折叠文字' },
|
|
1450
|
+
h(Toggle, {
|
|
1451
|
+
label: '显示折叠文字',
|
|
1452
|
+
checked: value('behavior.showCollapsedText', true) === true,
|
|
1453
|
+
onChange: (next) => update('behavior.showCollapsedText', next),
|
|
1454
|
+
}),
|
|
1455
|
+
),
|
|
1456
|
+
h(
|
|
1457
|
+
Row,
|
|
1458
|
+
{ label: '显示岛屿名称' },
|
|
1459
|
+
h(Toggle, {
|
|
1460
|
+
label: '显示岛屿名称',
|
|
1461
|
+
checked: value('behavior.showTitle', false) === true,
|
|
1462
|
+
onChange: (next) => update('behavior.showTitle', next),
|
|
1463
|
+
}),
|
|
1464
|
+
),
|
|
1465
|
+
h(
|
|
1466
|
+
Row,
|
|
1467
|
+
{ label: '空闲时显示剩余待办数' },
|
|
1468
|
+
h(Toggle, {
|
|
1469
|
+
label: '空闲时显示剩余待办数',
|
|
1470
|
+
checked: value('behavior.showIdleTodoCount', true) === true,
|
|
1471
|
+
onChange: (next) => update('behavior.showIdleTodoCount', next),
|
|
1472
|
+
}),
|
|
1473
|
+
),
|
|
1474
|
+
),
|
|
1475
|
+
h(
|
|
1476
|
+
Group,
|
|
1477
|
+
{
|
|
1478
|
+
title: '快捷键',
|
|
1479
|
+
key: 'hotkeys',
|
|
1480
|
+
desc: '两个都可以不设;不设就不占用任何组合键。',
|
|
1481
|
+
},
|
|
1482
|
+
h(
|
|
1483
|
+
Row,
|
|
1484
|
+
{
|
|
1485
|
+
label: '显示或隐藏小岛',
|
|
1486
|
+
desc: withNote('把小岛藏起来,再按一次叫回来。', shortcutNote('toggleIsland')),
|
|
1487
|
+
},
|
|
1488
|
+
h(ShortcutField, {
|
|
1489
|
+
label: '显示或隐藏小岛',
|
|
1490
|
+
value: value('behavior.toggleShortcut', ''),
|
|
1491
|
+
optional: true,
|
|
1492
|
+
onChange: (next) => update('behavior.toggleShortcut', next),
|
|
1493
|
+
}),
|
|
1494
|
+
),
|
|
1495
|
+
h(
|
|
1496
|
+
Row,
|
|
1497
|
+
{
|
|
1498
|
+
label: '展开到 VibeDev 会话',
|
|
1499
|
+
desc: withNote('把小岛叫出来,并打开会话那一页。', shortcutNote('openSessions')),
|
|
1500
|
+
},
|
|
1501
|
+
h(ShortcutField, {
|
|
1502
|
+
label: '展开到 VibeDev 会话',
|
|
1503
|
+
value: value('behavior.sessionsShortcut', ''),
|
|
1504
|
+
optional: true,
|
|
1505
|
+
onChange: (next) => update('behavior.sessionsShortcut', next),
|
|
1506
|
+
}),
|
|
1507
|
+
),
|
|
1508
|
+
),
|
|
1509
|
+
],
|
|
1510
|
+
|
|
1511
|
+
pages: () => {
|
|
1512
|
+
// 往小岛上放过东西的插件(这次运行里的)和单独关掉的,每个一行开关。
|
|
1513
|
+
const contributorRows = () => {
|
|
1514
|
+
const blocked = value('contrib.blocked', NO_EVENTS)
|
|
1515
|
+
const seen = Array.isArray(status?.contributors) ? status.contributors : NO_EVENTS
|
|
1516
|
+
const names = [...seen.map((item) => item.name), ...blocked].filter(
|
|
1517
|
+
(name, index, all) => typeof name === 'string' && all.indexOf(name) === index,
|
|
1518
|
+
)
|
|
1519
|
+
if (names.length === 0) {
|
|
1520
|
+
return [
|
|
1521
|
+
h(Row, {
|
|
1522
|
+
key: 'none',
|
|
1523
|
+
label: '还没有插件放过东西',
|
|
1524
|
+
desc: '其它插件第一次往小岛上放东西之后,会出现在这里,可以单独关掉。',
|
|
1525
|
+
}),
|
|
1526
|
+
]
|
|
1527
|
+
}
|
|
1528
|
+
return names.map((name) => {
|
|
1529
|
+
const item = seen.find((entry) => entry.name === name)
|
|
1530
|
+
return h(
|
|
1531
|
+
Row,
|
|
1532
|
+
{
|
|
1533
|
+
key: name,
|
|
1534
|
+
label: name,
|
|
1535
|
+
dim: value('contrib.enabled', true) !== true,
|
|
1536
|
+
desc: item === undefined ? '这次运行里还没放过东西。' : `现在挂着 ${item.items} 条。`,
|
|
1537
|
+
},
|
|
1538
|
+
h(Toggle, {
|
|
1539
|
+
label: `允许 ${name}`,
|
|
1540
|
+
checked: !blocked.includes(name),
|
|
1541
|
+
disabled: value('contrib.enabled', true) !== true,
|
|
1542
|
+
onChange: (next) =>
|
|
1543
|
+
update('contrib.blocked', next ? blocked.filter((entry) => entry !== name) : [...blocked, name]),
|
|
1544
|
+
}),
|
|
1545
|
+
)
|
|
1546
|
+
})
|
|
1547
|
+
}
|
|
1548
|
+
const order = value('pages.order', TAB_PAGES)
|
|
1549
|
+
const hidden = value('pages.hidden', NO_EVENTS)
|
|
1550
|
+
const shown = order.filter((id) => !hidden.includes(id))
|
|
1551
|
+
const move = (id, step) => update('pages.order', movePage(order, id, step))
|
|
1552
|
+
const setShown = (id, visible) => update('pages.hidden', setPageShown(hidden, id, visible))
|
|
1553
|
+
const openOn = value('pages.openOn', 'last')
|
|
1554
|
+
const openOnLabels = { last: '上次停留的那一页', ...PAGE_LABELS }
|
|
1555
|
+
const openOnChoices = ['last', ...TAB_PAGES]
|
|
1556
|
+
return [
|
|
1557
|
+
h(
|
|
1558
|
+
Group,
|
|
1559
|
+
{
|
|
1560
|
+
title: '页面',
|
|
1561
|
+
key: 'pages',
|
|
1562
|
+
desc: '展开后顶上那一排按钮:用箭头调整顺序,关掉的页面不给入口。至少留一页。',
|
|
1563
|
+
},
|
|
1564
|
+
h(
|
|
1565
|
+
'div',
|
|
1566
|
+
{ className: 'vdi-list' },
|
|
1567
|
+
order.map((id, index) => {
|
|
1568
|
+
const visible = !hidden.includes(id)
|
|
1569
|
+
// 只剩这一页还开着时不能再关:展开的小岛不能没有东西可看。
|
|
1570
|
+
const last = visible && shown.length === 1
|
|
1571
|
+
return h(
|
|
1572
|
+
'div',
|
|
1573
|
+
{ className: `vdi-item${visible ? '' : ' vdi-item--off'}`, key: id },
|
|
1574
|
+
h('div', { className: 'vdi-item__main' }, h('span', null, PAGE_LABELS[id])),
|
|
1575
|
+
h(
|
|
1576
|
+
'div',
|
|
1577
|
+
{ className: 'vdi-item__act' },
|
|
1578
|
+
h(
|
|
1579
|
+
'button',
|
|
1580
|
+
{
|
|
1581
|
+
className: 'vdi-move',
|
|
1582
|
+
type: 'button',
|
|
1583
|
+
'aria-label': `${PAGE_LABELS[id]} 上移`,
|
|
1584
|
+
disabled: index === 0,
|
|
1585
|
+
onClick: () => move(id, -1),
|
|
1586
|
+
},
|
|
1587
|
+
'↑',
|
|
1588
|
+
),
|
|
1589
|
+
h(
|
|
1590
|
+
'button',
|
|
1591
|
+
{
|
|
1592
|
+
className: 'vdi-move',
|
|
1593
|
+
type: 'button',
|
|
1594
|
+
'aria-label': `${PAGE_LABELS[id]} 下移`,
|
|
1595
|
+
disabled: index === order.length - 1,
|
|
1596
|
+
onClick: () => move(id, 1),
|
|
1597
|
+
},
|
|
1598
|
+
'↓',
|
|
1599
|
+
),
|
|
1600
|
+
h(Toggle, {
|
|
1601
|
+
label: `显示 ${PAGE_LABELS[id]}`,
|
|
1602
|
+
checked: visible,
|
|
1603
|
+
disabled: last,
|
|
1604
|
+
onChange: (next) => setShown(id, next),
|
|
1605
|
+
}),
|
|
1606
|
+
),
|
|
1607
|
+
)
|
|
1608
|
+
}),
|
|
1609
|
+
h(
|
|
1610
|
+
'div',
|
|
1611
|
+
{
|
|
1612
|
+
className: `vdi-item${hidden.includes(MESSAGES_PAGE) ? ' vdi-item--off' : ''}`,
|
|
1613
|
+
key: MESSAGES_PAGE,
|
|
1614
|
+
},
|
|
1615
|
+
h(
|
|
1616
|
+
'div',
|
|
1617
|
+
{ className: 'vdi-item__main' },
|
|
1618
|
+
h(
|
|
1619
|
+
'div',
|
|
1620
|
+
null,
|
|
1621
|
+
h('div', null, PAGE_LABELS[MESSAGES_PAGE]),
|
|
1622
|
+
h(
|
|
1623
|
+
'div',
|
|
1624
|
+
{ className: 'vdi-item__sub' },
|
|
1625
|
+
'入口是右上角的铃铛,不在那一排按钮里,所以不参与排序。',
|
|
1626
|
+
),
|
|
1627
|
+
),
|
|
1628
|
+
),
|
|
1629
|
+
h(
|
|
1630
|
+
'div',
|
|
1631
|
+
{ className: 'vdi-item__act' },
|
|
1632
|
+
h(Toggle, {
|
|
1633
|
+
label: `显示 ${PAGE_LABELS[MESSAGES_PAGE]}`,
|
|
1634
|
+
checked: !hidden.includes(MESSAGES_PAGE),
|
|
1635
|
+
onChange: (next) => setShown(MESSAGES_PAGE, next),
|
|
1636
|
+
}),
|
|
1637
|
+
),
|
|
1638
|
+
),
|
|
1639
|
+
),
|
|
1640
|
+
),
|
|
1641
|
+
h(
|
|
1642
|
+
Group,
|
|
1643
|
+
{ title: '展开时', key: 'open' },
|
|
1644
|
+
h(
|
|
1645
|
+
Row,
|
|
1646
|
+
{
|
|
1647
|
+
label: '展开时打开',
|
|
1648
|
+
desc: '选了某一页,每次展开都先到那一页;它被关掉时改去排第一的那一页。',
|
|
1649
|
+
},
|
|
1650
|
+
h(Select, {
|
|
1651
|
+
label: '展开时打开',
|
|
1652
|
+
options: openOnChoices.map((id) => openOnLabels[id]),
|
|
1653
|
+
value: openOnLabels[openOn] ?? openOnLabels.last,
|
|
1654
|
+
onChange: (label) =>
|
|
1655
|
+
update('pages.openOn', openOnChoices.find((id) => openOnLabels[id] === label) ?? 'last'),
|
|
1656
|
+
}),
|
|
1657
|
+
),
|
|
1658
|
+
),
|
|
1659
|
+
h(
|
|
1660
|
+
Group,
|
|
1661
|
+
{ title: '其它插件放的东西', key: 'contrib' },
|
|
1662
|
+
h(
|
|
1663
|
+
Row,
|
|
1664
|
+
{
|
|
1665
|
+
label: '让其它插件往小岛上放东西',
|
|
1666
|
+
desc:
|
|
1667
|
+
'装了的其它插件可以在小岛上放状态、后台任务的进度(例如影视工作台的图片、视频、音频生成)、一页进度和会自己消失的通知。' +
|
|
1668
|
+
'有真实进度时显示进度,没有就转圈;每个插件的通知一分钟最多 3 条,更新太快的会合并;插件停用时它放的东西一起撤下。',
|
|
1669
|
+
},
|
|
1670
|
+
h(Toggle, {
|
|
1671
|
+
label: '让其它插件往小岛上放东西',
|
|
1672
|
+
checked: value('contrib.enabled', true) === true,
|
|
1673
|
+
onChange: (next) => update('contrib.enabled', next),
|
|
1674
|
+
}),
|
|
1675
|
+
),
|
|
1676
|
+
...contributorRows(),
|
|
1677
|
+
),
|
|
1678
|
+
]
|
|
1679
|
+
},
|
|
1680
|
+
|
|
1681
|
+
sessions: () => [
|
|
1682
|
+
h(
|
|
1683
|
+
Group,
|
|
1684
|
+
{ title: '状态灯', key: 'light' },
|
|
1685
|
+
h(
|
|
1686
|
+
Row,
|
|
1687
|
+
{ label: '在小岛上显示会话状态' },
|
|
1688
|
+
h(Toggle, {
|
|
1689
|
+
label: '在小岛上显示会话状态',
|
|
1690
|
+
checked: value('sessions.showStatus', true) === true,
|
|
1691
|
+
onChange: (next) => update('sessions.showStatus', next),
|
|
1692
|
+
}),
|
|
1693
|
+
),
|
|
1694
|
+
h(
|
|
1695
|
+
Row,
|
|
1696
|
+
{ label: '显示哪些会话', desc: '「最近在用的工作目录」:只留和最近活动的那条会话在同一个目录下的。' },
|
|
1697
|
+
h(Select, {
|
|
1698
|
+
label: '显示哪些会话',
|
|
1699
|
+
options: ['全部会话', '最近在用的工作目录', '只显示正在运行的会话'],
|
|
1700
|
+
value:
|
|
1701
|
+
value('sessions.scope', 'all') === 'workspace'
|
|
1702
|
+
? '最近在用的工作目录'
|
|
1703
|
+
: value('sessions.scope', 'all') === 'current'
|
|
1704
|
+
? '只显示正在运行的会话'
|
|
1705
|
+
: '全部会话',
|
|
1706
|
+
onChange: (option) =>
|
|
1707
|
+
update(
|
|
1708
|
+
'sessions.scope',
|
|
1709
|
+
option === '最近在用的工作目录'
|
|
1710
|
+
? 'workspace'
|
|
1711
|
+
: option === '只显示正在运行的会话'
|
|
1712
|
+
? 'current'
|
|
1713
|
+
: 'all',
|
|
1714
|
+
),
|
|
1715
|
+
}),
|
|
1716
|
+
),
|
|
1717
|
+
h(
|
|
1718
|
+
Row,
|
|
1719
|
+
{ label: '折叠条显示会话标题', desc: '有变化时:开始、完成、出错、等你时显示。' },
|
|
1720
|
+
h(Segmented, {
|
|
1721
|
+
label: '折叠条显示会话标题',
|
|
1722
|
+
options: ['有变化时', '运行时一直显示', '不显示'],
|
|
1723
|
+
value:
|
|
1724
|
+
{ changes: '有变化时', always: '运行时一直显示', never: '不显示' }[
|
|
1725
|
+
value('sessions.titleMode', 'changes')
|
|
1726
|
+
] ?? '有变化时',
|
|
1727
|
+
onChange: (option) =>
|
|
1728
|
+
update(
|
|
1729
|
+
'sessions.titleMode',
|
|
1730
|
+
{ 有变化时: 'changes', 运行时一直显示: 'always', 不显示: 'never' }[option] ?? 'changes',
|
|
1731
|
+
),
|
|
1732
|
+
}),
|
|
1733
|
+
),
|
|
1734
|
+
h(
|
|
1735
|
+
Row,
|
|
1736
|
+
{
|
|
1737
|
+
label: '状态灯样式',
|
|
1738
|
+
desc: '进度环:插件的任务有真实进度时(比如影视工作台的生成),灯变成一个跟着进度走的环;会话在跑、没有进度时环在转。',
|
|
1739
|
+
},
|
|
1740
|
+
h(Segmented, {
|
|
1741
|
+
label: '状态灯样式',
|
|
1742
|
+
options: ['圆点', '进度环'],
|
|
1743
|
+
value: value('sessions.lightStyle', 'dot') === 'ring' ? '进度环' : '圆点',
|
|
1744
|
+
onChange: (option) => update('sessions.lightStyle', option === '进度环' ? 'ring' : 'dot'),
|
|
1745
|
+
}),
|
|
1746
|
+
),
|
|
1747
|
+
),
|
|
1748
|
+
h(
|
|
1749
|
+
Group,
|
|
1750
|
+
{ title: '提醒', key: 'notify' },
|
|
1751
|
+
h(
|
|
1752
|
+
Row,
|
|
1753
|
+
{ label: '任务完成时通知' },
|
|
1754
|
+
h(Toggle, {
|
|
1755
|
+
label: '任务完成时通知',
|
|
1756
|
+
checked: value('sessions.notifyOnDone', true) === true,
|
|
1757
|
+
onChange: (next) => update('sessions.notifyOnDone', next),
|
|
1758
|
+
}),
|
|
1759
|
+
),
|
|
1760
|
+
h(
|
|
1761
|
+
Row,
|
|
1762
|
+
{ label: '运行超过多久才提醒完成', desc: '短任务不打扰。设成 0 就是每次完成都提醒。' },
|
|
1763
|
+
h(NumberInput, {
|
|
1764
|
+
label: '运行超过多久才提醒完成',
|
|
1765
|
+
value: value('sessions.doneNotifyMinSeconds', 60),
|
|
1766
|
+
unit: '秒',
|
|
1767
|
+
min: 0,
|
|
1768
|
+
max: 3600,
|
|
1769
|
+
onChange: (next) => update('sessions.doneNotifyMinSeconds', next),
|
|
1770
|
+
}),
|
|
1771
|
+
),
|
|
1772
|
+
h(
|
|
1773
|
+
Row,
|
|
1774
|
+
{ label: '通知时播放提示音', desc: '任务完成时岛屿响一下。它不会抢走你正在用的窗口的焦点。' },
|
|
1775
|
+
h(Toggle, {
|
|
1776
|
+
label: '通知时播放提示音',
|
|
1777
|
+
checked: value('sessions.notifySound', true) === true,
|
|
1778
|
+
onChange: (next) => update('sessions.notifySound', next),
|
|
1779
|
+
}),
|
|
1780
|
+
),
|
|
1781
|
+
h(
|
|
1782
|
+
Row,
|
|
1783
|
+
{ label: '提示音', dim: value('sessions.notifySound', true) !== true },
|
|
1784
|
+
h(Select, {
|
|
1785
|
+
label: '提示音',
|
|
1786
|
+
options: SOUND_CHOICES.map(([, label]) => label),
|
|
1787
|
+
value: (SOUND_CHOICES.find(([id]) => id === value('sessions.sound', 'exclamation')) ??
|
|
1788
|
+
SOUND_CHOICES[0])[1],
|
|
1789
|
+
onChange: (option) =>
|
|
1790
|
+
update(
|
|
1791
|
+
'sessions.sound',
|
|
1792
|
+
(SOUND_CHOICES.find(([, label]) => label === option) ?? SOUND_CHOICES[0])[0],
|
|
1793
|
+
),
|
|
1794
|
+
}),
|
|
1795
|
+
),
|
|
1796
|
+
h(
|
|
1797
|
+
Row,
|
|
1798
|
+
{ label: '音量', dim: value('sessions.notifySound', true) !== true },
|
|
1799
|
+
h(Slider, {
|
|
1800
|
+
label: '音量',
|
|
1801
|
+
value: value('sessions.soundVolume', 100),
|
|
1802
|
+
min: 0,
|
|
1803
|
+
max: 100,
|
|
1804
|
+
step: 5,
|
|
1805
|
+
unit: '%',
|
|
1806
|
+
onChange: (next) => update('sessions.soundVolume', next),
|
|
1807
|
+
}),
|
|
1808
|
+
h(
|
|
1809
|
+
'button',
|
|
1810
|
+
{
|
|
1811
|
+
className: 'vdi-btn',
|
|
1812
|
+
type: 'button',
|
|
1813
|
+
disabled: busy || !running,
|
|
1814
|
+
onClick: () => void control('sound-test'),
|
|
1815
|
+
},
|
|
1816
|
+
'试听',
|
|
1817
|
+
),
|
|
1818
|
+
),
|
|
1819
|
+
h(
|
|
1820
|
+
Row,
|
|
1821
|
+
{ label: '运行中的会话显示成任务', desc: '折叠条上显示一条「运行中」的任务,不编造百分比。' },
|
|
1822
|
+
h(Toggle, {
|
|
1823
|
+
label: '运行中的会话显示成任务',
|
|
1824
|
+
checked: value('sessions.showRunningTask', true) === true,
|
|
1825
|
+
onChange: (next) => update('sessions.showRunningTask', next),
|
|
1826
|
+
}),
|
|
1827
|
+
),
|
|
1828
|
+
h(
|
|
1829
|
+
Row,
|
|
1830
|
+
{ label: '出错时通知' },
|
|
1831
|
+
h(Toggle, {
|
|
1832
|
+
label: '出错时通知',
|
|
1833
|
+
checked: value('sessions.notifyOnError', true) === true,
|
|
1834
|
+
onChange: (next) => update('sessions.notifyOnError', next),
|
|
1835
|
+
}),
|
|
1836
|
+
),
|
|
1837
|
+
h(
|
|
1838
|
+
Row,
|
|
1839
|
+
{ label: '需要回答问题时提醒', desc: '点一下回到 VibeDev 回答。' },
|
|
1840
|
+
h(Toggle, {
|
|
1841
|
+
label: '需要回答问题时提醒',
|
|
1842
|
+
checked: value('sessions.notifyOnQuestion', true) === true,
|
|
1843
|
+
onChange: (next) => update('sessions.notifyOnQuestion', next),
|
|
1844
|
+
}),
|
|
1845
|
+
),
|
|
1846
|
+
),
|
|
1847
|
+
h(
|
|
1848
|
+
Group,
|
|
1849
|
+
{ title: '岛上审批', key: 'approval' },
|
|
1850
|
+
h(
|
|
1851
|
+
Row,
|
|
1852
|
+
{
|
|
1853
|
+
label: '在小岛上提醒审批',
|
|
1854
|
+
desc: 'VibeDev 需要你批准操作时,小岛上挂一张卡片,直到这件事有了结果;点「去处理」回到 VibeDev。',
|
|
1855
|
+
},
|
|
1856
|
+
h(Toggle, {
|
|
1857
|
+
label: '在小岛上提醒审批',
|
|
1858
|
+
checked: value('sessions.approveOnIsland', true) === true,
|
|
1859
|
+
onChange: (next) => update('sessions.approveOnIsland', next),
|
|
1860
|
+
}),
|
|
1861
|
+
),
|
|
1862
|
+
h(
|
|
1863
|
+
Row,
|
|
1864
|
+
{
|
|
1865
|
+
label: '在小岛上直接批准',
|
|
1866
|
+
dim: value('sessions.approveOnIsland', true) !== true,
|
|
1867
|
+
desc:
|
|
1868
|
+
'你不在 VibeDev 里时,先在小岛上问:可以直接「允许」一次或「拒绝」。看起来危险的操作(删除、强推、改系统、提权)只能回 VibeDev 批准;申请整机权限的可以在岛上批准,卡片标红(岛上看不到命令本身);' +
|
|
1869
|
+
'60 秒没人管就交回 VibeDev 照常问你。你正看着 VibeDev、或者在全屏打游戏时,直接交给 VibeDev。',
|
|
1870
|
+
},
|
|
1871
|
+
h(Toggle, {
|
|
1872
|
+
label: '在小岛上直接批准',
|
|
1873
|
+
checked: value('sessions.decideOnIsland', true) === true,
|
|
1874
|
+
disabled: value('sessions.approveOnIsland', true) !== true,
|
|
1875
|
+
onChange: (next) => update('sessions.decideOnIsland', next),
|
|
1876
|
+
}),
|
|
1877
|
+
),
|
|
1878
|
+
),
|
|
1879
|
+
],
|
|
1880
|
+
|
|
1881
|
+
todos: () => [
|
|
1882
|
+
h(
|
|
1883
|
+
Group,
|
|
1884
|
+
{ title: '待办', key: 'todo' },
|
|
1885
|
+
h(
|
|
1886
|
+
Row,
|
|
1887
|
+
{ label: '自动将未完成任务写入下一天' },
|
|
1888
|
+
h(Toggle, {
|
|
1889
|
+
label: '自动将未完成任务写入下一天',
|
|
1890
|
+
checked: value('todos.carryOver', false) === true,
|
|
1891
|
+
onChange: (next) => update('todos.carryOver', next),
|
|
1892
|
+
}),
|
|
1893
|
+
),
|
|
1894
|
+
h(
|
|
1895
|
+
Row,
|
|
1896
|
+
{ label: '允许拖动调整任务顺序' },
|
|
1897
|
+
h(Toggle, {
|
|
1898
|
+
label: '允许拖动调整任务顺序',
|
|
1899
|
+
checked: value('todos.reorder', false) === true,
|
|
1900
|
+
onChange: (next) => update('todos.reorder', next),
|
|
1901
|
+
}),
|
|
1902
|
+
),
|
|
1903
|
+
h(
|
|
1904
|
+
Row,
|
|
1905
|
+
{ label: '多任务流动', desc: '折叠时轮流显示多个任务。' },
|
|
1906
|
+
h(Toggle, {
|
|
1907
|
+
label: '多任务流动',
|
|
1908
|
+
checked: value('todos.rotate', false) === true,
|
|
1909
|
+
onChange: (next) => update('todos.rotate', next),
|
|
1910
|
+
}),
|
|
1911
|
+
),
|
|
1912
|
+
h(
|
|
1913
|
+
Row,
|
|
1914
|
+
{ label: '每个任务停留时间', dim: value('todos.rotate', false) !== true },
|
|
1915
|
+
h(NumberInput, {
|
|
1916
|
+
label: '每个任务停留时间',
|
|
1917
|
+
value: value('todos.rotationSeconds', 5),
|
|
1918
|
+
unit: '秒',
|
|
1919
|
+
min: 2,
|
|
1920
|
+
max: 60,
|
|
1921
|
+
onChange: (next) => update('todos.rotationSeconds', next),
|
|
1922
|
+
}),
|
|
1923
|
+
),
|
|
1924
|
+
),
|
|
1925
|
+
h(
|
|
1926
|
+
Group,
|
|
1927
|
+
{
|
|
1928
|
+
title: '存储',
|
|
1929
|
+
key: 'storage',
|
|
1930
|
+
desc: '待办、笔记和归档由岛屿写入文件,VibeDev 的 Agent 以后可以直接读。',
|
|
1931
|
+
},
|
|
1932
|
+
h(
|
|
1933
|
+
Row,
|
|
1934
|
+
{ label: '待办与笔记', desc: '清单、当天笔记和归档存在同一个 JSON 文件里。' },
|
|
1935
|
+
h(PathInput, { label: '待办与笔记', value: '%APPDATA%/com.vibedev.island/data/todos.json' }),
|
|
1936
|
+
),
|
|
1937
|
+
h(
|
|
1938
|
+
Row,
|
|
1939
|
+
{
|
|
1940
|
+
label: 'Markdown 导出目录',
|
|
1941
|
+
desc: '每天的清单另存一份 Markdown。留空用默认目录(文档\\VibeDev);回车或点别处生效。',
|
|
1942
|
+
},
|
|
1943
|
+
h(PathInput, {
|
|
1944
|
+
label: 'Markdown 导出目录',
|
|
1945
|
+
value: value('todos.saveDirectory', ''),
|
|
1946
|
+
placeholder: '例如 D:\\笔记\\每日(留空用默认)',
|
|
1947
|
+
onChange: (next) => update('todos.saveDirectory', next),
|
|
1948
|
+
}),
|
|
1949
|
+
),
|
|
1950
|
+
),
|
|
1951
|
+
],
|
|
1952
|
+
|
|
1953
|
+
clipboard: () => [
|
|
1954
|
+
h(
|
|
1955
|
+
Group,
|
|
1956
|
+
{ title: '记录', key: 'record' },
|
|
1957
|
+
h(
|
|
1958
|
+
Row,
|
|
1959
|
+
{ label: '记录剪贴板', desc: '密码管理器复制时标明了「别记录」的内容一律不记。' },
|
|
1960
|
+
h(Toggle, {
|
|
1961
|
+
label: '记录剪贴板',
|
|
1962
|
+
checked: value('clipboard.enabled', true) === true,
|
|
1963
|
+
onChange: (next) => update('clipboard.enabled', next),
|
|
1964
|
+
}),
|
|
1965
|
+
),
|
|
1966
|
+
h(
|
|
1967
|
+
Row,
|
|
1968
|
+
{ label: '记录图片' },
|
|
1969
|
+
h(Toggle, {
|
|
1970
|
+
label: '记录图片',
|
|
1971
|
+
checked: value('clipboard.images', true) === true,
|
|
1972
|
+
onChange: (next) => update('clipboard.images', next),
|
|
1973
|
+
}),
|
|
1974
|
+
),
|
|
1975
|
+
h(
|
|
1976
|
+
Row,
|
|
1977
|
+
{ label: '最大历史条数' },
|
|
1978
|
+
h(NumberInput, {
|
|
1979
|
+
label: '最大历史条数',
|
|
1980
|
+
value: value('clipboard.maxItems', 200),
|
|
1981
|
+
unit: '条',
|
|
1982
|
+
min: 20,
|
|
1983
|
+
max: 200,
|
|
1984
|
+
onChange: (next) => update('clipboard.maxItems', next),
|
|
1985
|
+
}),
|
|
1986
|
+
),
|
|
1987
|
+
h(
|
|
1988
|
+
Row,
|
|
1989
|
+
{
|
|
1990
|
+
label: '敏感内容自动打码',
|
|
1991
|
+
desc:
|
|
1992
|
+
'复制的内容里认出密钥、令牌(sk-、ghp_、AKIA 这类)、私钥或「password=…」的值时,历史里只存打码后的样子,' +
|
|
1993
|
+
'复制这一条拿到的也是打码后的。只认很确定的格式;打开之前已经记下的不改。',
|
|
1994
|
+
},
|
|
1995
|
+
h(Toggle, {
|
|
1996
|
+
label: '敏感内容自动打码',
|
|
1997
|
+
checked: value('clipboard.maskSecrets', true) === true,
|
|
1998
|
+
onChange: (next) => update('clipboard.maskSecrets', next),
|
|
1999
|
+
}),
|
|
2000
|
+
),
|
|
2001
|
+
),
|
|
2002
|
+
h(
|
|
2003
|
+
Group,
|
|
2004
|
+
{ title: '快捷键', key: 'shortcut' },
|
|
2005
|
+
h(
|
|
2006
|
+
Row,
|
|
2007
|
+
{ label: '启用展开快捷键' },
|
|
2008
|
+
h(Toggle, {
|
|
2009
|
+
label: '启用展开快捷键',
|
|
2010
|
+
checked: value('clipboard.shortcutEnabled', true) === true,
|
|
2011
|
+
onChange: (next) => update('clipboard.shortcutEnabled', next),
|
|
2012
|
+
}),
|
|
2013
|
+
),
|
|
2014
|
+
h(
|
|
2015
|
+
Row,
|
|
2016
|
+
{ label: '展开剪贴板', desc: shortcutNote('clipboard') },
|
|
2017
|
+
h(ShortcutField, {
|
|
2018
|
+
label: '展开剪贴板',
|
|
2019
|
+
value: value('clipboard.shortcut', 'Ctrl+Shift+V'),
|
|
2020
|
+
onChange: (next) => update('clipboard.shortcut', next),
|
|
2021
|
+
}),
|
|
2022
|
+
),
|
|
2023
|
+
),
|
|
2024
|
+
],
|
|
2025
|
+
|
|
2026
|
+
screenshot: () => [
|
|
2027
|
+
h(
|
|
2028
|
+
Group,
|
|
2029
|
+
{ title: '截图', key: 'shot' },
|
|
2030
|
+
h(
|
|
2031
|
+
Row,
|
|
2032
|
+
{ label: '启用截图' },
|
|
2033
|
+
h(Toggle, {
|
|
2034
|
+
label: '启用截图',
|
|
2035
|
+
checked: value('screenshot.enabled', true) === true,
|
|
2036
|
+
onChange: (next) => update('screenshot.enabled', next),
|
|
2037
|
+
}),
|
|
2038
|
+
),
|
|
2039
|
+
h(
|
|
2040
|
+
Row,
|
|
2041
|
+
{
|
|
2042
|
+
label: '截图快捷键',
|
|
2043
|
+
desc: withNote(
|
|
2044
|
+
'默认 Ctrl+Shift+1:Ctrl+Shift+A 是 VibeDev 归档会话的键,别占。',
|
|
2045
|
+
shortcutNote('screenshot'),
|
|
2046
|
+
),
|
|
2047
|
+
},
|
|
2048
|
+
h(ShortcutField, {
|
|
2049
|
+
label: '截图快捷键',
|
|
2050
|
+
value: value('screenshot.shortcut', 'Ctrl+Shift+1'),
|
|
2051
|
+
onChange: (next) => update('screenshot.shortcut', next),
|
|
2052
|
+
}),
|
|
2053
|
+
),
|
|
2054
|
+
),
|
|
2055
|
+
h(
|
|
2056
|
+
Group,
|
|
2057
|
+
{ title: '截完之后', key: 'after' },
|
|
2058
|
+
h(
|
|
2059
|
+
Row,
|
|
2060
|
+
{
|
|
2061
|
+
label: '框选后先标注',
|
|
2062
|
+
desc: '框选或点选之后出一排工具:矩形、箭头、画笔、马赛克,可以撤销;回车、双击或点 ✓ 完成(再按下面的默认动作复制、保存或发给会话),Esc 取消。关掉就是松手即完成。',
|
|
2063
|
+
},
|
|
2064
|
+
h(Toggle, {
|
|
2065
|
+
label: '框选后先标注',
|
|
2066
|
+
checked: value('screenshot.annotate', true) === true,
|
|
2067
|
+
onChange: (next) => update('screenshot.annotate', next),
|
|
2068
|
+
}),
|
|
2069
|
+
),
|
|
2070
|
+
h(
|
|
2071
|
+
Row,
|
|
2072
|
+
{
|
|
2073
|
+
label: '默认动作',
|
|
2074
|
+
desc: '截完总会进剪贴板。「复制并保存」再另存一份 PNG;「发给会话」截完在小岛上选一个 VibeDev 会话,可以附一句话再发。',
|
|
2075
|
+
},
|
|
2076
|
+
h(Select, {
|
|
2077
|
+
label: '默认动作',
|
|
2078
|
+
options: SCREENSHOT_ACTIONS.map(([, label]) => label),
|
|
2079
|
+
value: (SCREENSHOT_ACTIONS.find(([id]) => id === value('screenshot.action', 'copy')) ??
|
|
2080
|
+
SCREENSHOT_ACTIONS[0])[1],
|
|
2081
|
+
onChange: (option) =>
|
|
2082
|
+
update(
|
|
2083
|
+
'screenshot.action',
|
|
2084
|
+
(SCREENSHOT_ACTIONS.find(([, label]) => label === option) ?? SCREENSHOT_ACTIONS[0])[0],
|
|
2085
|
+
),
|
|
2086
|
+
}),
|
|
2087
|
+
),
|
|
2088
|
+
h(
|
|
2089
|
+
Row,
|
|
2090
|
+
{
|
|
2091
|
+
label: '保存目录',
|
|
2092
|
+
desc: '留空用默认目录 %APPDATA%\\com.vibedev.island\\screenshots;回车或点别处生效。',
|
|
2093
|
+
},
|
|
2094
|
+
h(PathInput, {
|
|
2095
|
+
label: '保存目录',
|
|
2096
|
+
value: value('screenshot.saveDirectory', ''),
|
|
2097
|
+
placeholder: '例如 D:\\截图(留空用默认)',
|
|
2098
|
+
onChange: (next) => update('screenshot.saveDirectory', next),
|
|
2099
|
+
}),
|
|
2100
|
+
),
|
|
2101
|
+
),
|
|
2102
|
+
],
|
|
2103
|
+
|
|
2104
|
+
messages: () => [
|
|
2105
|
+
h(
|
|
2106
|
+
Group,
|
|
2107
|
+
{ title: '消息接收', key: 'receive' },
|
|
2108
|
+
h(
|
|
2109
|
+
Row,
|
|
2110
|
+
{ label: 'QQ 通知', desc: '读取 Windows 通知中心里的 QQ 消息。' },
|
|
2111
|
+
h(Toggle, {
|
|
2112
|
+
label: 'QQ 通知',
|
|
2113
|
+
checked: value('messages.qq', true) === true,
|
|
2114
|
+
onChange: (next) => update('messages.qq', next),
|
|
2115
|
+
}),
|
|
2116
|
+
),
|
|
2117
|
+
// QQ 通知要 Windows 授权才能读;状态由岛屿回报,按状态给对应按钮。
|
|
2118
|
+
(() => {
|
|
2119
|
+
const qq = status?.qq
|
|
2120
|
+
const state = qq?.status
|
|
2121
|
+
const label =
|
|
2122
|
+
{
|
|
2123
|
+
listening: '已授权,正在接收',
|
|
2124
|
+
waiting: '等待 QQ 通知',
|
|
2125
|
+
disabled: '已关闭',
|
|
2126
|
+
permissionRequired: '还没授权',
|
|
2127
|
+
permissionDenied: '已被拒绝,需要去系统设置里打开',
|
|
2128
|
+
error: '出错了',
|
|
2129
|
+
}[state] ?? (status?.running === true ? '读取中…' : '岛屿未运行')
|
|
2130
|
+
const needsGrant = state === 'permissionRequired' || state === 'error'
|
|
2131
|
+
const needsSettings = state === 'permissionDenied'
|
|
2132
|
+
return h(
|
|
2133
|
+
Row,
|
|
2134
|
+
{ label: '通知读取权限', desc: qq?.error ? `${label}:${qq.error}` : label },
|
|
2135
|
+
needsGrant
|
|
2136
|
+
? h(
|
|
2137
|
+
'button',
|
|
2138
|
+
{
|
|
2139
|
+
className: 'vdi-btn',
|
|
2140
|
+
type: 'button',
|
|
2141
|
+
disabled: busy,
|
|
2142
|
+
onClick: () => void control('qq-request-access'),
|
|
2143
|
+
},
|
|
2144
|
+
'申请授权',
|
|
2145
|
+
)
|
|
2146
|
+
: needsSettings
|
|
2147
|
+
? h(
|
|
2148
|
+
'button',
|
|
2149
|
+
{
|
|
2150
|
+
className: 'vdi-btn',
|
|
2151
|
+
type: 'button',
|
|
2152
|
+
disabled: busy,
|
|
2153
|
+
onClick: () => void control('qq-open-settings'),
|
|
2154
|
+
},
|
|
2155
|
+
'打开系统设置',
|
|
2156
|
+
)
|
|
2157
|
+
: h('span', { className: 'vdi-info' }, state === 'listening' ? '正常' : '—'),
|
|
2158
|
+
)
|
|
2159
|
+
})(),
|
|
2160
|
+
h(
|
|
2161
|
+
Row,
|
|
2162
|
+
{
|
|
2163
|
+
label: '微信提醒',
|
|
2164
|
+
// 没连上时把原因带出来(比如没找到微信)。
|
|
2165
|
+
desc: ['微信托盘图标闪烁时提醒。', status?.wechat?.summary?.connection].filter(Boolean).join(' '),
|
|
2166
|
+
},
|
|
2167
|
+
h(Toggle, {
|
|
2168
|
+
label: '微信提醒',
|
|
2169
|
+
checked: value('messages.wechat', false) === true,
|
|
2170
|
+
onChange: (next) => update('messages.wechat', next),
|
|
2171
|
+
}),
|
|
2172
|
+
),
|
|
2173
|
+
// 下面两项只在微信提醒开着时有意义;第二项只在第一项开着时有意义。
|
|
2174
|
+
...(value('messages.wechat', false) === true
|
|
2175
|
+
? [
|
|
2176
|
+
h(
|
|
2177
|
+
Row,
|
|
2178
|
+
{
|
|
2179
|
+
key: 'wechat-details',
|
|
2180
|
+
label: '显示联系人和消息内容',
|
|
2181
|
+
desc:
|
|
2182
|
+
'默认只知道微信有新消息。打开后,小岛会把正在运行的微信里控制辅助功能的一个字节从 0 改成 1,' +
|
|
2183
|
+
'微信就像开着读屏软件一样公开界面,这样才读得到会话列表里是谁、说了什么,点提醒还能直接进那个聊天。' +
|
|
2184
|
+
'只改内存:关掉这个开关或退出小岛时改回,微信重启后会再改一次。' +
|
|
2185
|
+
'这不是微信公开支持的做法:微信会多占一些 CPU 和内存,安全软件可能拦截,腾讯也可能把它当成异常行为。',
|
|
2186
|
+
},
|
|
2187
|
+
h(Toggle, {
|
|
2188
|
+
label: '显示联系人和消息内容',
|
|
2189
|
+
checked: value('messages.wechatDetails', false) === true,
|
|
2190
|
+
onChange: (next) => update('messages.wechatDetails', next),
|
|
2191
|
+
}),
|
|
2192
|
+
),
|
|
2193
|
+
...(value('messages.wechatDetails', false) === true
|
|
2194
|
+
? [
|
|
2195
|
+
h(
|
|
2196
|
+
Row,
|
|
2197
|
+
{
|
|
2198
|
+
key: 'wechat-details-state',
|
|
2199
|
+
label: '读取状态',
|
|
2200
|
+
desc: status?.wechat?.summary?.details ?? '正在读取…',
|
|
2201
|
+
},
|
|
2202
|
+
h('span', { className: 'vdi-info' }, status?.wechat?.exposeStatus ? '见说明' : '—'),
|
|
2203
|
+
),
|
|
2204
|
+
h(
|
|
2205
|
+
Row,
|
|
2206
|
+
{
|
|
2207
|
+
key: 'wechat-hide-taskbar',
|
|
2208
|
+
label: '微信最小化时不占任务栏',
|
|
2209
|
+
desc:
|
|
2210
|
+
'建议打开。微信关进托盘后读不到会话列表,最小化才读得到。打开后,最小化的微信不显示任务栏按钮,' +
|
|
2211
|
+
'看起来和关进托盘一样;从托盘或提醒里打开微信时按钮会回来。所以请用最小化代替关闭。',
|
|
2212
|
+
},
|
|
2213
|
+
h(Toggle, {
|
|
2214
|
+
label: '微信最小化时不占任务栏',
|
|
2215
|
+
checked: value('messages.wechatHideTaskbar', false) === true,
|
|
2216
|
+
onChange: (next) => update('messages.wechatHideTaskbar', next),
|
|
2217
|
+
}),
|
|
2218
|
+
),
|
|
2219
|
+
]
|
|
2220
|
+
: NO_EVENTS),
|
|
2221
|
+
]
|
|
2222
|
+
: NO_EVENTS),
|
|
2223
|
+
),
|
|
2224
|
+
h(
|
|
2225
|
+
Group,
|
|
2226
|
+
{ title: '邮箱', key: 'mail' },
|
|
2227
|
+
infoRow(
|
|
2228
|
+
'QQ 邮箱',
|
|
2229
|
+
'在岛屿上连接',
|
|
2230
|
+
'账号和授权码在岛屿的「消息」页里填写,授权码保存在 Windows 凭据管理器里。',
|
|
2231
|
+
),
|
|
2232
|
+
),
|
|
2233
|
+
h(
|
|
2234
|
+
Group,
|
|
2235
|
+
{ title: '新消息', key: 'new', desc: '新消息在岛上怎么出现。' },
|
|
2236
|
+
h(
|
|
2237
|
+
Row,
|
|
2238
|
+
{
|
|
2239
|
+
label: '提示方式',
|
|
2240
|
+
desc:
|
|
2241
|
+
'一行:折叠条上显示发件人和内容。横幅:在折叠的小岛下面出一张卡片,带时间,一会儿自己收回去。' +
|
|
2242
|
+
'面板:直接展开到消息页。',
|
|
2243
|
+
},
|
|
2244
|
+
h(Segmented, {
|
|
2245
|
+
label: '提示方式',
|
|
2246
|
+
options: NOTICE_CHOICES.map((id) => NOTICE_LABELS[id]),
|
|
2247
|
+
value: NOTICE_LABELS[value('messages.notice', 'line')] ?? NOTICE_LABELS.line,
|
|
2248
|
+
onChange: (label) =>
|
|
2249
|
+
update('messages.notice', NOTICE_CHOICES.find((id) => NOTICE_LABELS[id] === label) ?? 'line'),
|
|
2250
|
+
}),
|
|
2251
|
+
),
|
|
2252
|
+
// 停留时间只对横幅有意义:选了别的方式就不放这一行。
|
|
2253
|
+
value('messages.notice', 'line') === 'banner'
|
|
2254
|
+
? h(
|
|
2255
|
+
Row,
|
|
2256
|
+
{ label: '横幅停留时间', desc: '鼠标停在横幅上时不计时,移开后重新走满。' },
|
|
2257
|
+
h(NumberInput, {
|
|
2258
|
+
label: '横幅停留时间',
|
|
2259
|
+
value: value('messages.bannerSeconds', 5),
|
|
2260
|
+
unit: '秒',
|
|
2261
|
+
min: 2,
|
|
2262
|
+
max: 15,
|
|
2263
|
+
onChange: (next) => update('messages.bannerSeconds', next),
|
|
2264
|
+
}),
|
|
2265
|
+
)
|
|
2266
|
+
: null,
|
|
2267
|
+
),
|
|
2268
|
+
],
|
|
2269
|
+
|
|
2270
|
+
translation: () => [
|
|
2271
|
+
h(
|
|
2272
|
+
Group,
|
|
2273
|
+
{ title: '翻译选中的文字', key: 'selection' },
|
|
2274
|
+
h(
|
|
2275
|
+
Row,
|
|
2276
|
+
{
|
|
2277
|
+
label: '翻译选中的文字',
|
|
2278
|
+
desc:
|
|
2279
|
+
'选中一段外文,把鼠标移到小岛上,展开的小岛最上面会出现「翻译」按钮,点一下在小岛下面打开译文;' +
|
|
2280
|
+
`选着文字按 ${value('translation.shortcut', 'Ctrl+Alt+T')} 也会直接翻译它。标题、列表、代码块和表格照原样排版。` +
|
|
2281
|
+
'选中的文字只留在本机内存里,点了翻译才发给翻译服务。',
|
|
2282
|
+
},
|
|
2283
|
+
h(Toggle, {
|
|
2284
|
+
label: '翻译选中的文字',
|
|
2285
|
+
checked: value('translation.selection', true) === true,
|
|
2286
|
+
onChange: (next) => update('translation.selection', next),
|
|
2287
|
+
}),
|
|
2288
|
+
),
|
|
2289
|
+
h(
|
|
2290
|
+
Row,
|
|
2291
|
+
{
|
|
2292
|
+
label: '也读取其它应用里选中的文字',
|
|
2293
|
+
dim: value('translation.selection', true) !== true,
|
|
2294
|
+
desc:
|
|
2295
|
+
'VibeDev 里选中的文字直接就能读到。其它应用要经 Windows 的无障碍接口去问:只读,不碰剪贴板、不模拟按键,密码框不读。' +
|
|
2296
|
+
'浏览器、VS Code 这类程序被这样问过之后会打开自己的无障碍支持,可能多占一些内存,所以默认关闭。' +
|
|
2297
|
+
'关着时,在其它应用里先复制(Ctrl+C),再把鼠标移到小岛上,也会出现翻译按钮。',
|
|
2298
|
+
},
|
|
2299
|
+
h(Toggle, {
|
|
2300
|
+
label: '也读取其它应用里选中的文字',
|
|
2301
|
+
checked: value('translation.readOtherApps', false) === true,
|
|
2302
|
+
disabled: value('translation.selection', true) !== true,
|
|
2303
|
+
onChange: (next) => update('translation.readOtherApps', next),
|
|
2304
|
+
}),
|
|
2305
|
+
),
|
|
2306
|
+
),
|
|
2307
|
+
h(
|
|
2308
|
+
Group,
|
|
2309
|
+
{ title: '翻译服务', key: 'service' },
|
|
2310
|
+
h(
|
|
2311
|
+
Row,
|
|
2312
|
+
{
|
|
2313
|
+
label: '翻译面板',
|
|
2314
|
+
desc:
|
|
2315
|
+
`没选文字时按 ${value('translation.shortcut', 'Ctrl+Alt+T')} 打开翻译面板:可以直接打字,或按 Tab 填入刚复制的内容,回车翻译。` +
|
|
2316
|
+
'小岛展开后右上角的「文」字按钮也能打开它。',
|
|
2317
|
+
},
|
|
2318
|
+
h(
|
|
2319
|
+
'button',
|
|
2320
|
+
{
|
|
2321
|
+
className: 'vdi-btn',
|
|
2322
|
+
type: 'button',
|
|
2323
|
+
disabled: busy || status?.running !== true,
|
|
2324
|
+
onClick: () => void control('open-translation'),
|
|
2325
|
+
},
|
|
2326
|
+
'打开翻译面板',
|
|
2327
|
+
),
|
|
2328
|
+
),
|
|
2329
|
+
h(
|
|
2330
|
+
Row,
|
|
2331
|
+
{
|
|
2332
|
+
label: '服务',
|
|
2333
|
+
desc:
|
|
2334
|
+
status?.translation?.available === false
|
|
2335
|
+
? 'VibeDev 的翻译服务现在不可用。如果你在翻译面板里存了自己的 DeepSeek 密钥(面板左下角的钥匙),会改用它。'
|
|
2336
|
+
: '翻译走 VibeDev 的翻译服务,不需要密钥。它连不上时,如果你在翻译面板里存了自己的 DeepSeek 密钥(面板左下角的钥匙),会改用它。',
|
|
2337
|
+
},
|
|
2338
|
+
h(
|
|
2339
|
+
'span',
|
|
2340
|
+
{ className: 'vdi-info' },
|
|
2341
|
+
status?.translation?.available === false ? '不可用' : 'VibeDev 翻译',
|
|
2342
|
+
),
|
|
2343
|
+
),
|
|
2344
|
+
h(
|
|
2345
|
+
Row,
|
|
2346
|
+
{
|
|
2347
|
+
label: '翻译通道',
|
|
2348
|
+
desc: '小岛上的翻译不属于任何会话,只能用不需要会话的通道。某个通道连不上时换另一个试试。',
|
|
2349
|
+
},
|
|
2350
|
+
h(Select, {
|
|
2351
|
+
label: '翻译通道',
|
|
2352
|
+
options: TRANSLATION_CHOICES.map((id) => TRANSLATION_LABELS[id]),
|
|
2353
|
+
value: TRANSLATION_LABELS[value('translation.provider', 'auto')] ?? TRANSLATION_LABELS.auto,
|
|
2354
|
+
onChange: (label) =>
|
|
2355
|
+
update(
|
|
2356
|
+
'translation.provider',
|
|
2357
|
+
TRANSLATION_CHOICES.find((id) => TRANSLATION_LABELS[id] === label) ?? 'auto',
|
|
2358
|
+
),
|
|
2359
|
+
}),
|
|
2360
|
+
),
|
|
2361
|
+
h(
|
|
2362
|
+
Row,
|
|
2363
|
+
{ label: '测试一下', desc: translationTestNote(status?.translation?.test) },
|
|
2364
|
+
h(
|
|
2365
|
+
'button',
|
|
2366
|
+
{
|
|
2367
|
+
className: 'vdi-btn',
|
|
2368
|
+
type: 'button',
|
|
2369
|
+
disabled: busy || status?.translation?.available === false,
|
|
2370
|
+
onClick: () => void control('translate-test'),
|
|
2371
|
+
},
|
|
2372
|
+
busy ? '翻译中…' : '翻译一句试试',
|
|
2373
|
+
),
|
|
2374
|
+
),
|
|
2375
|
+
h(
|
|
2376
|
+
Row,
|
|
2377
|
+
{ label: '快捷键', desc: shortcutNote('translation') },
|
|
2378
|
+
h(ShortcutField, {
|
|
2379
|
+
label: '翻译快捷键',
|
|
2380
|
+
value: value('translation.shortcut', 'Ctrl+Alt+T'),
|
|
2381
|
+
onChange: (next) => update('translation.shortcut', next),
|
|
2382
|
+
}),
|
|
2383
|
+
),
|
|
2384
|
+
),
|
|
2385
|
+
],
|
|
2386
|
+
|
|
2387
|
+
about: () => [
|
|
2388
|
+
h(
|
|
2389
|
+
Group,
|
|
2390
|
+
{ title: '版本', key: 'version' },
|
|
2391
|
+
infoRow('小岛', status?.version ?? '—'),
|
|
2392
|
+
infoRow(
|
|
2393
|
+
'插件',
|
|
2394
|
+
status?.pluginVersion === undefined ? PACKAGE_NAME : `${PACKAGE_NAME} ${status.pluginVersion}`,
|
|
2395
|
+
),
|
|
2396
|
+
infoRow('协议版本', status?.protocol === undefined ? '—' : String(status.protocol)),
|
|
2397
|
+
),
|
|
2398
|
+
h(Group, { title: '更新记录', key: 'changelog' }, h(Changelog, { initial: props?.initialChangelog })),
|
|
2399
|
+
h(
|
|
2400
|
+
Group,
|
|
2401
|
+
{ title: '数据', key: 'data' },
|
|
2402
|
+
h(
|
|
2403
|
+
Row,
|
|
2404
|
+
{ label: '设置文件', desc: '设置由 VibeDev 持有,岛屿只在内存里使用。' },
|
|
2405
|
+
h(PathInput, {
|
|
2406
|
+
label: '设置文件',
|
|
2407
|
+
value: status?.settingsPath ?? '%APPDATA%/VibeDev/island-settings.json',
|
|
2408
|
+
}),
|
|
2409
|
+
),
|
|
2410
|
+
h(
|
|
2411
|
+
Row,
|
|
2412
|
+
{ label: '数据目录', desc: '待办、笔记和归档。' },
|
|
2413
|
+
h(PathInput, { label: '数据目录', value: '%APPDATA%/com.vibedev.island/data' }),
|
|
2414
|
+
),
|
|
2415
|
+
h(
|
|
2416
|
+
Row,
|
|
2417
|
+
{
|
|
2418
|
+
label: '恢复默认设置',
|
|
2419
|
+
desc: '外观、行为和各功能的设置回到默认值,快捷键也会回到默认。存下来的样式预设保留;待办、笔记和剪贴板历史不受影响。',
|
|
2420
|
+
},
|
|
2421
|
+
h(ConfirmButton, {
|
|
2422
|
+
label: '恢复默认设置',
|
|
2423
|
+
confirmLabel: '再点一次确认',
|
|
2424
|
+
disabled: busy,
|
|
2425
|
+
onConfirm: () => void resetSettings(),
|
|
2426
|
+
}),
|
|
2427
|
+
),
|
|
2428
|
+
),
|
|
2429
|
+
h(
|
|
2430
|
+
Group,
|
|
2431
|
+
{ title: '诊断', key: 'diagnostics' },
|
|
2432
|
+
h(
|
|
2433
|
+
Row,
|
|
2434
|
+
{
|
|
2435
|
+
label: '导出诊断信息',
|
|
2436
|
+
desc:
|
|
2437
|
+
status?.diagnosticsPath === undefined
|
|
2438
|
+
? '把版本、WebView2、各项状态、设置和最近 200 行日志写进一个文本文件,在资源管理器里选中它。日志里可能有会话标题,发给别人前看一眼;密钥不在里面。'
|
|
2439
|
+
: `已导出:${status.diagnosticsPath}`,
|
|
2440
|
+
},
|
|
2441
|
+
h(
|
|
2442
|
+
'button',
|
|
2443
|
+
{
|
|
2444
|
+
className: 'vdi-btn',
|
|
2445
|
+
type: 'button',
|
|
2446
|
+
disabled: busy,
|
|
2447
|
+
onClick: () => void control('export-diagnostics'),
|
|
2448
|
+
},
|
|
2449
|
+
'导出',
|
|
2450
|
+
),
|
|
2451
|
+
),
|
|
2452
|
+
),
|
|
2453
|
+
h(
|
|
2454
|
+
Group,
|
|
2455
|
+
{ title: '许可与致谢', key: 'license' },
|
|
2456
|
+
infoRow('小岛', 'MIT', '基于 fly-island(flyl1u,MIT)改造。'),
|
|
2457
|
+
h(Row, { label: '第三方许可' }, null),
|
|
2458
|
+
h(ThirdParty, null),
|
|
2459
|
+
),
|
|
2460
|
+
],
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
const active = sections[section] ?? sections.overview
|
|
2464
|
+
const titles = {
|
|
2465
|
+
overview: '概览',
|
|
2466
|
+
appearance: '外观',
|
|
2467
|
+
behavior: '行为',
|
|
2468
|
+
pages: '岛上页面',
|
|
2469
|
+
sessions: 'VibeDev 会话',
|
|
2470
|
+
todos: '待办',
|
|
2471
|
+
clipboard: '剪贴板',
|
|
2472
|
+
screenshot: '截图',
|
|
2473
|
+
messages: '消息',
|
|
2474
|
+
translation: '翻译',
|
|
2475
|
+
about: '关于',
|
|
2476
|
+
}
|
|
2477
|
+
const descriptions = {
|
|
2478
|
+
overview: '岛屿的运行状态。岛屿是独立的原生程序,只能由本插件拉起,不能单独运行。',
|
|
2479
|
+
appearance: '小岛的样子,改动实时生效。',
|
|
2480
|
+
behavior: '什么时候展开、收起,以及什么时候保持安静。',
|
|
2481
|
+
pages: '展开后能看到哪些页、按什么顺序。',
|
|
2482
|
+
sessions: '把 VibeDev 会话的状态放到小岛上,有审批和提问时提醒你。',
|
|
2483
|
+
todos: '待办、每日笔记和归档。',
|
|
2484
|
+
clipboard: '图文剪贴板历史。',
|
|
2485
|
+
screenshot: '快捷键框选截图:可以点选窗口和控件,也可以拖出任意区域。',
|
|
2486
|
+
messages: 'QQ、微信和邮箱的新消息。',
|
|
2487
|
+
translation: '选中文字后把鼠标移到小岛上,或者按快捷键,就能翻译;标题、列表、代码块照原样排版。',
|
|
2488
|
+
about: '',
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
return h(
|
|
2492
|
+
'div',
|
|
2493
|
+
{ className: 'vdi' },
|
|
2494
|
+
h('style', null, CSS),
|
|
2495
|
+
h(
|
|
2496
|
+
'nav',
|
|
2497
|
+
{ className: 'vdi__nav', 'aria-label': '设置分区' },
|
|
2498
|
+
SECTIONS.map((item) =>
|
|
2499
|
+
h(
|
|
2500
|
+
'button',
|
|
2501
|
+
{
|
|
2502
|
+
key: item.id,
|
|
2503
|
+
type: 'button',
|
|
2504
|
+
'aria-current': item.id === section ? 'true' : 'false',
|
|
2505
|
+
onClick: () => setSection(item.id),
|
|
2506
|
+
},
|
|
2507
|
+
h(Icon, { name: item.icon }),
|
|
2508
|
+
h('span', null, item.title),
|
|
2509
|
+
),
|
|
2510
|
+
),
|
|
2511
|
+
),
|
|
2512
|
+
h(
|
|
2513
|
+
'div',
|
|
2514
|
+
{ className: 'vdi__body' },
|
|
2515
|
+
h('h2', { className: 'vdi__title' }, titles[section] ?? '概览'),
|
|
2516
|
+
descriptions[section] ? h('p', { className: 'vdi__desc' }, descriptions[section]) : null,
|
|
2517
|
+
ready ? active() : h('div', { className: 'vdi-status__meta', style: { marginTop: 12 } }, '正在读取设置…'),
|
|
2518
|
+
error === undefined ? null : h('div', { className: 'vdi-error' }, error),
|
|
2519
|
+
),
|
|
2520
|
+
)
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
/* ------------------------------------------------------ 来自岛屿的动作 */
|
|
2524
|
+
|
|
2525
|
+
/**
|
|
2526
|
+
* 发送到会话:取岛屿要发的内容,用会话自己的接口发出去(会话正在跑时排在后面)。
|
|
2527
|
+
* 别的 VibeDev 窗口已经取走发了时返回 `{ skipped: true }`。
|
|
2528
|
+
*/
|
|
2529
|
+
async function sendToSession(event) {
|
|
2530
|
+
const sessions = sessionsOf()
|
|
2531
|
+
if (typeof sessions?.using !== 'function') throw new Error('页面没有 sessions 服务,发不出去。')
|
|
2532
|
+
let entry
|
|
2533
|
+
try {
|
|
2534
|
+
entry = await readJson(`${OUTBOX_URL}?id=${encodeURIComponent(String(event.outbox))}`)
|
|
2535
|
+
} catch (cause) {
|
|
2536
|
+
if (String(cause?.message ?? cause).includes('Nothing to send')) return { skipped: true }
|
|
2537
|
+
throw cause
|
|
2538
|
+
}
|
|
2539
|
+
const parts = []
|
|
2540
|
+
if (typeof entry?.text === 'string' && entry.text !== '') parts.push({ type: 'text', text: entry.text })
|
|
2541
|
+
if (entry?.image !== undefined && entry.image !== null) {
|
|
2542
|
+
parts.push({ type: 'image', mediaType: entry.image.mediaType, data: entry.image.data, name: entry.image.name })
|
|
2543
|
+
}
|
|
2544
|
+
if (parts.length === 0) throw new Error('没有要发送的内容。')
|
|
2545
|
+
await sessions.using(event.sessionId, { source: 'controllerOperation' }, async (reference) => {
|
|
2546
|
+
const binding = await reference.ready
|
|
2547
|
+
const result = await binding.session.prompt(parts, 'queue')
|
|
2548
|
+
if (result?.ok === false) throw new Error(result.error?.message ?? '会话没有收下这条消息。')
|
|
2549
|
+
})
|
|
2550
|
+
return undefined
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
/** 执行宿主转来的一个动作;做不成就抛出原因。返回 `{ skipped: true }` 表示这件事轮不到这个页面做。 */
|
|
2554
|
+
async function performPageEvent(event) {
|
|
2555
|
+
if (event.type === 'send-to-session') return sendToSession(event)
|
|
2556
|
+
if (event.type === 'open-session') {
|
|
2557
|
+
const workspace = workspaceOf()
|
|
2558
|
+
if (typeof workspace?.openSession !== 'function') throw new Error('页面没有 uiWorkspace 服务,打不开会话。')
|
|
2559
|
+
workspace.openSession(event.sessionId)
|
|
2560
|
+
return
|
|
2561
|
+
}
|
|
2562
|
+
if (event.type === 'open-settings') {
|
|
2563
|
+
// 插件管理页是主区域里键为 plugins 的面板;layout.selectPanel 是宿主给的正式入口。
|
|
2564
|
+
// 再往里直接打开某个插件的详情页没有正式接口,所以只切到插件页。
|
|
2565
|
+
const layout = layoutOf()
|
|
2566
|
+
if (typeof layout?.selectPanel !== 'function') throw new Error('页面没有 layout 服务,切不到插件页。')
|
|
2567
|
+
layout.selectPanel(event.panel ?? 'plugins')
|
|
2568
|
+
return
|
|
2569
|
+
}
|
|
2570
|
+
throw new Error(`Unknown page event: ${String(event.type)}`)
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
/**
|
|
2574
|
+
* 岛屿在浏览器外面,它的「去处理」要绕到宿主再回到页面:页面保持一个长轮询,
|
|
2575
|
+
* 宿主有事就立刻回。返回停止函数。
|
|
2576
|
+
*/
|
|
2577
|
+
function watchPageEvents() {
|
|
2578
|
+
const controller = new AbortController()
|
|
2579
|
+
let after = -1
|
|
2580
|
+
let retryMs = EVENTS_RETRY_MS
|
|
2581
|
+
const loop = async () => {
|
|
2582
|
+
while (!controller.signal.aborted) {
|
|
2583
|
+
try {
|
|
2584
|
+
const answer = await readJson(`${EVENTS_URL}?after=${after}`, { signal: controller.signal })
|
|
2585
|
+
retryMs = EVENTS_RETRY_MS
|
|
2586
|
+
if (typeof answer?.seq === 'number') after = answer.seq
|
|
2587
|
+
for (const event of Array.isArray(answer?.events) ? answer.events : NO_EVENTS) {
|
|
2588
|
+
const outcome = { seq: event.seq, type: event.type, ok: true }
|
|
2589
|
+
try {
|
|
2590
|
+
const result = await performPageEvent(event)
|
|
2591
|
+
if (result?.skipped === true) {
|
|
2592
|
+
outcome.ok = false
|
|
2593
|
+
outcome.skipped = true
|
|
2594
|
+
}
|
|
2595
|
+
} catch (cause) {
|
|
2596
|
+
outcome.ok = false
|
|
2597
|
+
outcome.error = String(cause?.message ?? cause)
|
|
2598
|
+
}
|
|
2599
|
+
// 回报给宿主,日志里才看得出这一下到底有没有跳过去。
|
|
2600
|
+
void postJson(EVENTS_URL, outcome).catch(() => undefined)
|
|
2601
|
+
}
|
|
2602
|
+
} catch {
|
|
2603
|
+
if (controller.signal.aborted) return
|
|
2604
|
+
// 宿主在重启或插件被停用:等一会儿再问,一直不通就问得越来越慢。
|
|
2605
|
+
await new Promise((resolve) => setTimeout(resolve, retryMs))
|
|
2606
|
+
retryMs = Math.min(retryMs * 2, EVENTS_RETRY_MAX_MS)
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
void loop()
|
|
2611
|
+
return () => controller.abort()
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
/* ------------------------------------------------------ VibeDev 的深浅 */
|
|
2615
|
+
|
|
2616
|
+
/**
|
|
2617
|
+
* VibeDev 现在是深色还是浅色,报给宿主:小岛设成「跟随 VibeDev」时照着变。
|
|
2618
|
+
* 主题服务可能比本插件晚就绪(那时 `ctx.get('theme')` 还是 undefined,页面一加载就报的那一次会丢),
|
|
2619
|
+
* 所以经 `ctx.inject(['theme'], …)` 等它就绪再开始;那个上下文卸载时,变化事件的监听跟着撤掉。
|
|
2620
|
+
*/
|
|
2621
|
+
function watchTheme(themed) {
|
|
2622
|
+
let wanted
|
|
2623
|
+
let attempts = 0
|
|
2624
|
+
let timer
|
|
2625
|
+
const send = () => {
|
|
2626
|
+
timer = undefined
|
|
2627
|
+
const scheme = wanted
|
|
2628
|
+
void postJson(THEME_URL, { scheme }).catch(() => {
|
|
2629
|
+
// 宿主还没起来(插件刚重启时页面这一半先好):过一会儿再报,别让小岛一直用错的深浅。
|
|
2630
|
+
if (scheme !== wanted || attempts >= THEME_RETRIES) return
|
|
2631
|
+
attempts += 1
|
|
2632
|
+
timer = setTimeout(send, THEME_RETRY_MS)
|
|
2633
|
+
})
|
|
2634
|
+
}
|
|
2635
|
+
const report = (snapshot) => {
|
|
2636
|
+
const scheme = snapshot?.active?.colorScheme
|
|
2637
|
+
if ((scheme !== 'light' && scheme !== 'dark') || scheme === wanted) return
|
|
2638
|
+
wanted = scheme
|
|
2639
|
+
attempts = 0
|
|
2640
|
+
clearTimeout(timer)
|
|
2641
|
+
send()
|
|
2642
|
+
}
|
|
2643
|
+
report(themed.theme.getTheme())
|
|
2644
|
+
themed.on('theme/change', report)
|
|
2645
|
+
themed.effect(() => () => clearTimeout(timer))
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
/* ------------------------------------------------------ 选中的文字 */
|
|
2649
|
+
|
|
2650
|
+
/**
|
|
2651
|
+
* 页面里选中的文字报给宿主:鼠标移到小岛上时,岛屿据此给出「翻译」按钮。
|
|
2652
|
+
* 选区停稳了才报、没变不报;文字和它的网页格式只经过本机内存。返回停止函数。
|
|
2653
|
+
*/
|
|
2654
|
+
function watchSelection() {
|
|
2655
|
+
// 服务端渲染(测试)里没有页面。
|
|
2656
|
+
if (typeof document === 'undefined') return () => undefined
|
|
2657
|
+
// 拖着选的时候不一路报:停下来这么久再报。
|
|
2658
|
+
const SETTLE_MS = 250
|
|
2659
|
+
const MAX_CHARS = 20_000
|
|
2660
|
+
const MAX_HTML = 400_000
|
|
2661
|
+
// 宿主说「不用报了」(设置关着)之后,隔这么久再问一次。
|
|
2662
|
+
const RECHECK_MS = 60_000
|
|
2663
|
+
// 只拿到一截时,用外层的这些结构把它包回去:代码块、列表、引用、标题。
|
|
2664
|
+
const CONTEXT = new Set(['PRE', 'CODE', 'UL', 'OL', 'LI', 'BLOCKQUOTE', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6'])
|
|
2665
|
+
// 选区跨了几格时,表格的结构也补回去;只选了一格里的字不当表格。
|
|
2666
|
+
const TABLE = new Set(['TABLE', 'THEAD', 'TBODY', 'TR'])
|
|
2667
|
+
// 往外找结构时到这些容器为止:再往外就不是这段内容自己的结构了。
|
|
2668
|
+
const STOP = new Set([
|
|
2669
|
+
'DIV',
|
|
2670
|
+
'SECTION',
|
|
2671
|
+
'ARTICLE',
|
|
2672
|
+
'MAIN',
|
|
2673
|
+
'ASIDE',
|
|
2674
|
+
'NAV',
|
|
2675
|
+
'HEADER',
|
|
2676
|
+
'FOOTER',
|
|
2677
|
+
'BODY',
|
|
2678
|
+
'TD',
|
|
2679
|
+
'TH',
|
|
2680
|
+
])
|
|
2681
|
+
// 同一页面的几次报告用同一个编号:开着几个窗口时,宿主据此分清是谁的选区。
|
|
2682
|
+
const page = Math.random().toString(36).slice(2)
|
|
2683
|
+
let timer
|
|
2684
|
+
let last = ''
|
|
2685
|
+
let pausedUntil = 0
|
|
2686
|
+
|
|
2687
|
+
const htmlOf = (selection) => {
|
|
2688
|
+
const holder = document.createElement('div')
|
|
2689
|
+
for (let index = 0; index < selection.rangeCount; index += 1) {
|
|
2690
|
+
const range = selection.getRangeAt(index)
|
|
2691
|
+
let content = range.cloneContents()
|
|
2692
|
+
let node = range.commonAncestorContainer
|
|
2693
|
+
if (node.nodeType !== 1) node = node.parentElement
|
|
2694
|
+
const spansCells = node !== null && TABLE.has(node.nodeName)
|
|
2695
|
+
for (let depth = 0; node !== null && depth < 8 && !STOP.has(node.nodeName); depth += 1) {
|
|
2696
|
+
if (CONTEXT.has(node.nodeName) || (spansCells && TABLE.has(node.nodeName))) {
|
|
2697
|
+
const shell = node.cloneNode(false)
|
|
2698
|
+
shell.appendChild(content)
|
|
2699
|
+
content = shell
|
|
2700
|
+
}
|
|
2701
|
+
node = node.parentElement
|
|
2702
|
+
}
|
|
2703
|
+
holder.appendChild(content)
|
|
2704
|
+
}
|
|
2705
|
+
const html = holder.innerHTML
|
|
2706
|
+
return html.length <= MAX_HTML ? html : undefined
|
|
2707
|
+
}
|
|
2708
|
+
|
|
2709
|
+
// 输入框里选中的字不在页面的选区里,单独读;密码框不读。
|
|
2710
|
+
const fieldText = () => {
|
|
2711
|
+
const field = document.activeElement
|
|
2712
|
+
const editable =
|
|
2713
|
+
field?.tagName === 'TEXTAREA' ||
|
|
2714
|
+
(field?.tagName === 'INPUT' && ['text', 'search', 'url'].includes(field.type))
|
|
2715
|
+
if (!editable) return undefined
|
|
2716
|
+
const { selectionStart: start, selectionEnd: end } = field
|
|
2717
|
+
return typeof start === 'number' && typeof end === 'number' && end > start
|
|
2718
|
+
? field.value.slice(start, end)
|
|
2719
|
+
: undefined
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2722
|
+
const report = (body) => {
|
|
2723
|
+
if (Date.now() < pausedUntil) return
|
|
2724
|
+
void postJson(SELECTION_URL, { page, ...body })
|
|
2725
|
+
.then((answer) => {
|
|
2726
|
+
if (answer?.wanted === false) pausedUntil = Date.now() + RECHECK_MS
|
|
2727
|
+
})
|
|
2728
|
+
.catch(() => undefined)
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
const read = () => {
|
|
2732
|
+
timer = undefined
|
|
2733
|
+
const selection = document.getSelection()
|
|
2734
|
+
const field = fieldText()
|
|
2735
|
+
const text = field ?? (selection === null ? '' : selection.toString())
|
|
2736
|
+
if (text.trim() === '') {
|
|
2737
|
+
if (last === '') return
|
|
2738
|
+
last = ''
|
|
2739
|
+
report({ text: '', focused: document.hasFocus() })
|
|
2740
|
+
return
|
|
2741
|
+
}
|
|
2742
|
+
if (text === last) return
|
|
2743
|
+
last = text
|
|
2744
|
+
const rich = field === undefined && selection !== null && selection.rangeCount > 0 && text.length <= MAX_CHARS
|
|
2745
|
+
report({ text, html: rich ? htmlOf(selection) : undefined, focused: document.hasFocus() })
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
const schedule = () => {
|
|
2749
|
+
window.clearTimeout(timer)
|
|
2750
|
+
timer = window.setTimeout(read, SETTLE_MS)
|
|
2751
|
+
}
|
|
2752
|
+
// 切到别的程序、又切回来:选区没变,告诉宿主页面还是不是用户正看着的那个。
|
|
2753
|
+
const focusChanged = () => {
|
|
2754
|
+
if (last !== '') report({ focused: document.hasFocus() })
|
|
2755
|
+
}
|
|
2756
|
+
// 页面要关了:清掉它报过的选区。keepalive 让请求在页面卸载后还能发出去。
|
|
2757
|
+
const closing = () => {
|
|
2758
|
+
if (last === '') return
|
|
2759
|
+
last = ''
|
|
2760
|
+
void fetch(SELECTION_URL, {
|
|
2761
|
+
method: 'POST',
|
|
2762
|
+
keepalive: true,
|
|
2763
|
+
headers: { 'content-type': 'application/json' },
|
|
2764
|
+
body: JSON.stringify({ page, text: '' }),
|
|
2765
|
+
}).catch(() => undefined)
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
document.addEventListener('selectionchange', schedule)
|
|
2769
|
+
window.addEventListener('focus', focusChanged)
|
|
2770
|
+
window.addEventListener('blur', focusChanged)
|
|
2771
|
+
window.addEventListener('pagehide', closing)
|
|
2772
|
+
return () => {
|
|
2773
|
+
document.removeEventListener('selectionchange', schedule)
|
|
2774
|
+
window.removeEventListener('focus', focusChanged)
|
|
2775
|
+
window.removeEventListener('blur', focusChanged)
|
|
2776
|
+
window.removeEventListener('pagehide', closing)
|
|
2777
|
+
window.clearTimeout(timer)
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
return {
|
|
2782
|
+
name: 'dsh-island-settings',
|
|
2783
|
+
inject: ['slots'],
|
|
2784
|
+
// 不依赖页面的纯函数,挂出来给测试直接调(服务端渲染测不到点击)。
|
|
2785
|
+
internals: { movePage, setPageShown },
|
|
2786
|
+
apply(ctx) {
|
|
2787
|
+
workspaceOf = () => ctx.get('uiWorkspace')
|
|
2788
|
+
sessionsOf = () => ctx.get('sessions')
|
|
2789
|
+
layoutOf = () => ctx.get('layout')
|
|
2790
|
+
// 页面一加载就开始等「去处理」,不依赖有没有人打开插件页。
|
|
2791
|
+
ctx.effect(() => watchPageEvents())
|
|
2792
|
+
// 选中的文字报给宿主(翻译用);设置关着时宿主会让它停下。
|
|
2793
|
+
ctx.effect(() => watchSelection())
|
|
2794
|
+
// VibeDev 的深浅报给宿主(小岛「跟随 VibeDev」时用):主题服务就绪了才开始。
|
|
2795
|
+
ctx.inject(['theme'], (themed) => watchTheme(themed))
|
|
2796
|
+
ctx.slots.inject('plugins.bundle.config', () =>
|
|
2797
|
+
ctx.slots.register({ name: 'plugins.bundle.config', key: PACKAGE_NAME }, IslandSettingsPage),
|
|
2798
|
+
)
|
|
2799
|
+
// 页头:标题旁的状态标签,和「重启 / 启动」按钮。
|
|
2800
|
+
ctx.slots.inject('plugins.detail.badge', () =>
|
|
2801
|
+
ctx.slots.register({ name: 'plugins.detail.badge', id: 'dsh-island-state' }, HeaderBadge),
|
|
2802
|
+
)
|
|
2803
|
+
ctx.slots.inject('plugins.detail.actions', () =>
|
|
2804
|
+
ctx.slots.register({ name: 'plugins.detail.actions', id: 'dsh-island-control' }, HeaderActions),
|
|
2805
|
+
)
|
|
2806
|
+
},
|
|
2807
|
+
}
|
|
2808
|
+
},
|
|
2809
|
+
})
|