synabun 2.4.2 → 2.4.3
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 +20 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +23 -3
- package/lib/release-npm-ci.mjs +23 -1
- package/mcp-server/dist/services/neural-interface.js +1 -1
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.js +8 -2
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -1
- package/mcp-server/package-lock.json +5 -5
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/services/neural-interface.ts +1 -1
- package/mcp-server/src/tools/browser-extension-setup.ts +8 -2
- package/neural-interface/i18n/en.json +50 -1
- package/neural-interface/i18n/pt-BR.json +57 -8
- package/neural-interface/lib/assistant-api.js +33 -0
- package/neural-interface/lib/assistant-brains/opencode.js +121 -7
- package/neural-interface/lib/assistant-dispatch.js +26 -2
- package/neural-interface/lib/assistant-envelope.js +40 -0
- package/neural-interface/lib/assistant-runtime.js +95 -10
- package/neural-interface/lib/browser-extension-adapter.js +1 -3
- package/neural-interface/lib/browser-extension-archive.js +149 -0
- package/neural-interface/lib/browser-extension-bridge.js +7 -4
- package/neural-interface/lib/browser-extension-folder.js +596 -76
- package/neural-interface/lib/browser-extension-package.js +200 -0
- package/neural-interface/lib/browser-extension-pin.js +84 -0
- package/neural-interface/lib/browser-extension-pin.json +33 -0
- package/neural-interface/lib/browser-extension-setup.js +105 -18
- package/neural-interface/lib/cli-install.js +23 -3
- package/neural-interface/lib/cli-update-planner.js +67 -4
- package/neural-interface/lib/native-loop-providers.js +10 -1
- package/neural-interface/lib/native-loop-runtime.js +20 -2
- package/neural-interface/lib/opencode-shell-read.js +107 -0
- package/neural-interface/lib/opencode-stop-failures.js +40 -0
- package/neural-interface/lib/opencode-turn-release.js +173 -0
- package/neural-interface/lib/opencode-v2-client.js +4 -1
- package/neural-interface/lib/opencode-v2-ws-requests.js +34 -0
- package/neural-interface/lib/opencode2-client.js +341 -6
- package/neural-interface/lib/opencode2-translate.js +161 -4
- package/neural-interface/lib/terminal-token-redaction.js +83 -0
- package/neural-interface/lib/whatsapp/bridge.js +52 -6
- package/neural-interface/package-lock.json +5 -5
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +5 -2
- package/neural-interface/public/shared/agy/agy-panel.js +38 -10
- package/neural-interface/public/shared/assistant/asst-api.js +25 -0
- package/neural-interface/public/shared/assistant/asst-panel.js +69 -1
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +23 -0
- package/neural-interface/public/shared/assistant/asst-render.js +138 -6
- package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
- package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +1 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +25 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
- package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
- package/neural-interface/public/shared/mtc/mtc-panel.js +17 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +34 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +26 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +39 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +20 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +40 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
- package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
- package/neural-interface/public/shared/shell-stop-view.js +83 -0
- package/neural-interface/public/shared/tour/tour-actor.js +14 -3
- package/neural-interface/public/shared/tray-auto-close.js +36 -6
- package/neural-interface/public/shared/ui-claude-panel.js +20 -0
- package/neural-interface/public/shared/ui-native-loop-router.js +45 -3
- package/neural-interface/public/shared/ui-scroll-follow.js +4 -0
- package/neural-interface/server.js +249 -35
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/browser-extension/content.js +0 -231
- package/browser-extension/engine.js +0 -658
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +0 -58
- package/browser-extension/popup-strings.js +0 -250
- package/browser-extension/popup-view.js +0 -151
- package/browser-extension/popup.css +0 -166
- package/browser-extension/popup.html +0 -108
- package/browser-extension/popup.js +0 -359
- package/browser-extension/service-worker.js +0 -283
- package/browser-extension/setup-content.js +0 -36
- package/browser-extension/tokens.css +0 -326
- /package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +0 -0
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/* The toolbar popup (popup.html). Every value is a style-guide token from tokens.css (the extension's byte-for-byte
|
|
2
|
-
copy of .synabun/style-guide/tokens.css); docs/design/browser-extension/prototype/app.css is the approved reference.
|
|
3
|
-
Scoped to this page: the content scripts never load it. */
|
|
4
|
-
*, *::before, *::after { box-sizing: border-box; }
|
|
5
|
-
html { color-scheme: dark; background: var(--color-neutral-800); }
|
|
6
|
-
body {
|
|
7
|
-
width: 360px; max-width: 100%; margin: 0; background: var(--color-neutral-800); color: var(--color-text);
|
|
8
|
-
font: var(--text-body-weight) var(--text-body-size)/1.5 var(--font-body); -webkit-font-smoothing: antialiased;
|
|
9
|
-
}
|
|
10
|
-
h1, h2, h3, p { margin: 0; }
|
|
11
|
-
h2, h3 { font-size: var(--text-body-size); font-weight: 600; line-height: 1.35; color: var(--color-text); }
|
|
12
|
-
p { color: var(--color-text-primary); }
|
|
13
|
-
code { font: var(--text-code-weight) var(--text-code-size)/1.5 var(--font-mono); overflow-wrap: anywhere; color: var(--color-text-primary); }
|
|
14
|
-
button, input { font: inherit; color: inherit; }
|
|
15
|
-
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
|
|
16
|
-
button:disabled { cursor: default; }
|
|
17
|
-
svg { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
|
|
18
|
-
:is(button, input, summary, [tabindex]):focus-visible { outline: 2px solid var(--color-focus); outline-offset: 3px; }
|
|
19
|
-
[hidden] { display: none !important; }
|
|
20
|
-
.p-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
21
|
-
|
|
22
|
-
/* header */
|
|
23
|
-
.p-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-lg); border-bottom: 1px solid var(--color-border); }
|
|
24
|
-
.p-brand { display: flex; align-items: center; gap: var(--space-sm); min-width: 0; }
|
|
25
|
-
.p-brand img { display: block; width: 32px; height: 32px; border-radius: var(--radius-control); }
|
|
26
|
-
.p-brand-text { min-width: 0; }
|
|
27
|
-
.p-brand strong { display: block; font: 600 var(--text-h4-size)/1.3 var(--font-heading); }
|
|
28
|
-
.p-brand small { display: block; font-size: var(--text-caption-size); line-height: 1.45; color: var(--color-text-muted); }
|
|
29
|
-
.p-icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: var(--radius-control); background: transparent; color: var(--color-text-primary); }
|
|
30
|
-
.p-icon-btn:hover { background: var(--color-surface-hover); color: var(--color-text); }
|
|
31
|
-
|
|
32
|
-
/* sections */
|
|
33
|
-
.p-section { padding: var(--space-lg); border-top: 1px solid var(--color-border); }
|
|
34
|
-
.p-head + .p-section { border-top: 0; }
|
|
35
|
-
.p-section > h2 { margin-bottom: var(--space-md); }
|
|
36
|
-
.p-section-title { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-sm); margin-bottom: var(--space-xs); }
|
|
37
|
-
.p-section-title span { font-size: var(--text-caption-size); color: var(--color-text-muted); }
|
|
38
|
-
.p-caption, .p-helper { font-size: var(--text-caption-size); line-height: 1.5; color: var(--color-text-muted); }
|
|
39
|
-
.p-caption { margin-bottom: var(--space-sm); }
|
|
40
|
-
.p-helper { margin-top: var(--space-md); }
|
|
41
|
-
.p-subhead { margin-top: var(--space-md); font-size: var(--text-caption-size); color: var(--color-text-primary); }
|
|
42
|
-
|
|
43
|
-
/* status: a symbol, a word, a sentence, the one action that helps */
|
|
44
|
-
.p-status { display: flex; align-items: flex-start; gap: var(--space-md); }
|
|
45
|
-
.p-status-symbol { display: grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0; border-radius: var(--radius-control); background: var(--color-surface-subtle); color: var(--color-info); }
|
|
46
|
-
.p-sym { display: none; }
|
|
47
|
-
.p-status[data-tone="good"] .p-status-symbol { color: var(--color-success); }
|
|
48
|
-
.p-status[data-tone="warn"] .p-status-symbol { color: var(--color-warning); }
|
|
49
|
-
.p-status[data-tone="bad"] .p-status-symbol { color: var(--color-danger); }
|
|
50
|
-
.p-status[data-sym="good"] [data-sym="good"], .p-status[data-sym="warn"] [data-sym="warn"], .p-status[data-sym="sync"] [data-sym="sync"],
|
|
51
|
-
.p-status[data-sym="bad"] [data-sym="bad"], .p-status[data-sym="link"] [data-sym="link"] { display: block; }
|
|
52
|
-
.p-status-body { flex: 1; min-width: 0; }
|
|
53
|
-
.p-status-title { font: 600 var(--text-h4-size)/1.3 var(--font-body); color: var(--color-text); }
|
|
54
|
-
.p-status-help { margin-top: var(--space-xs); font-size: var(--text-caption-size); line-height: 1.5; }
|
|
55
|
-
.p-status .p-actions { margin-top: var(--space-md); }
|
|
56
|
-
|
|
57
|
-
/* buttons: 44 px to hit, the guide's 5 px radius */
|
|
58
|
-
.p-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); }
|
|
59
|
-
.p-btn {
|
|
60
|
-
display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm); min-height: 44px; min-width: 0;
|
|
61
|
-
padding: var(--space-sm) var(--space-md); border: 1px solid var(--color-text-muted); border-radius: var(--radius-control);
|
|
62
|
-
background: var(--color-surface-subtle); color: var(--color-text); font-size: var(--text-button-size); font-weight: var(--text-button-weight);
|
|
63
|
-
line-height: 1.35; text-align: center; white-space: normal; overflow-wrap: anywhere;
|
|
64
|
-
}
|
|
65
|
-
.p-btn:hover:not(:disabled) { background: var(--color-surface-hover); }
|
|
66
|
-
.p-btn:disabled { color: var(--color-text-muted); border-color: var(--color-border-visible); background: transparent; }
|
|
67
|
-
.p-btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); }
|
|
68
|
-
.p-btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }
|
|
69
|
-
.p-btn-ghost { border-color: transparent; background: transparent; padding-inline: var(--space-sm); }
|
|
70
|
-
.p-btn-danger { color: var(--color-danger); }
|
|
71
|
-
.p-btn-danger:not(.p-btn-ghost) { border-color: var(--color-danger); }
|
|
72
|
-
|
|
73
|
-
/* agent access: the mode, the app's dropdown pattern (never a native select) */
|
|
74
|
-
.p-mode { margin-top: var(--space-lg); }
|
|
75
|
-
.p-label { display: block; margin-bottom: var(--space-sm); font-size: var(--text-caption-size); color: var(--color-text-primary); }
|
|
76
|
-
.p-dropdown { position: relative; min-width: 0; }
|
|
77
|
-
.p-dropdown-trigger {
|
|
78
|
-
display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); width: 100%; min-height: 44px;
|
|
79
|
-
padding: var(--space-sm) var(--space-md); border: 1px solid var(--color-text-muted); border-radius: var(--radius-control);
|
|
80
|
-
background: var(--color-surface-subtle); font-size: var(--text-button-size); font-weight: 500; line-height: 1.45; text-align: start;
|
|
81
|
-
}
|
|
82
|
-
.p-dropdown-trigger:hover { background: var(--color-surface-hover); }
|
|
83
|
-
.p-dropdown-trigger span { min-width: 0; overflow-wrap: anywhere; }
|
|
84
|
-
.p-dropdown-trigger svg { width: 14px; height: 14px; }
|
|
85
|
-
.p-dropdown-trigger[aria-expanded="true"] svg { transform: rotate(180deg); }
|
|
86
|
-
.p-dropdown-menu {
|
|
87
|
-
position: absolute; top: calc(100% + 4px); inset-inline: 0; z-index: 20; padding: var(--space-xs);
|
|
88
|
-
background: var(--color-neutral-700); border: 1px solid var(--color-text-muted); border-radius: var(--radius-control); box-shadow: var(--shadow-lg);
|
|
89
|
-
}
|
|
90
|
-
.p-dropdown-item { display: flex; gap: var(--space-sm); align-items: center; min-height: 44px; padding: var(--space-sm) var(--space-md); border-radius: var(--radius-control); cursor: pointer; font-size: var(--text-caption-size); line-height: 1.45; }
|
|
91
|
-
.p-dropdown-item::before { content: ''; flex: 0 0 14px; text-align: center; }
|
|
92
|
-
.p-dropdown-item[aria-selected="true"]::before { content: '✓'; }
|
|
93
|
-
.p-dropdown-item:hover, .p-dropdown-item[aria-selected="true"] { background: var(--color-surface-hover); }
|
|
94
|
-
.p-dropdown-item.p-highlight { outline: 2px solid var(--color-focus); outline-offset: -2px; }
|
|
95
|
-
.p-mode-help { margin-top: var(--space-sm); font-size: var(--text-caption-size); line-height: 1.5; }
|
|
96
|
-
|
|
97
|
-
/* the tabs agents hold, grouped by agent */
|
|
98
|
-
.p-tab-list { max-height: 260px; overflow-y: auto; padding-inline: 3px; margin-inline: -3px; }
|
|
99
|
-
.p-agent + .p-agent { margin-top: var(--space-md); }
|
|
100
|
-
.p-agent-heading { display: flex; align-items: center; gap: var(--space-sm); min-width: 0; margin: var(--space-xs) 0; font-size: var(--text-caption-size); font-weight: 600; color: var(--color-text-primary); overflow-wrap: anywhere; }
|
|
101
|
-
.p-agent-mark { display: grid; place-items: center; flex: 0 0 24px; height: 24px; border-radius: var(--radius-control); background: var(--color-surface-hover); font: 500 11px/1 var(--font-mono); color: var(--color-text); }
|
|
102
|
-
.p-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-sm); padding-block: var(--space-xs); border-bottom: 1px solid var(--color-border); }
|
|
103
|
-
.p-row:last-child { border-bottom: 0; }
|
|
104
|
-
.p-row-text { flex: 1 1 180px; min-width: 0; padding-block: var(--space-xs); }
|
|
105
|
-
.p-row-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-body-size); font-weight: 500; color: var(--color-text); }
|
|
106
|
-
.p-row-address { display: block; overflow-wrap: anywhere; font-size: var(--text-caption-size); color: var(--color-text-muted); unicode-bidi: isolate; }
|
|
107
|
-
.p-row > .p-btn { flex: 0 0 auto; padding-inline: var(--space-sm); }
|
|
108
|
-
.p-row-error { flex: 1 0 100%; font-size: var(--text-caption-size); color: var(--color-warning); }
|
|
109
|
-
.p-row[data-stale="true"] .p-row-title { color: var(--color-text-primary); }
|
|
110
|
-
.p-empty { padding: var(--space-xl) var(--space-sm); text-align: center; }
|
|
111
|
-
.p-empty > svg { width: 28px; height: 28px; margin: 0 auto var(--space-md); display: block; color: var(--color-text-muted); }
|
|
112
|
-
.p-empty p { max-width: 36ch; margin: var(--space-sm) auto 0; font-size: var(--text-caption-size); }
|
|
113
|
-
.p-list:empty { display: none; }
|
|
114
|
-
.p-list + .p-list { margin-top: var(--space-sm); }
|
|
115
|
-
.p-section .p-actions { margin-top: var(--space-md); }
|
|
116
|
-
.p-notice { padding: var(--space-md); border-inline-start: 2px solid var(--color-warning); background: var(--color-surface-subtle); font-size: var(--text-caption-size); }
|
|
117
|
-
.p-notice[data-tone="bad"] { border-color: var(--color-danger); }
|
|
118
|
-
|
|
119
|
-
/* checkboxes: the whole row is the hit area */
|
|
120
|
-
.p-check { display: flex; align-items: center; gap: var(--space-sm); min-height: 44px; font-size: var(--text-caption-size); color: var(--color-text); cursor: pointer; }
|
|
121
|
-
.p-check input { width: 18px; height: 18px; margin: 0; flex-shrink: 0; accent-color: var(--color-primary-500); }
|
|
122
|
-
|
|
123
|
-
/* disclosures: files and limits, the typed code */
|
|
124
|
-
.p-details { border-top: 1px solid var(--color-border); }
|
|
125
|
-
.p-details > summary {
|
|
126
|
-
display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); min-height: 44px;
|
|
127
|
-
padding: var(--space-md) var(--space-lg); list-style: none; cursor: pointer; font-size: var(--text-caption-size); font-weight: 500; color: var(--color-text);
|
|
128
|
-
}
|
|
129
|
-
.p-details > summary::-webkit-details-marker { display: none; }
|
|
130
|
-
.p-details > summary::after { content: '+'; font-size: 18px; line-height: 1; color: var(--color-text-muted); }
|
|
131
|
-
.p-details[open] > summary::after { content: '−'; }
|
|
132
|
-
.p-details > summary:hover { background: var(--color-surface-subtle); }
|
|
133
|
-
.p-details-body { padding: 0 var(--space-lg) var(--space-lg); font-size: var(--text-caption-size); }
|
|
134
|
-
.p-details-body > * + * { margin-top: var(--space-sm); }
|
|
135
|
-
.p-details-body h3 { margin-top: var(--space-md); }
|
|
136
|
-
.p-details-nested { margin-top: var(--space-sm); border-top: 1px solid var(--color-border); }
|
|
137
|
-
.p-details-nested > summary { padding-inline: 0; }
|
|
138
|
-
.p-details-nested > .p-details-body { padding-inline: 0; }
|
|
139
|
-
.p-pair .p-field { display: grid; gap: var(--space-xs); color: var(--color-text-primary); }
|
|
140
|
-
.p-pair input {
|
|
141
|
-
width: 100%; min-height: 36px; padding: var(--space-xs) var(--space-sm); border: 1px solid var(--color-text-muted);
|
|
142
|
-
border-radius: var(--radius-input); background: var(--color-settings-field); color: var(--color-text); font-family: var(--font-mono);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/* footer */
|
|
146
|
-
.p-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-xs); padding: var(--space-xs) var(--space-sm); border-top: 1px solid var(--color-border); }
|
|
147
|
-
.p-footer-end { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
|
|
148
|
-
.p-footer-tools { flex-basis: 100%; }
|
|
149
|
-
|
|
150
|
-
/* confirmations and the result line */
|
|
151
|
-
.p-dialog { width: min(328px, calc(100vw - 32px)); padding: var(--space-xl); border: 1px solid var(--color-text-muted); border-radius: var(--radius-modal); background: var(--color-neutral-700); color: var(--color-text); }
|
|
152
|
-
.p-dialog::backdrop { background: var(--color-settings-field); }
|
|
153
|
-
.p-dialog h2 { margin-bottom: var(--space-sm); font-size: var(--text-h4-size); }
|
|
154
|
-
.p-dialog p { font-size: var(--text-caption-size); line-height: 1.5; }
|
|
155
|
-
.p-dialog-actions { justify-content: flex-end; margin-top: var(--space-lg); }
|
|
156
|
-
.p-toast {
|
|
157
|
-
position: sticky; bottom: var(--space-sm); margin: 0 var(--space-sm) var(--space-sm); padding: var(--space-md) var(--space-lg);
|
|
158
|
-
border: 1px solid var(--color-text-muted); border-radius: var(--radius-control); background: var(--color-neutral-700); font-size: var(--text-body-size); color: var(--color-text); z-index: 30;
|
|
159
|
-
}
|
|
160
|
-
.p-toast:empty { display: none; }
|
|
161
|
-
.p-toast[data-tone="bad"] { border-color: var(--color-danger); }
|
|
162
|
-
|
|
163
|
-
@media (prefers-reduced-motion: no-preference) {
|
|
164
|
-
.p-btn, .p-icon-btn, .p-dropdown-trigger, .p-details > summary, .p-dropdown-item { transition: background-color 150ms ease, color 150ms ease; }
|
|
165
|
-
.p-dropdown-trigger svg { transition: transform 150ms ease; }
|
|
166
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>SynaBun Browser Bridge</title><link rel="stylesheet" href="tokens.css"><link rel="stylesheet" href="popup.css"><body>
|
|
2
|
-
<!-- The toolbar popup (docs/design/browser-extension: "Extension popup"). Am I connected, what may agents use, which
|
|
3
|
-
tabs do they hold. Every word comes from popup-strings.js in the browser's language (popup.js fills it in); what
|
|
4
|
-
the popup shows is decided by popup-view.js. -->
|
|
5
|
-
<div class="popup" id="popup" data-state="loading" aria-busy="true">
|
|
6
|
-
<header class="p-head">
|
|
7
|
-
<div class="p-brand"><img src="icons/icon-32.png" alt="" width="32" height="32"><div class="p-brand-text"><strong>SynaBun</strong><small id="p-brand-sub"></small></div></div>
|
|
8
|
-
<button type="button" class="p-icon-btn" id="p-open-app" data-action="open-app" aria-label="Open SynaBun" title="Open SynaBun"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 17 17 7M8 7h9v9"></path></svg></button>
|
|
9
|
-
</header>
|
|
10
|
-
|
|
11
|
-
<section class="p-section p-top" aria-labelledby="p-status-title">
|
|
12
|
-
<div class="p-status" id="p-status" data-tone="">
|
|
13
|
-
<span class="p-status-symbol" aria-hidden="true">
|
|
14
|
-
<svg class="p-sym" data-sym="good" viewBox="0 0 24 24"><path d="m5 12 4 4 10-10"></path></svg>
|
|
15
|
-
<svg class="p-sym" data-sym="warn" viewBox="0 0 24 24"><path d="M9 5v14M15 5v14"></path></svg>
|
|
16
|
-
<svg class="p-sym" data-sym="sync" viewBox="0 0 24 24"><path d="M20 7a9 9 0 0 0-15-1L2 9m0-6v6h6M4 17a9 9 0 0 0 15 1l3-3m0 6v-6h-6"></path></svg>
|
|
17
|
-
<svg class="p-sym" data-sym="bad" viewBox="0 0 24 24"><path d="m12 3 10 18H2L12 3ZM12 9v5M12 17h.01"></path></svg>
|
|
18
|
-
<svg class="p-sym" data-sym="link" viewBox="0 0 24 24"><path d="M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1"></path></svg>
|
|
19
|
-
</span>
|
|
20
|
-
<div class="p-status-body">
|
|
21
|
-
<h1 class="p-status-title" id="p-status-title" tabindex="-1"></h1>
|
|
22
|
-
<p class="p-status-help" id="p-status-help"></p>
|
|
23
|
-
<div class="p-actions" id="p-status-actions" hidden><button type="button" class="p-btn p-btn-primary" id="p-primary" hidden></button></div>
|
|
24
|
-
</div>
|
|
25
|
-
</div>
|
|
26
|
-
|
|
27
|
-
<div class="p-mode" id="p-mode" hidden>
|
|
28
|
-
<span class="p-label" id="p-mode-label"></span>
|
|
29
|
-
<div class="p-dropdown" id="p-mode-dropdown">
|
|
30
|
-
<button type="button" class="p-dropdown-trigger" id="p-mode-trigger" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="p-mode-list" aria-labelledby="p-mode-label p-mode-value"><span id="p-mode-value"></span><svg viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"></path></svg></button>
|
|
31
|
-
<div class="p-dropdown-menu" id="p-mode-list" role="listbox" aria-labelledby="p-mode-label" hidden>
|
|
32
|
-
<div class="p-dropdown-item" role="option" id="p-mode-full" data-value="full" aria-selected="true"></div>
|
|
33
|
-
<div class="p-dropdown-item" role="option" id="p-mode-restricted" data-value="restricted" aria-selected="false"></div>
|
|
34
|
-
</div>
|
|
35
|
-
</div>
|
|
36
|
-
<p class="p-mode-help" id="p-mode-help"></p>
|
|
37
|
-
</div>
|
|
38
|
-
</section>
|
|
39
|
-
|
|
40
|
-
<section class="p-section" id="p-activity" aria-labelledby="p-activity-title" hidden>
|
|
41
|
-
<div class="p-section-title"><h2 id="p-activity-title" tabindex="-1"></h2><span id="p-activity-count"></span></div>
|
|
42
|
-
<p class="p-caption" id="p-activity-summary"></p>
|
|
43
|
-
<div class="p-tab-list" id="p-groups"></div>
|
|
44
|
-
<div class="p-empty" id="p-empty" hidden>
|
|
45
|
-
<svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="7" width="15" height="13" rx="2"></rect><path d="M7 3h12a2 2 0 0 1 2 2v11M3 11h15"></path></svg>
|
|
46
|
-
<h3 id="p-empty-title"></h3><p id="p-empty-help"></p>
|
|
47
|
-
</div>
|
|
48
|
-
<p class="p-helper" id="p-activity-help"></p>
|
|
49
|
-
</section>
|
|
50
|
-
|
|
51
|
-
<section class="p-section" id="p-shared" aria-labelledby="p-shared-title" hidden>
|
|
52
|
-
<h2 id="p-shared-title"></h2>
|
|
53
|
-
<div class="p-list" id="p-sites"></div>
|
|
54
|
-
<div class="p-empty" id="p-shared-empty" hidden><h3 id="p-shared-empty-title"></h3><p id="p-shared-empty-help"></p></div>
|
|
55
|
-
<h3 class="p-subhead" id="p-waiting-title" hidden></h3>
|
|
56
|
-
<div class="p-list" id="p-waiting"></div>
|
|
57
|
-
<div class="p-actions"><button type="button" class="p-btn p-btn-primary" id="share" data-action="share"></button><button type="button" class="p-btn" id="site" data-action="site"></button></div>
|
|
58
|
-
<label class="p-check"><input type="checkbox" id="newTabs"><span id="p-newtabs-label"></span></label>
|
|
59
|
-
</section>
|
|
60
|
-
|
|
61
|
-
<details class="p-details" id="p-files" hidden>
|
|
62
|
-
<summary id="p-files-summary"></summary>
|
|
63
|
-
<div class="p-details-body">
|
|
64
|
-
<label class="p-check"><input type="checkbox" id="downloads"><span id="p-downloads-label"></span></label>
|
|
65
|
-
<p id="p-download-note"></p>
|
|
66
|
-
<p class="p-notice" id="p-downloads-denied" role="status" hidden></p>
|
|
67
|
-
<h3 id="p-upload-title"></h3>
|
|
68
|
-
<p id="p-upload-help"></p>
|
|
69
|
-
<p id="p-limits"></p>
|
|
70
|
-
<details class="p-details p-details-nested" id="p-connection">
|
|
71
|
-
<summary id="p-connection-summary"></summary>
|
|
72
|
-
<p class="p-details-body"><span id="p-bridge-label"></span> <code id="p-bridge"></code></p>
|
|
73
|
-
</details>
|
|
74
|
-
</div>
|
|
75
|
-
</details>
|
|
76
|
-
|
|
77
|
-
<details class="p-details" id="p-pair-code" hidden>
|
|
78
|
-
<summary id="p-pair-summary"></summary>
|
|
79
|
-
<form class="p-details-body p-pair" id="pair">
|
|
80
|
-
<p id="p-pair-help"></p>
|
|
81
|
-
<label class="p-field" for="port"><span id="p-port-label"></span><input id="port" type="number" min="1024" max="65535" value="3345" inputmode="numeric"></label>
|
|
82
|
-
<label class="p-field" for="code"><span id="p-code-label"></span><input id="code" autocomplete="off" spellcheck="false" maxlength="24"></label>
|
|
83
|
-
<button class="p-btn" id="p-pair-submit" type="submit"></button>
|
|
84
|
-
</form>
|
|
85
|
-
</details>
|
|
86
|
-
|
|
87
|
-
<footer class="p-footer" id="p-footer">
|
|
88
|
-
<button type="button" class="p-btn p-btn-ghost" id="p-footer-app" data-action="open-app"></button>
|
|
89
|
-
<span class="p-footer-end">
|
|
90
|
-
<button type="button" class="p-btn p-btn-ghost" id="disconnect" data-action="confirm-disconnect" hidden></button>
|
|
91
|
-
<button type="button" class="p-btn p-btn-ghost p-btn-danger" id="revoke" data-action="confirm-revoke" hidden></button>
|
|
92
|
-
</span>
|
|
93
|
-
<div class="p-footer-end p-footer-tools">
|
|
94
|
-
<button type="button" class="p-btn p-btn-ghost" id="p-open-extensions" data-action="open-extensions"></button>
|
|
95
|
-
<button type="button" class="p-btn p-btn-ghost" id="p-reload-extension" data-action="reload-extension"></button>
|
|
96
|
-
</div>
|
|
97
|
-
</footer>
|
|
98
|
-
|
|
99
|
-
<p class="p-sr-only" id="p-live" role="status" aria-live="polite"></p>
|
|
100
|
-
<p class="p-toast" id="p-toast" role="status" aria-live="polite"></p>
|
|
101
|
-
</div>
|
|
102
|
-
|
|
103
|
-
<dialog class="p-dialog" id="p-confirm" aria-labelledby="p-confirm-title" aria-describedby="p-confirm-body">
|
|
104
|
-
<h2 id="p-confirm-title"></h2>
|
|
105
|
-
<p id="p-confirm-body"></p>
|
|
106
|
-
<div class="p-actions p-dialog-actions"><button type="button" class="p-btn" id="p-confirm-cancel" data-action="cancel-confirm"></button><button type="button" class="p-btn" id="p-confirm-ok" data-action="do-confirm"></button></div>
|
|
107
|
-
</dialog>
|
|
108
|
-
<script type="module" src="popup.js"></script></body></html>
|
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
// The toolbar popup's DOM glue (popup.html). popup-view.js decides what is shown. Bridge actions go to the service
|
|
2
|
-
// worker (docs/browser-extension-bridge.md). The popup opens its own links and reloads the extension directly.
|
|
3
|
-
// Disconnect, Revoke pairing, a mode change and removing a shared site are confirmed first. Take back is immediate
|
|
4
|
-
// and keeps the tab open.
|
|
5
|
-
import { publicOrigin, hostPattern } from './protocol.js';
|
|
6
|
-
import { popupLocale, translator } from './popup-strings.js';
|
|
7
|
-
import { popupView } from './popup-view.js';
|
|
8
|
-
|
|
9
|
-
const $ = id => document.getElementById(id);
|
|
10
|
-
const locale = popupLocale([globalThis.chrome?.i18n?.getUILanguage?.(), ...(globalThis.navigator?.languages || []), globalThis.navigator?.language].filter(Boolean));
|
|
11
|
-
const t = translator(locale);
|
|
12
|
-
const coded = code => Object.assign(new Error(code), { code });
|
|
13
|
-
|
|
14
|
-
async function ask(message) {
|
|
15
|
-
const result = await chrome.runtime.sendMessage(message);
|
|
16
|
-
if (!result?.ok) throw Object.assign(new Error(result?.error || 'EXTENSION_UNAVAILABLE'), { code: result?.code || 'EXTENSION_UNAVAILABLE' });
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
// Whether a pairing credential is stored: its size only, never its value. null where the browser cannot say.
|
|
20
|
-
async function storedPairing() {
|
|
21
|
-
try { const bytes = await chrome.storage.local.getBytesInUse?.('credential'); return typeof bytes === 'number' ? bytes > 0 : null; }
|
|
22
|
-
catch { return null; }
|
|
23
|
-
}
|
|
24
|
-
// SynaBun's own address, from this extension's manifest (the setup page's content script names the app's origin).
|
|
25
|
-
function appOrigin() {
|
|
26
|
-
try {
|
|
27
|
-
const own = chrome.runtime.getManifest().content_scripts || [];
|
|
28
|
-
const pattern = own.flatMap(entry => entry.js?.includes('setup-content.js') ? entry.matches || [] : [])[0];
|
|
29
|
-
if (pattern) return new URL(pattern.replace(/\*$/, '')).origin;
|
|
30
|
-
} catch {}
|
|
31
|
-
return 'http://127.0.0.1:3344';
|
|
32
|
-
}
|
|
33
|
-
const openTab = url => chrome.tabs.create({ url });
|
|
34
|
-
|
|
35
|
-
// ── the words that never change while the popup is open ──
|
|
36
|
-
function fixedText() {
|
|
37
|
-
document.documentElement.lang = locale;
|
|
38
|
-
const set = (id, key) => { const node = $(id); if (node) node.textContent = t(key); };
|
|
39
|
-
let version;
|
|
40
|
-
try { version = chrome.runtime.getManifest().version; } catch {}
|
|
41
|
-
$('p-brand-sub').textContent = version ? `${t('brandSub')} · v${version}` : t('brandSub');
|
|
42
|
-
const openApp = $('p-open-app'); openApp.setAttribute('aria-label', t('openApp')); openApp.setAttribute('title', t('openApp'));
|
|
43
|
-
set('p-footer-app', 'openApp'); set('disconnect', 'disconnect'); set('revoke', 'revoke');
|
|
44
|
-
set('p-open-extensions', 'openExtensions'); set('p-reload-extension', 'reloadExtension');
|
|
45
|
-
set('p-mode-label', 'agentAccess'); set('p-mode-full', 'full'); set('p-mode-restricted', 'restricted');
|
|
46
|
-
set('p-empty-title', 'emptyTitle'); set('p-empty-help', 'emptyHelp');
|
|
47
|
-
set('p-shared-title', 'sharedSites'); set('p-shared-empty-title', 'noShared'); set('p-shared-empty-help', 'noSharedHelp'); set('p-waiting-title', 'sharedTabs');
|
|
48
|
-
set('share', 'shareTab'); set('site', 'shareSite'); set('p-newtabs-label', 'newTabs');
|
|
49
|
-
set('p-files-summary', 'advanced'); set('p-downloads-label', 'downloads'); set('p-download-note', 'downloadNote'); set('p-downloads-denied', 'downloadsDenied');
|
|
50
|
-
set('p-upload-title', 'uploadFolder'); set('p-upload-help', 'uploadHelpPopup'); set('p-limits', 'limits');
|
|
51
|
-
set('p-connection-summary', 'details'); set('p-bridge-label', 'bridge');
|
|
52
|
-
set('p-pair-summary', 'pairCode'); set('p-pair-help', 'pairCodeHelp'); set('p-port-label', 'pairPort'); set('p-code-label', 'pairCodeLabel'); set('p-pair-submit', 'pairAction');
|
|
53
|
-
set('p-confirm-cancel', 'cancel');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ── state ──
|
|
57
|
-
let view = null, lastState = '', refreshing = false, portTouched = false;
|
|
58
|
-
const busy = new Set(), rowErrors = new Set();
|
|
59
|
-
|
|
60
|
-
const SYMBOLS = { connected: 'good', disconnected: 'warn', connecting: 'sync', reconnecting: 'sync', loading: 'sync', error: 'bad', unpaired: 'link' };
|
|
61
|
-
const PRIMARY_LABEL = { resume: 'reconnect', connect: 'connect', retry: 'retry', 'open-app': 'openApp' };
|
|
62
|
-
|
|
63
|
-
// Children of `container` follow `items` in order, each kept by its key so focus and scroll survive a refresh.
|
|
64
|
-
function reconcile(container, items, key, make, update) {
|
|
65
|
-
const existing = new Map([...container.children].map(el => [el.dataset.key, el]));
|
|
66
|
-
items.forEach((item, i) => {
|
|
67
|
-
const k = key(item);
|
|
68
|
-
let el = existing.get(k);
|
|
69
|
-
if (!el) { el = make(item); el.dataset.key = k; }
|
|
70
|
-
existing.delete(k);
|
|
71
|
-
update(el, item);
|
|
72
|
-
if (container.children[i] !== el) container.insertBefore(el, container.children[i] || null);
|
|
73
|
-
});
|
|
74
|
-
for (const el of existing.values()) el.remove();
|
|
75
|
-
}
|
|
76
|
-
function element(tag, className, attrs = {}) {
|
|
77
|
-
const el = document.createElement(tag);
|
|
78
|
-
if (className) el.className = className;
|
|
79
|
-
for (const [name, value] of Object.entries(attrs)) el.setAttribute(name, value);
|
|
80
|
-
return el;
|
|
81
|
-
}
|
|
82
|
-
function textOnce(node, text) { if (node.textContent !== text) node.textContent = text; }
|
|
83
|
-
|
|
84
|
-
// A tab row: its title and safe address, and one action (Take back, or Stop sharing for a shared tab nobody holds).
|
|
85
|
-
function makeRow(kind) {
|
|
86
|
-
return () => {
|
|
87
|
-
const row = element('div', 'p-row');
|
|
88
|
-
const text = element('div', 'p-row-text');
|
|
89
|
-
text.append(element('span', 'p-row-title'), element('span', 'p-row-address'));
|
|
90
|
-
const button = element('button', 'p-btn', { type: 'button', 'data-action': kind });
|
|
91
|
-
const error = element('p', 'p-row-error', { role: 'alert' }); error.hidden = true;
|
|
92
|
-
row.append(text, button, error);
|
|
93
|
-
return row;
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function updateRow(row, tab, { kind, agent = '', disabled }) {
|
|
97
|
-
row.dataset.handle = tab.handle; row.dataset.stale = String(!!disabled);
|
|
98
|
-
const [text, button, error] = row.children;
|
|
99
|
-
const [title, address] = text.children;
|
|
100
|
-
textOnce(title, tab.title); title.setAttribute('title', tab.title);
|
|
101
|
-
textOnce(address, tab.address);
|
|
102
|
-
button.dataset.handle = tab.handle;
|
|
103
|
-
const pending = busy.has(tab.handle);
|
|
104
|
-
textOnce(button, t(pending ? 'busy' : kind === 'take-back' ? 'takeBack' : 'stopSharing'));
|
|
105
|
-
button.setAttribute('aria-label', kind === 'take-back' ? t('takeBackLabel', { title: tab.title, agent }) : t('stopSharingLabel', { title: tab.title }));
|
|
106
|
-
button.disabled = !!disabled || pending;
|
|
107
|
-
error.hidden = !rowErrors.has(tab.handle);
|
|
108
|
-
textOnce(error, rowErrors.has(tab.handle) ? t('actionError') : '');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function render(next) {
|
|
112
|
-
view = next;
|
|
113
|
-
const popup = $('popup');
|
|
114
|
-
popup.dataset.state = view.state; popup.setAttribute('aria-busy', 'false');
|
|
115
|
-
// status
|
|
116
|
-
const status = $('p-status'); status.dataset.tone = view.tone; status.dataset.sym = SYMBOLS[view.state] || 'sync';
|
|
117
|
-
textOnce($('p-status-title'), view.title); textOnce($('p-status-help'), view.help);
|
|
118
|
-
const primary = $('p-primary');
|
|
119
|
-
primary.hidden = !view.primary; $('p-status-actions').hidden = !view.primary;
|
|
120
|
-
if (view.primary) { primary.dataset.action = view.primary; textOnce(primary, t(PRIMARY_LABEL[view.primary])); primary.className = `p-btn ${view.primary === 'open-app' ? '' : 'p-btn-primary'}`.trim(); }
|
|
121
|
-
// A connection change is announced once, never every poll.
|
|
122
|
-
if (view.state !== lastState) { lastState = view.state; $('p-live').textContent = `${t('statusLabel')}: ${view.title}`; }
|
|
123
|
-
// agent access
|
|
124
|
-
$('p-mode').hidden = !view.showMode;
|
|
125
|
-
const chosen = view.full ? 'full' : 'restricted';
|
|
126
|
-
textOnce($('p-mode-value'), t(chosen));
|
|
127
|
-
for (const option of $('p-mode-list').children) option.setAttribute('aria-selected', String(option.dataset.value === chosen));
|
|
128
|
-
textOnce($('p-mode-help'), t(view.full ? 'fullHelp' : 'restrictedHelp'));
|
|
129
|
-
// activity: the tabs agents hold, by agent
|
|
130
|
-
$('p-activity').hidden = !view.showActivity;
|
|
131
|
-
const total = view.groups.reduce((sum, g) => sum + g.tabs.length, 0);
|
|
132
|
-
textOnce($('p-activity-title'), t(view.stale ? 'pausedTabs' : 'controlled'));
|
|
133
|
-
textOnce($('p-activity-count'), total ? String(total) : '');
|
|
134
|
-
$('p-activity-summary').hidden = !total; textOnce($('p-activity-summary'), view.summary);
|
|
135
|
-
reconcile($('p-groups'), view.groups, g => g.owner, () => {
|
|
136
|
-
const group = element('div', 'p-agent');
|
|
137
|
-
const heading = element('div', 'p-agent-heading');
|
|
138
|
-
heading.append(element('span', 'p-agent-mark', { 'aria-hidden': 'true' }), element('span', 'p-agent-name'));
|
|
139
|
-
group.append(heading, element('div', 'p-agent-tabs'));
|
|
140
|
-
return group;
|
|
141
|
-
}, (group, g) => {
|
|
142
|
-
const [heading, list] = group.children;
|
|
143
|
-
textOnce(heading.children[0], g.mark); textOnce(heading.children[1], g.label);
|
|
144
|
-
reconcile(list, g.tabs, tab => tab.handle, makeRow('take-back'), (row, tab) => updateRow(row, tab, { kind: 'take-back', agent: g.label, disabled: !view.live }));
|
|
145
|
-
});
|
|
146
|
-
$('p-empty').hidden = !(view.live && !total);
|
|
147
|
-
textOnce($('p-activity-help'), t(view.stale ? 'staleHelp' : 'takeBackHelp'));
|
|
148
|
-
$('p-activity-help').hidden = !total;
|
|
149
|
-
// restricted mode: what the owner shares
|
|
150
|
-
$('p-shared').hidden = !view.showShared;
|
|
151
|
-
reconcile($('p-sites'), view.sites, site => site, () => {
|
|
152
|
-
const row = element('div', 'p-row');
|
|
153
|
-
const text = element('div', 'p-row-text'); text.append(element('code', 'p-row-title'));
|
|
154
|
-
row.append(text, element('button', 'p-btn p-btn-ghost p-btn-danger', { type: 'button', 'data-action': 'confirm-site' }));
|
|
155
|
-
return row;
|
|
156
|
-
}, (row, site) => {
|
|
157
|
-
textOnce(row.children[0].children[0], site);
|
|
158
|
-
const button = row.children[1]; button.dataset.site = site; textOnce(button, t('removeSite')); button.setAttribute('aria-label', t('removeSiteLabel', { site }));
|
|
159
|
-
});
|
|
160
|
-
reconcile($('p-waiting'), view.showShared ? view.waiting : [], tab => tab.handle, makeRow('stop-sharing'), (row, tab) => updateRow(row, tab, { kind: 'stop-sharing', disabled: !view.live }));
|
|
161
|
-
$('p-waiting-title').hidden = !view.waiting.length;
|
|
162
|
-
$('p-shared-empty').hidden = !!(view.sites.length || view.waiting.length);
|
|
163
|
-
$('newTabs').checked = view.options.allowNewTabs; $('downloads').checked = view.options.downloads;
|
|
164
|
-
// files and limits, the typed code
|
|
165
|
-
$('p-files').hidden = !view.showFiles;
|
|
166
|
-
textOnce($('p-bridge'), `127.0.0.1:${view.port}`);
|
|
167
|
-
$('p-pair-code').hidden = !view.showPairCode;
|
|
168
|
-
if (!portTouched) $('port').value = String(view.port);
|
|
169
|
-
// footer
|
|
170
|
-
$('disconnect').hidden = !view.canDisconnect;
|
|
171
|
-
$('revoke').hidden = !view.canRevoke;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
async function refresh() {
|
|
175
|
-
if (refreshing) return;
|
|
176
|
-
refreshing = true;
|
|
177
|
-
try {
|
|
178
|
-
let result = null;
|
|
179
|
-
try { result = await ask({ action: 'status' }); } catch { result = null; }
|
|
180
|
-
render(popupView(result, { paired: result ? await storedPairing() : null, t }));
|
|
181
|
-
} finally { refreshing = false; }
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// ── feedback ──
|
|
185
|
-
let toastTimer;
|
|
186
|
-
function toast(text, tone = '') {
|
|
187
|
-
const node = $('p-toast'); node.textContent = text; node.dataset.tone = tone;
|
|
188
|
-
clearTimeout(toastTimer); toastTimer = setTimeout(() => { node.textContent = ''; }, 6000);
|
|
189
|
-
}
|
|
190
|
-
function failure(error) {
|
|
191
|
-
const code = String(error?.code || '');
|
|
192
|
-
if (code === 'SITE_DENIED') return t('siteDenied');
|
|
193
|
-
if (code === 'EXTENSION_UNAVAILABLE') return t('unavailable');
|
|
194
|
-
return t('actionFailed', { code: code || 'OPERATION_FAILED' });
|
|
195
|
-
}
|
|
196
|
-
// Runs one owner action, says how it went, and shows the worker's state after it.
|
|
197
|
-
async function run(fn, done) {
|
|
198
|
-
try { await fn(); if (done) toast(done); }
|
|
199
|
-
catch (error) { toast(failure(error), 'bad'); }
|
|
200
|
-
await refresh();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// ── confirmations (a styled <dialog>; Cancel has the focus first; focus returns where it came from) ──
|
|
204
|
-
const CONFIRMS = {
|
|
205
|
-
disconnect: ['disconnectTitle', 'disconnectBody', 'disconnect', 'danger'],
|
|
206
|
-
revoke: ['revokeTitle', 'revokeBody', 'revoke', 'danger'],
|
|
207
|
-
restrict: ['restrictTitle', 'restrictBody', 'restrictConfirm', 'primary'],
|
|
208
|
-
full: ['fullTitle', 'fullBody', 'fullConfirm', 'primary'],
|
|
209
|
-
site: ['removeTitle', 'removeBody', 'removeSite', 'danger'],
|
|
210
|
-
};
|
|
211
|
-
let pending = null;
|
|
212
|
-
function confirmFirst(kind, opener, action) {
|
|
213
|
-
const [title, body, ok, tone] = CONFIRMS[kind];
|
|
214
|
-
const dialog = $('p-confirm');
|
|
215
|
-
$('p-confirm-title').textContent = t(title); $('p-confirm-body').textContent = t(body);
|
|
216
|
-
const button = $('p-confirm-ok'); button.textContent = t(ok); button.className = `p-btn p-btn-${tone}`;
|
|
217
|
-
dialog.dataset.kind = kind;
|
|
218
|
-
pending = { action, opener };
|
|
219
|
-
if (typeof dialog.showModal === 'function') dialog.showModal(); else dialog.setAttribute('open', '');
|
|
220
|
-
$('p-confirm-cancel').focus();
|
|
221
|
-
}
|
|
222
|
-
function closeConfirm() {
|
|
223
|
-
const dialog = $('p-confirm'), opener = pending?.opener;
|
|
224
|
-
pending = null;
|
|
225
|
-
if (typeof dialog.close === 'function' && dialog.open) dialog.close(); else dialog.removeAttribute('open');
|
|
226
|
-
if (opener?.isConnected && !opener.hidden) opener.focus(); else $('p-status-title').focus?.();
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// ── the mode dropdown: the app's .cc-dropdown keyboard model (never a native select) ──
|
|
230
|
-
const trigger = () => $('p-mode-trigger'), options = () => [...$('p-mode-list').children];
|
|
231
|
-
let highlighted = 0, typed = '', typedAt = 0;
|
|
232
|
-
function openMenu(open) {
|
|
233
|
-
const menu = $('p-mode-list');
|
|
234
|
-
menu.hidden = !open; trigger().setAttribute('aria-expanded', String(open));
|
|
235
|
-
if (open) highlight(options().findIndex(o => o.getAttribute('aria-selected') === 'true'));
|
|
236
|
-
else { trigger().removeAttribute('aria-activedescendant'); for (const o of options()) o.classList.remove('p-highlight'); }
|
|
237
|
-
}
|
|
238
|
-
function highlight(index) {
|
|
239
|
-
const list = options();
|
|
240
|
-
highlighted = Math.max(0, Math.min(list.length - 1, index));
|
|
241
|
-
list.forEach((o, i) => o.classList.toggle('p-highlight', i === highlighted));
|
|
242
|
-
trigger().setAttribute('aria-activedescendant', list[highlighted].id);
|
|
243
|
-
}
|
|
244
|
-
function choose(value) {
|
|
245
|
-
openMenu(false); trigger().focus();
|
|
246
|
-
const full = value === 'full';
|
|
247
|
-
if (!view || full === view.full) return;
|
|
248
|
-
confirmFirst(full ? 'full' : 'restrict', trigger(), () => run(() => ask({ action: 'mode', fullControl: full }), t('modeSaved')));
|
|
249
|
-
}
|
|
250
|
-
function menuKey(event) {
|
|
251
|
-
const open = trigger().getAttribute('aria-expanded') === 'true', list = options();
|
|
252
|
-
if (event.key === 'Tab') { if (open) openMenu(false); return; }
|
|
253
|
-
if (event.key === 'Escape') { if (open) { event.preventDefault(); openMenu(false); } return; }
|
|
254
|
-
if (['ArrowDown', 'ArrowUp', 'Home', 'End', 'PageDown', 'PageUp', 'Enter', ' '].includes(event.key)) {
|
|
255
|
-
event.preventDefault();
|
|
256
|
-
if (!open) { openMenu(true); return; }
|
|
257
|
-
if (event.key === 'Enter' || event.key === ' ') { choose(list[highlighted].dataset.value); return; }
|
|
258
|
-
const step = { ArrowDown: 1, ArrowUp: -1, PageDown: 10, PageUp: -10 }[event.key];
|
|
259
|
-
highlight(event.key === 'Home' ? 0 : event.key === 'End' ? list.length - 1 : highlighted + step);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
if (event.key?.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
263
|
-
if (Date.now() - typedAt > 600) typed = '';
|
|
264
|
-
typedAt = Date.now(); typed += event.key.toLowerCase();
|
|
265
|
-
if (!open) openMenu(true);
|
|
266
|
-
const i = list.findIndex(o => o.textContent.toLowerCase().startsWith(typed));
|
|
267
|
-
if (i >= 0) highlight(i);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// ── actions ──
|
|
272
|
-
function nextFocus(button) {
|
|
273
|
-
// After a row leaves, the focus goes to the next row's action, else the previous one, else the section title.
|
|
274
|
-
const all = [...$('popup').querySelectorAll('[data-action="take-back"]')];
|
|
275
|
-
const i = all.indexOf(button);
|
|
276
|
-
return all[i + 1] || all[i - 1] || null;
|
|
277
|
-
}
|
|
278
|
-
async function takeBack(button, verb) {
|
|
279
|
-
const handle = button.dataset.handle;
|
|
280
|
-
if (!handle || busy.has(handle)) return;
|
|
281
|
-
const after = nextFocus(button);
|
|
282
|
-
busy.add(handle); rowErrors.delete(handle); render(view);
|
|
283
|
-
let ok = false;
|
|
284
|
-
try { await ask({ action: 'revokeTab', tab: handle }); ok = true; }
|
|
285
|
-
catch { rowErrors.add(handle); }
|
|
286
|
-
finally { busy.delete(handle); }
|
|
287
|
-
await refresh();
|
|
288
|
-
if (ok) {
|
|
289
|
-
toast(t(verb === 'take-back' ? 'takenBack' : 'saved'));
|
|
290
|
-
if (!button.isConnected) (after?.isConnected ? after : $('p-activity-title'))?.focus?.();
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async function act(action, target) {
|
|
294
|
-
if (action === 'open-app') { await openTab(`${appOrigin()}/`); return; }
|
|
295
|
-
if (action === 'open-extensions') {
|
|
296
|
-
try { await openTab('chrome://extensions/'); }
|
|
297
|
-
catch { toast(t('openExtensionsFailed'), 'bad'); }
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
if (action === 'reload-extension') {
|
|
301
|
-
try { chrome.runtime.reload(); }
|
|
302
|
-
catch { toast(t('reloadExtensionFailed'), 'bad'); }
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
if (action === 'connect') { await openTab(`${appOrigin()}/extension-setup`); toast(t('connectOpened')); return; }
|
|
306
|
-
if (action === 'retry') { await refresh(); return; }
|
|
307
|
-
if (action === 'resume') { await run(() => ask({ action: 'resume' }), t('reconnectingToast')); return; }
|
|
308
|
-
if (action === 'confirm-disconnect') { confirmFirst('disconnect', target, () => run(() => ask({ action: 'disconnect' }), t('disconnectedToast'))); return; }
|
|
309
|
-
if (action === 'confirm-revoke') { confirmFirst('revoke', target, () => run(() => ask({ action: 'revoke' }), t('revokedToast'))); return; }
|
|
310
|
-
if (action === 'confirm-site') { const site = target.dataset.site; confirmFirst('site', target, () => run(() => ask({ action: 'revokeSite', site }), t('saved'))); return; }
|
|
311
|
-
if (action === 'take-back' || action === 'stop-sharing') { await takeBack(target, action); return; }
|
|
312
|
-
if (action === 'cancel-confirm') { closeConfirm(); return; }
|
|
313
|
-
if (action === 'do-confirm') { const next = pending?.action; closeConfirm(); if (next) await next(); return; }
|
|
314
|
-
// Restricted mode: share the browser's active tab (and its site), or only its site for new tabs. The site permission
|
|
315
|
-
// is asked in this click, as before.
|
|
316
|
-
if (action === 'share' || action === 'site') {
|
|
317
|
-
const siteOnly = action === 'site';
|
|
318
|
-
await run(async () => {
|
|
319
|
-
const tab = (await chrome.tabs.query({ active: true, currentWindow: true }))[0];
|
|
320
|
-
const site = publicOrigin(tab?.url);
|
|
321
|
-
if (!await chrome.permissions.request({ origins: [hostPattern(site)] })) throw coded('SITE_DENIED');
|
|
322
|
-
await ask({ action: 'share', tab: tab.id, siteOnly });
|
|
323
|
-
}, t(siteOnly ? 'siteToast' : 'sharedToast'));
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function wire() {
|
|
328
|
-
document.addEventListener('click', event => {
|
|
329
|
-
const option = event.target.closest?.('[role="option"]');
|
|
330
|
-
if (option && $('p-mode-list').contains(option)) { choose(option.dataset.value); return; }
|
|
331
|
-
if (event.target.closest?.('.p-dropdown-trigger')) { openMenu(trigger().getAttribute('aria-expanded') !== 'true'); return; }
|
|
332
|
-
const target = event.target.closest?.('[data-action]');
|
|
333
|
-
if (target && !target.disabled) void act(target.dataset.action, target);
|
|
334
|
-
});
|
|
335
|
-
trigger().addEventListener('keydown', menuKey);
|
|
336
|
-
document.addEventListener('pointerdown', event => { if (!event.target.closest?.('.p-dropdown')) openMenu(false); });
|
|
337
|
-
const dialog = $('p-confirm');
|
|
338
|
-
// Escape cancels (the dialog's own cancel event); the focus goes back to the control that opened it.
|
|
339
|
-
dialog.addEventListener('cancel', event => { event.preventDefault(); closeConfirm(); });
|
|
340
|
-
for (const id of ['newTabs', 'downloads']) $(id).addEventListener('change', () => run(async () => {
|
|
341
|
-
$('p-downloads-denied').hidden = true;
|
|
342
|
-
if (id === 'downloads' && $('downloads').checked && !await chrome.permissions.request({ permissions: ['downloads'] })) {
|
|
343
|
-
$('downloads').checked = false; $('p-downloads-denied').hidden = false; $('p-files').open = true;
|
|
344
|
-
}
|
|
345
|
-
await ask({ action: 'options', options: { allowNewTabs: $('newTabs').checked, downloads: $('downloads').checked } });
|
|
346
|
-
}, t('saved')));
|
|
347
|
-
$('port').addEventListener('input', () => { portTouched = true; });
|
|
348
|
-
$('pair').addEventListener('submit', event => {
|
|
349
|
-
event.preventDefault();
|
|
350
|
-
void run(async () => { await ask({ action: 'pair', code: $('code').value, port: Number($('port').value) }); $('code').value = ''; }, t('pairStarted'));
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
fixedText();
|
|
355
|
-
wire();
|
|
356
|
-
render(popupView(undefined, { t }));
|
|
357
|
-
await refresh();
|
|
358
|
-
const timer = setInterval(() => { void refresh(); }, 1500);
|
|
359
|
-
window.addEventListener('unload', () => clearInterval(timer));
|