@xlinklight/browser-extension-tools 1.0.0-rc.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +33 -33
- package/assets/shared/css/side-panel.css +94 -94
- package/assets/shared/js/chrome-runtime.js +87 -87
- package/assets/shared/js/extension-account-menu.js +239 -239
- package/assets/shared/js/extension-i18n.js +42 -42
- package/assets/shared/js/extension-session-store.js +42 -42
- package/assets/shared/js/extension-tabs.js +23 -23
- package/assets/shared/js/link-light-api-client.js +31 -31
- package/assets/shared/js/side-panel-account.js +14 -14
- package/assets/shared/js/side-panel-api.js +13 -13
- package/assets/shared/js/side-panel-bootstrap.js +127 -127
- package/assets/shared/js/side-panel-dom.js +15 -15
- package/assets/shared/js/side-panel-i18n.js +37 -37
- package/assets/shared/js/side-panel-import-preview.js +7 -7
- package/assets/shared/js/side-panel-status.js +13 -13
- package/assets/shared/js/side-panel-tabs.js +35 -35
- package/assets/shared/js/side-panel-translations.js +41 -41
- package/package.json +1 -1
- package/src/chrome-discovery.mjs +231 -231
- package/src/chrome-for-testing.mjs +203 -203
- package/src/chrome-install-worker.mjs +8 -8
- package/src/cli.mjs +171 -171
- package/src/dev-cli.mjs +9 -9
- package/src/dev-extension.mjs +350 -350
- package/src/package-cli.mjs +7 -7
- package/src/package.mjs +223 -223
- package/src/profile.mjs +144 -144
- package/src/reload-server.mjs +108 -108
- package/src/run.mjs +7 -7
- package/src/watcher.mjs +45 -45
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
(function initializeLinkLightAccountMenu(global) {
|
|
2
|
-
const defaultKeys = {
|
|
3
|
-
token: "linkLightSessionToken",
|
|
4
|
-
expiresAt: "linkLightSessionExpiresAt",
|
|
5
|
-
user: "linkLightUserSummary",
|
|
6
|
-
workspace: "linkLightWorkspaceSummary",
|
|
7
|
-
};
|
|
8
|
-
const pairingStorageKey = "linkLightPairing";
|
|
9
|
-
const pairingPollIntervalMs = 2000;
|
|
10
|
-
|
|
11
|
-
function createExtensionAccountMenu({
|
|
12
|
-
runtime,
|
|
13
|
-
sessionStore = global.LinkLightSessionStore.createExtensionSessionStore(runtime, defaultKeys),
|
|
14
|
-
documentRef = global.document,
|
|
15
|
-
t = (key) => key,
|
|
16
|
-
getLocale = () => "zh-CN",
|
|
17
|
-
setStatus = () => undefined,
|
|
18
|
-
onStateChange = () => undefined,
|
|
19
|
-
onSignedOut = () => undefined,
|
|
20
|
-
openUrl = (url) => global.open(url, "_blank", "noopener"),
|
|
21
|
-
deviceName = "Chrome Side Panel",
|
|
22
|
-
}) {
|
|
23
|
-
const accountButton = documentRef.querySelector("#ll-account-button");
|
|
24
|
-
const userMenu = documentRef.querySelector("#ll-user-menu");
|
|
25
|
-
const userEmail = documentRef.querySelector("#ll-user-email");
|
|
26
|
-
const userWorkspace = documentRef.querySelector("#ll-user-workspace");
|
|
27
|
-
const userPlan = documentRef.querySelector("#ll-user-plan");
|
|
28
|
-
const signInButton = documentRef.querySelector("#ll-account-sign-in");
|
|
29
|
-
const accountOpenButton = documentRef.querySelector("#ll-account-open");
|
|
30
|
-
const accountDevicesButton = documentRef.querySelector("#ll-account-devices");
|
|
31
|
-
const accountHelpButton = documentRef.querySelector("#ll-account-help");
|
|
32
|
-
const accountFeedbackButton = documentRef.querySelector("#ll-account-feedback");
|
|
33
|
-
const accountLogoutButton = documentRef.querySelector("#ll-account-logout");
|
|
34
|
-
|
|
35
|
-
let accountState = { token: "", expiresAt: "", user: null, workspace: null };
|
|
36
|
-
|
|
37
|
-
function setMenuExpanded(expanded) {
|
|
38
|
-
if (userMenu) userMenu.hidden = !expanded;
|
|
39
|
-
accountButton?.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function openMenu() {
|
|
43
|
-
setMenuExpanded(true);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function closeMenu() {
|
|
47
|
-
setMenuExpanded(false);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function toggleMenu() {
|
|
51
|
-
if (userMenu && !userMenu.hidden) closeMenu();
|
|
52
|
-
else openMenu();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function isMenuEventTarget(target) {
|
|
56
|
-
return Boolean(
|
|
57
|
-
target
|
|
58
|
-
&& (accountButton?.contains(target) || userMenu?.contains(target)),
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function handleDocumentClick(event) {
|
|
63
|
-
if (!isMenuEventTarget(event.target)) closeMenu();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function handleDocumentKeydown(event) {
|
|
67
|
-
if (event.key === "Escape") closeMenu();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function accountUrl(path = "") {
|
|
71
|
-
return `${runtime.origin}/${getLocale()}${path}`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function isSignedIn() {
|
|
75
|
-
return sessionStore.isSignedIn(accountState);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function headers() {
|
|
79
|
-
return sessionStore.headers(accountState);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function getAccountState() {
|
|
83
|
-
return accountState;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function render() {
|
|
87
|
-
const signedIn = isSignedIn();
|
|
88
|
-
if (accountButton) {
|
|
89
|
-
accountButton.textContent = signedIn ? "L" : "?";
|
|
90
|
-
if (!accountButton.hasAttribute("aria-expanded")) accountButton.setAttribute("aria-expanded", "false");
|
|
91
|
-
}
|
|
92
|
-
if (userEmail) {
|
|
93
|
-
userEmail.textContent = signedIn
|
|
94
|
-
? accountState.user?.email || accountState.user?.id || t("accountMenuSignedIn")
|
|
95
|
-
: t("accountMenuSignedOut");
|
|
96
|
-
}
|
|
97
|
-
if (userWorkspace) userWorkspace.textContent = signedIn ? accountState.workspace?.name || accountState.workspace?.id || "" : "";
|
|
98
|
-
if (userPlan) userPlan.textContent = signedIn ? t("accountMenuPlan") : t("accountMenuSignInRequired");
|
|
99
|
-
if (signInButton) signInButton.hidden = signedIn;
|
|
100
|
-
if (accountOpenButton) accountOpenButton.hidden = !signedIn;
|
|
101
|
-
if (accountDevicesButton) accountDevicesButton.hidden = !signedIn;
|
|
102
|
-
if (accountLogoutButton) accountLogoutButton.hidden = !signedIn;
|
|
103
|
-
onStateChange({ signedIn, state: accountState });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function readAccountState() {
|
|
107
|
-
accountState = await sessionStore.read();
|
|
108
|
-
render();
|
|
109
|
-
return accountState;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async function saveApprovedSession(data) {
|
|
113
|
-
accountState = {
|
|
114
|
-
token: String(data.sessionToken || ""),
|
|
115
|
-
expiresAt: String(data.expiresAt || ""),
|
|
116
|
-
user: data.user || null,
|
|
117
|
-
workspace: data.workspace || null,
|
|
118
|
-
};
|
|
119
|
-
await sessionStore.save(accountState);
|
|
120
|
-
render();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async function startPairing() {
|
|
124
|
-
setStatus("statusPairingStarted");
|
|
125
|
-
const response = await global.fetch(`${runtime.origin}/api/auth/extension/pairings`, {
|
|
126
|
-
method: "POST",
|
|
127
|
-
headers: { "Content-Type": "application/json" },
|
|
128
|
-
body: JSON.stringify({ deviceName, locale: getLocale() }),
|
|
129
|
-
});
|
|
130
|
-
const data = await response.json();
|
|
131
|
-
|
|
132
|
-
if (!response.ok) throw new Error(data?.error?.code || "errorPairingFailed");
|
|
133
|
-
|
|
134
|
-
await runtime.storage.set({ [pairingStorageKey]: data });
|
|
135
|
-
openUrl(data.verificationUrl);
|
|
136
|
-
await pollExtensionPairingUntilApproved(data);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async function pollExtensionPairing(pairing) {
|
|
140
|
-
const response = await global.fetch(`${runtime.origin}/api/auth/extension/pairings/${pairing.pairingId}`, {
|
|
141
|
-
headers: { Authorization: `Bearer ${pairing.pairingToken}` },
|
|
142
|
-
});
|
|
143
|
-
const data = await response.json();
|
|
144
|
-
|
|
145
|
-
if (response.ok && data.status === "approved") {
|
|
146
|
-
await saveApprovedSession(data);
|
|
147
|
-
await runtime.storage.remove([pairingStorageKey]);
|
|
148
|
-
setStatus("statusPairingApproved");
|
|
149
|
-
return data;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
setStatus("statusPairingPending");
|
|
153
|
-
return data;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
async function pollExtensionPairingUntilApproved(pairing) {
|
|
157
|
-
const expiresAt = Date.parse(pairing.expiresAt);
|
|
158
|
-
|
|
159
|
-
while (Number.isNaN(expiresAt) || Date.now() < expiresAt) {
|
|
160
|
-
const result = await pollExtensionPairing(pairing);
|
|
161
|
-
if (result?.status === "approved") return;
|
|
162
|
-
await waitForPairingPoll();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
await runtime.storage.remove([pairingStorageKey]);
|
|
166
|
-
setStatus("statusPairingExpired");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function waitForPairingPoll() {
|
|
170
|
-
return new Promise((resolve) => global.setTimeout(resolve, pairingPollIntervalMs));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async function logout() {
|
|
174
|
-
if (accountState.token) {
|
|
175
|
-
await global.fetch(`${runtime.origin}/api/auth/extension/sessions/revoke`, {
|
|
176
|
-
method: "POST",
|
|
177
|
-
headers: { Authorization: `Bearer ${accountState.token}` },
|
|
178
|
-
}).catch(() => null);
|
|
179
|
-
}
|
|
180
|
-
await sessionStore.clear([pairingStorageKey]);
|
|
181
|
-
accountState = { token: "", expiresAt: "", user: null, workspace: null };
|
|
182
|
-
onSignedOut();
|
|
183
|
-
render();
|
|
184
|
-
setStatus("statusSignedOut");
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function initializeActions() {
|
|
188
|
-
closeMenu();
|
|
189
|
-
accountButton?.addEventListener("click", (event) => {
|
|
190
|
-
event.stopPropagation();
|
|
191
|
-
toggleMenu();
|
|
192
|
-
});
|
|
193
|
-
signInButton?.addEventListener("click", async () => {
|
|
194
|
-
closeMenu();
|
|
195
|
-
try {
|
|
196
|
-
await startPairing();
|
|
197
|
-
} catch (error) {
|
|
198
|
-
setStatus(error instanceof Error && t(error.message) !== error.message ? error.message : "errorPairingFailed");
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
accountOpenButton?.addEventListener("click", () => {
|
|
202
|
-
closeMenu();
|
|
203
|
-
openUrl(accountUrl("/account"));
|
|
204
|
-
});
|
|
205
|
-
accountDevicesButton?.addEventListener("click", () => {
|
|
206
|
-
closeMenu();
|
|
207
|
-
openUrl(accountUrl("/account/devices"));
|
|
208
|
-
});
|
|
209
|
-
accountHelpButton?.addEventListener("click", () => {
|
|
210
|
-
closeMenu();
|
|
211
|
-
openUrl(accountUrl(""));
|
|
212
|
-
});
|
|
213
|
-
accountFeedbackButton?.addEventListener("click", () => {
|
|
214
|
-
closeMenu();
|
|
215
|
-
openUrl(accountUrl("/account"));
|
|
216
|
-
});
|
|
217
|
-
accountLogoutButton?.addEventListener("click", async () => {
|
|
218
|
-
closeMenu();
|
|
219
|
-
await logout();
|
|
220
|
-
});
|
|
221
|
-
documentRef.addEventListener("click", handleDocumentClick);
|
|
222
|
-
documentRef.addEventListener("keydown", handleDocumentKeydown);
|
|
223
|
-
global.addEventListener("blur", closeMenu);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
getAccountState,
|
|
228
|
-
headers,
|
|
229
|
-
initializeActions,
|
|
230
|
-
isSignedIn,
|
|
231
|
-
logout,
|
|
232
|
-
readAccountState,
|
|
233
|
-
render,
|
|
234
|
-
startPairing,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
global.LinkLightAccountMenu = { createExtensionAccountMenu };
|
|
239
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightAccountMenu(global) {
|
|
2
|
+
const defaultKeys = {
|
|
3
|
+
token: "linkLightSessionToken",
|
|
4
|
+
expiresAt: "linkLightSessionExpiresAt",
|
|
5
|
+
user: "linkLightUserSummary",
|
|
6
|
+
workspace: "linkLightWorkspaceSummary",
|
|
7
|
+
};
|
|
8
|
+
const pairingStorageKey = "linkLightPairing";
|
|
9
|
+
const pairingPollIntervalMs = 2000;
|
|
10
|
+
|
|
11
|
+
function createExtensionAccountMenu({
|
|
12
|
+
runtime,
|
|
13
|
+
sessionStore = global.LinkLightSessionStore.createExtensionSessionStore(runtime, defaultKeys),
|
|
14
|
+
documentRef = global.document,
|
|
15
|
+
t = (key) => key,
|
|
16
|
+
getLocale = () => "zh-CN",
|
|
17
|
+
setStatus = () => undefined,
|
|
18
|
+
onStateChange = () => undefined,
|
|
19
|
+
onSignedOut = () => undefined,
|
|
20
|
+
openUrl = (url) => global.open(url, "_blank", "noopener"),
|
|
21
|
+
deviceName = "Chrome Side Panel",
|
|
22
|
+
}) {
|
|
23
|
+
const accountButton = documentRef.querySelector("#ll-account-button");
|
|
24
|
+
const userMenu = documentRef.querySelector("#ll-user-menu");
|
|
25
|
+
const userEmail = documentRef.querySelector("#ll-user-email");
|
|
26
|
+
const userWorkspace = documentRef.querySelector("#ll-user-workspace");
|
|
27
|
+
const userPlan = documentRef.querySelector("#ll-user-plan");
|
|
28
|
+
const signInButton = documentRef.querySelector("#ll-account-sign-in");
|
|
29
|
+
const accountOpenButton = documentRef.querySelector("#ll-account-open");
|
|
30
|
+
const accountDevicesButton = documentRef.querySelector("#ll-account-devices");
|
|
31
|
+
const accountHelpButton = documentRef.querySelector("#ll-account-help");
|
|
32
|
+
const accountFeedbackButton = documentRef.querySelector("#ll-account-feedback");
|
|
33
|
+
const accountLogoutButton = documentRef.querySelector("#ll-account-logout");
|
|
34
|
+
|
|
35
|
+
let accountState = { token: "", expiresAt: "", user: null, workspace: null };
|
|
36
|
+
|
|
37
|
+
function setMenuExpanded(expanded) {
|
|
38
|
+
if (userMenu) userMenu.hidden = !expanded;
|
|
39
|
+
accountButton?.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function openMenu() {
|
|
43
|
+
setMenuExpanded(true);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function closeMenu() {
|
|
47
|
+
setMenuExpanded(false);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function toggleMenu() {
|
|
51
|
+
if (userMenu && !userMenu.hidden) closeMenu();
|
|
52
|
+
else openMenu();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isMenuEventTarget(target) {
|
|
56
|
+
return Boolean(
|
|
57
|
+
target
|
|
58
|
+
&& (accountButton?.contains(target) || userMenu?.contains(target)),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function handleDocumentClick(event) {
|
|
63
|
+
if (!isMenuEventTarget(event.target)) closeMenu();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function handleDocumentKeydown(event) {
|
|
67
|
+
if (event.key === "Escape") closeMenu();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function accountUrl(path = "") {
|
|
71
|
+
return `${runtime.origin}/${getLocale()}${path}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function isSignedIn() {
|
|
75
|
+
return sessionStore.isSignedIn(accountState);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function headers() {
|
|
79
|
+
return sessionStore.headers(accountState);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getAccountState() {
|
|
83
|
+
return accountState;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function render() {
|
|
87
|
+
const signedIn = isSignedIn();
|
|
88
|
+
if (accountButton) {
|
|
89
|
+
accountButton.textContent = signedIn ? "L" : "?";
|
|
90
|
+
if (!accountButton.hasAttribute("aria-expanded")) accountButton.setAttribute("aria-expanded", "false");
|
|
91
|
+
}
|
|
92
|
+
if (userEmail) {
|
|
93
|
+
userEmail.textContent = signedIn
|
|
94
|
+
? accountState.user?.email || accountState.user?.id || t("accountMenuSignedIn")
|
|
95
|
+
: t("accountMenuSignedOut");
|
|
96
|
+
}
|
|
97
|
+
if (userWorkspace) userWorkspace.textContent = signedIn ? accountState.workspace?.name || accountState.workspace?.id || "" : "";
|
|
98
|
+
if (userPlan) userPlan.textContent = signedIn ? t("accountMenuPlan") : t("accountMenuSignInRequired");
|
|
99
|
+
if (signInButton) signInButton.hidden = signedIn;
|
|
100
|
+
if (accountOpenButton) accountOpenButton.hidden = !signedIn;
|
|
101
|
+
if (accountDevicesButton) accountDevicesButton.hidden = !signedIn;
|
|
102
|
+
if (accountLogoutButton) accountLogoutButton.hidden = !signedIn;
|
|
103
|
+
onStateChange({ signedIn, state: accountState });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function readAccountState() {
|
|
107
|
+
accountState = await sessionStore.read();
|
|
108
|
+
render();
|
|
109
|
+
return accountState;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function saveApprovedSession(data) {
|
|
113
|
+
accountState = {
|
|
114
|
+
token: String(data.sessionToken || ""),
|
|
115
|
+
expiresAt: String(data.expiresAt || ""),
|
|
116
|
+
user: data.user || null,
|
|
117
|
+
workspace: data.workspace || null,
|
|
118
|
+
};
|
|
119
|
+
await sessionStore.save(accountState);
|
|
120
|
+
render();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function startPairing() {
|
|
124
|
+
setStatus("statusPairingStarted");
|
|
125
|
+
const response = await global.fetch(`${runtime.origin}/api/auth/extension/pairings`, {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: { "Content-Type": "application/json" },
|
|
128
|
+
body: JSON.stringify({ deviceName, locale: getLocale() }),
|
|
129
|
+
});
|
|
130
|
+
const data = await response.json();
|
|
131
|
+
|
|
132
|
+
if (!response.ok) throw new Error(data?.error?.code || "errorPairingFailed");
|
|
133
|
+
|
|
134
|
+
await runtime.storage.set({ [pairingStorageKey]: data });
|
|
135
|
+
openUrl(data.verificationUrl);
|
|
136
|
+
await pollExtensionPairingUntilApproved(data);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function pollExtensionPairing(pairing) {
|
|
140
|
+
const response = await global.fetch(`${runtime.origin}/api/auth/extension/pairings/${pairing.pairingId}`, {
|
|
141
|
+
headers: { Authorization: `Bearer ${pairing.pairingToken}` },
|
|
142
|
+
});
|
|
143
|
+
const data = await response.json();
|
|
144
|
+
|
|
145
|
+
if (response.ok && data.status === "approved") {
|
|
146
|
+
await saveApprovedSession(data);
|
|
147
|
+
await runtime.storage.remove([pairingStorageKey]);
|
|
148
|
+
setStatus("statusPairingApproved");
|
|
149
|
+
return data;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setStatus("statusPairingPending");
|
|
153
|
+
return data;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function pollExtensionPairingUntilApproved(pairing) {
|
|
157
|
+
const expiresAt = Date.parse(pairing.expiresAt);
|
|
158
|
+
|
|
159
|
+
while (Number.isNaN(expiresAt) || Date.now() < expiresAt) {
|
|
160
|
+
const result = await pollExtensionPairing(pairing);
|
|
161
|
+
if (result?.status === "approved") return;
|
|
162
|
+
await waitForPairingPoll();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
await runtime.storage.remove([pairingStorageKey]);
|
|
166
|
+
setStatus("statusPairingExpired");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function waitForPairingPoll() {
|
|
170
|
+
return new Promise((resolve) => global.setTimeout(resolve, pairingPollIntervalMs));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function logout() {
|
|
174
|
+
if (accountState.token) {
|
|
175
|
+
await global.fetch(`${runtime.origin}/api/auth/extension/sessions/revoke`, {
|
|
176
|
+
method: "POST",
|
|
177
|
+
headers: { Authorization: `Bearer ${accountState.token}` },
|
|
178
|
+
}).catch(() => null);
|
|
179
|
+
}
|
|
180
|
+
await sessionStore.clear([pairingStorageKey]);
|
|
181
|
+
accountState = { token: "", expiresAt: "", user: null, workspace: null };
|
|
182
|
+
onSignedOut();
|
|
183
|
+
render();
|
|
184
|
+
setStatus("statusSignedOut");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function initializeActions() {
|
|
188
|
+
closeMenu();
|
|
189
|
+
accountButton?.addEventListener("click", (event) => {
|
|
190
|
+
event.stopPropagation();
|
|
191
|
+
toggleMenu();
|
|
192
|
+
});
|
|
193
|
+
signInButton?.addEventListener("click", async () => {
|
|
194
|
+
closeMenu();
|
|
195
|
+
try {
|
|
196
|
+
await startPairing();
|
|
197
|
+
} catch (error) {
|
|
198
|
+
setStatus(error instanceof Error && t(error.message) !== error.message ? error.message : "errorPairingFailed");
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
accountOpenButton?.addEventListener("click", () => {
|
|
202
|
+
closeMenu();
|
|
203
|
+
openUrl(accountUrl("/account"));
|
|
204
|
+
});
|
|
205
|
+
accountDevicesButton?.addEventListener("click", () => {
|
|
206
|
+
closeMenu();
|
|
207
|
+
openUrl(accountUrl("/account/devices"));
|
|
208
|
+
});
|
|
209
|
+
accountHelpButton?.addEventListener("click", () => {
|
|
210
|
+
closeMenu();
|
|
211
|
+
openUrl(accountUrl(""));
|
|
212
|
+
});
|
|
213
|
+
accountFeedbackButton?.addEventListener("click", () => {
|
|
214
|
+
closeMenu();
|
|
215
|
+
openUrl(accountUrl("/account"));
|
|
216
|
+
});
|
|
217
|
+
accountLogoutButton?.addEventListener("click", async () => {
|
|
218
|
+
closeMenu();
|
|
219
|
+
await logout();
|
|
220
|
+
});
|
|
221
|
+
documentRef.addEventListener("click", handleDocumentClick);
|
|
222
|
+
documentRef.addEventListener("keydown", handleDocumentKeydown);
|
|
223
|
+
global.addEventListener("blur", closeMenu);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
getAccountState,
|
|
228
|
+
headers,
|
|
229
|
+
initializeActions,
|
|
230
|
+
isSignedIn,
|
|
231
|
+
logout,
|
|
232
|
+
readAccountState,
|
|
233
|
+
render,
|
|
234
|
+
startPairing,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
global.LinkLightAccountMenu = { createExtensionAccountMenu };
|
|
239
|
+
})(globalThis);
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
(function initializeLinkLightExtensionI18n(global) {
|
|
2
|
-
function createExtensionI18n(runtime, options = {}) {
|
|
3
|
-
const fallbackLocale = options.fallbackLocale || "zh-CN";
|
|
4
|
-
const localeDirectories = options.localeDirectories || { "zh-CN": "zh_CN", "en-US": "en" };
|
|
5
|
-
let messages = {};
|
|
6
|
-
|
|
7
|
-
function normalizeLanguagePreference(value) {
|
|
8
|
-
if (value === "zh-CN" || value === "en-US") return value;
|
|
9
|
-
return "auto";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function resolveLocale(preference) {
|
|
13
|
-
if (preference === "zh-CN" || preference === "en-US") return preference;
|
|
14
|
-
return runtime.getUILocale ? runtime.getUILocale() : fallbackLocale;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function loadMessages(locale) {
|
|
18
|
-
const directory = localeDirectories[locale] ?? localeDirectories[fallbackLocale];
|
|
19
|
-
const catalog = await runtime.loadLocaleMessages(directory);
|
|
20
|
-
messages = Object.fromEntries(
|
|
21
|
-
Object.entries(catalog).map(([key, value]) => [key, typeof value?.message === "string" ? value.message : ""]),
|
|
22
|
-
);
|
|
23
|
-
return messages;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function interpolate(template, values = {}) {
|
|
27
|
-
return String(template || "").replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ""));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function t(key, values = {}) {
|
|
31
|
-
return interpolate(messages[key] ?? key, values);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function hasMessage(key) {
|
|
35
|
-
return Object.prototype.hasOwnProperty.call(messages, key);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return { hasMessage, loadMessages, normalizeLanguagePreference, resolveLocale, t };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
global.LinkLightExtensionI18n = { createExtensionI18n };
|
|
42
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightExtensionI18n(global) {
|
|
2
|
+
function createExtensionI18n(runtime, options = {}) {
|
|
3
|
+
const fallbackLocale = options.fallbackLocale || "zh-CN";
|
|
4
|
+
const localeDirectories = options.localeDirectories || { "zh-CN": "zh_CN", "en-US": "en" };
|
|
5
|
+
let messages = {};
|
|
6
|
+
|
|
7
|
+
function normalizeLanguagePreference(value) {
|
|
8
|
+
if (value === "zh-CN" || value === "en-US") return value;
|
|
9
|
+
return "auto";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function resolveLocale(preference) {
|
|
13
|
+
if (preference === "zh-CN" || preference === "en-US") return preference;
|
|
14
|
+
return runtime.getUILocale ? runtime.getUILocale() : fallbackLocale;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function loadMessages(locale) {
|
|
18
|
+
const directory = localeDirectories[locale] ?? localeDirectories[fallbackLocale];
|
|
19
|
+
const catalog = await runtime.loadLocaleMessages(directory);
|
|
20
|
+
messages = Object.fromEntries(
|
|
21
|
+
Object.entries(catalog).map(([key, value]) => [key, typeof value?.message === "string" ? value.message : ""]),
|
|
22
|
+
);
|
|
23
|
+
return messages;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function interpolate(template, values = {}) {
|
|
27
|
+
return String(template || "").replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ""));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function t(key, values = {}) {
|
|
31
|
+
return interpolate(messages[key] ?? key, values);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function hasMessage(key) {
|
|
35
|
+
return Object.prototype.hasOwnProperty.call(messages, key);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { hasMessage, loadMessages, normalizeLanguagePreference, resolveLocale, t };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
global.LinkLightExtensionI18n = { createExtensionI18n };
|
|
42
|
+
})(globalThis);
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
(function initializeLinkLightSessionStore(global) {
|
|
2
|
-
function createExtensionSessionStore(runtime, keys) {
|
|
3
|
-
async function read() {
|
|
4
|
-
const result = await runtime.storage.get(Object.values(keys));
|
|
5
|
-
return {
|
|
6
|
-
expiresAt: String(result?.[keys.expiresAt] || ""),
|
|
7
|
-
token: String(result?.[keys.token] || ""),
|
|
8
|
-
user: keys.user ? result?.[keys.user] || null : null,
|
|
9
|
-
workspace: keys.workspace ? result?.[keys.workspace] || null : null,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async function save(state) {
|
|
14
|
-
const values = {
|
|
15
|
-
[keys.token]: state.token || "",
|
|
16
|
-
[keys.expiresAt]: state.expiresAt || "",
|
|
17
|
-
};
|
|
18
|
-
if (keys.user) values[keys.user] = state.user || null;
|
|
19
|
-
if (keys.workspace) values[keys.workspace] = state.workspace || null;
|
|
20
|
-
await runtime.storage.set(values);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function clear(extraKeys = []) {
|
|
24
|
-
await runtime.storage.remove([...Object.values(keys), ...extraKeys]);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function isSignedIn(state) {
|
|
28
|
-
return Boolean(state?.token && state?.expiresAt && new Date(state.expiresAt).getTime() > Date.now());
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function headers(state) {
|
|
32
|
-
const requestHeaders = { "Content-Type": "application/json" };
|
|
33
|
-
if (!isSignedIn(state)) throw new Error("authentication_required");
|
|
34
|
-
requestHeaders.Authorization = `Bearer ${state.token}`;
|
|
35
|
-
return requestHeaders;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return { clear, headers, isSignedIn, read, save };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
global.LinkLightSessionStore = { createExtensionSessionStore };
|
|
42
|
-
})(globalThis);
|
|
1
|
+
(function initializeLinkLightSessionStore(global) {
|
|
2
|
+
function createExtensionSessionStore(runtime, keys) {
|
|
3
|
+
async function read() {
|
|
4
|
+
const result = await runtime.storage.get(Object.values(keys));
|
|
5
|
+
return {
|
|
6
|
+
expiresAt: String(result?.[keys.expiresAt] || ""),
|
|
7
|
+
token: String(result?.[keys.token] || ""),
|
|
8
|
+
user: keys.user ? result?.[keys.user] || null : null,
|
|
9
|
+
workspace: keys.workspace ? result?.[keys.workspace] || null : null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function save(state) {
|
|
14
|
+
const values = {
|
|
15
|
+
[keys.token]: state.token || "",
|
|
16
|
+
[keys.expiresAt]: state.expiresAt || "",
|
|
17
|
+
};
|
|
18
|
+
if (keys.user) values[keys.user] = state.user || null;
|
|
19
|
+
if (keys.workspace) values[keys.workspace] = state.workspace || null;
|
|
20
|
+
await runtime.storage.set(values);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function clear(extraKeys = []) {
|
|
24
|
+
await runtime.storage.remove([...Object.values(keys), ...extraKeys]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isSignedIn(state) {
|
|
28
|
+
return Boolean(state?.token && state?.expiresAt && new Date(state.expiresAt).getTime() > Date.now());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function headers(state) {
|
|
32
|
+
const requestHeaders = { "Content-Type": "application/json" };
|
|
33
|
+
if (!isSignedIn(state)) throw new Error("authentication_required");
|
|
34
|
+
requestHeaders.Authorization = `Bearer ${state.token}`;
|
|
35
|
+
return requestHeaders;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { clear, headers, isSignedIn, read, save };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
global.LinkLightSessionStore = { createExtensionSessionStore };
|
|
42
|
+
})(globalThis);
|