codex-overleaf-link 1.9.3 → 1.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -23
- package/extension/bootstrap/manifest.template.json +1 -1
- package/extension/runtime-manifest.json +1 -0
- package/extension/src/background.js +20 -0
- package/extension/src/backgroundUpdateCoordinator.js +414 -0
- package/extension/src/content/contentRuntime.js +3 -0
- package/extension/src/content/updateNotice.js +248 -0
- package/extension/src/popup.js +268 -3
- package/extension/src/shared/compatibility.js +1 -1
- package/extension/src/shared/updateConsent.js +201 -0
- package/extension/styles/panel.css +146 -0
- package/native-host/src/updateManager.js +257 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<h1>Codex Overleaf Link</h1>
|
|
4
4
|
<p><strong>Empower Overleaf with Codex.</strong></p>
|
|
5
5
|
<p>
|
|
6
|
-
<img src="https://img.shields.io/badge/version-1.9.
|
|
6
|
+
<img src="https://img.shields.io/badge/version-1.9.5-blue" alt="version">
|
|
7
7
|
<img src="https://img.shields.io/badge/platform-macOS%20%2F%20Windows%20%2F%20Linux-lightgrey" alt="platform">
|
|
8
8
|
<img src="https://img.shields.io/badge/chrome-MV3-green" alt="chrome manifest v3">
|
|
9
9
|
<img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="node version">
|
|
@@ -38,14 +38,14 @@ One command installs the managed native host **and** managed extension runtime.
|
|
|
38
38
|
macOS / Linux:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
CODEX_OVERLEAF_REF=v1.9.
|
|
41
|
+
CODEX_OVERLEAF_REF=v1.9.5 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.5/install.sh)"
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Windows PowerShell:
|
|
45
45
|
|
|
46
46
|
```powershell
|
|
47
|
-
iwr https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.
|
|
48
|
-
$env:CODEX_OVERLEAF_REF='v1.9.
|
|
47
|
+
iwr https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.5/install.ps1 -OutFile install.ps1
|
|
48
|
+
$env:CODEX_OVERLEAF_REF='v1.9.5'
|
|
49
49
|
powershell -ExecutionPolicy Bypass -File install.ps1
|
|
50
50
|
```
|
|
51
51
|
|
|
@@ -56,7 +56,7 @@ Then, in the `chrome://extensions` tab the script opened: enable **Developer mod
|
|
|
56
56
|
`npm exec` installs the same managed native host and extension runtime without keeping a source checkout. Use it if you prefer a pinned npm package.
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
59
|
+
npm exec --yes codex-overleaf-link@1.9.5 -- install-managed
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
Then, in `chrome://extensions`, enable **Developer mode**, click **Load unpacked**, and select the managed extension path printed by the command. The Release extension zip remains available for explicitly unmanaged/manual installations.
|
|
@@ -86,9 +86,9 @@ npm installs, updates, and uninstalls the coordinated managed extension/native p
|
|
|
86
86
|
|
|
87
87
|
| Action | Command |
|
|
88
88
|
|--------|---------|
|
|
89
|
-
| Install / update | `npm exec --yes codex-overleaf-link@1.9.
|
|
90
|
-
| Diagnose | `npm exec --yes codex-overleaf-link@1.9.
|
|
91
|
-
| Uninstall | `npm exec --yes codex-overleaf-link@1.9.
|
|
89
|
+
| Install / update | `npm exec --yes codex-overleaf-link@1.9.5 -- install-managed` |
|
|
90
|
+
| Diagnose | `npm exec --yes codex-overleaf-link@1.9.5 -- doctor` |
|
|
91
|
+
| Uninstall | `npm exec --yes codex-overleaf-link@1.9.5 -- uninstall-managed` |
|
|
92
92
|
|
|
93
93
|
Use `--extension-id <chrome-extension-id>` only for a custom/dev unpacked extension id that differs from the official bundled id.
|
|
94
94
|
|
|
@@ -98,13 +98,13 @@ Managed installations discover signed stable updates automatically and apply the
|
|
|
98
98
|
|
|
99
99
|
## GitHub Release Artifacts
|
|
100
100
|
|
|
101
|
-
The v1.9.
|
|
101
|
+
The v1.9.5 GitHub Release contains:
|
|
102
102
|
|
|
103
|
-
- `codex-overleaf-link-extension-v1.9.
|
|
104
|
-
- `codex-overleaf-native-host-v1.9.
|
|
105
|
-
- `codex-overleaf-link-1.9.
|
|
106
|
-
- `install.sh`: release-pinned macOS / Linux installer that defaults to `v1.9.
|
|
107
|
-
- `install.ps1`: release-pinned Windows PowerShell installer that defaults to `v1.9.
|
|
103
|
+
- `codex-overleaf-link-extension-v1.9.5.zip`: loadable Chrome extension package for manual unpacked installation.
|
|
104
|
+
- `codex-overleaf-native-host-v1.9.5.tar.gz`: native host runtime files used by the installer and release verification.
|
|
105
|
+
- `codex-overleaf-link-1.9.5.tgz`: npm native host CLI package for pinned install, doctor, and uninstall flows.
|
|
106
|
+
- `install.sh`: release-pinned macOS / Linux installer that defaults to `v1.9.5` when run directly from the release artifact.
|
|
107
|
+
- `install.ps1`: release-pinned Windows PowerShell installer that defaults to `v1.9.5` when run directly from the release artifact.
|
|
108
108
|
- `uninstall-native-host.mjs`: native host uninstaller that removes the Chrome Native Messaging manifest, bridge executable, and runtime copy.
|
|
109
109
|
- `nativeHostPlatform.js`, `manifest.js`, `runtimeInstaller.js`: helper files required by the loose uninstaller asset.
|
|
110
110
|
- `SHA256SUMS` and `release-manifest.json`: checksum and artifact metadata for release verification.
|
|
@@ -115,7 +115,7 @@ The v1.9.3 GitHub Release contains:
|
|
|
115
115
|
Remove the native host (use `--browser chromium` on Linux Chromium):
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
118
|
+
npm exec --yes codex-overleaf-link@1.9.5 -- uninstall-managed
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
The same command works on Windows PowerShell. If you installed from a manual checkout or source installer, you can also run `npm run uninstall:native` inside the repo, use `node ~/.codex-overleaf/source/scripts/uninstall-native-host.mjs` on macOS / Linux, or use `node $env:LOCALAPPDATA\CodexOverleaf\source\scripts\uninstall-native-host.mjs` on Windows PowerShell.
|
|
@@ -150,13 +150,13 @@ Then remove the extension from `chrome://extensions`. To delete local data: on m
|
|
|
150
150
|
Linux Chromium install or update:
|
|
151
151
|
|
|
152
152
|
```bash
|
|
153
|
-
CODEX_OVERLEAF_REF=v1.9.
|
|
153
|
+
CODEX_OVERLEAF_REF=v1.9.5 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.5/install.sh)" -- --browser chromium
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
Linux Chromium uninstall:
|
|
157
157
|
|
|
158
158
|
```bash
|
|
159
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
159
|
+
npm exec --yes codex-overleaf-link@1.9.5 -- uninstall-managed --browser chromium
|
|
160
160
|
```
|
|
161
161
|
|
|
162
162
|
## Features
|
|
@@ -291,7 +291,7 @@ Composer attachments are turn-scoped Codex context. Limits are 8 attachments per
|
|
|
291
291
|
Re-run any [native host installer](#install), reload the extension in `chrome://extensions`, then refresh the Overleaf tab. This also fixes extension/native version mismatch and native protocol mismatch.
|
|
292
292
|
|
|
293
293
|
```bash
|
|
294
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
294
|
+
npm exec --yes codex-overleaf-link@1.9.5 -- install-managed
|
|
295
295
|
```
|
|
296
296
|
|
|
297
297
|
**The Windows popup or panel shows a Bash recovery command**
|
|
@@ -340,8 +340,8 @@ Use this matrix for release-candidate signoff and compatibility reports. Record
|
|
|
340
340
|
| Browser/channel/version | Google Chrome channel and version. | Google Chrome channel and version. | Google Chrome channel and version. | Chromium channel/package and version. |
|
|
341
341
|
| Install mode | Manual unpacked extension from GitHub Release zip or checkout. | Manual unpacked extension from GitHub Release zip or checkout. | Manual unpacked extension from GitHub Release zip or checkout. | Manual unpacked extension from GitHub Release zip or checkout; native host installed with `--browser chromium`. |
|
|
342
342
|
| Extension id | Bundled id `illdpneeeopfffmiepaejglgmhpmdhdc`, or actual custom id passed with `--extension-id`. | Bundled id `illdpneeeopfffmiepaejglgmhpmdhdc`, or actual custom id passed with `--extension-id`. | Bundled id `illdpneeeopfffmiepaejglgmhpmdhdc`, or actual custom id passed with `--extension-id`. | Bundled id `illdpneeeopfffmiepaejglgmhpmdhdc`, or actual custom id passed with `--extension-id`. |
|
|
343
|
-
| Installer/update command | `npm exec --yes codex-overleaf-link@1.9.
|
|
344
|
-
| Uninstall command | `npm exec --yes codex-overleaf-link@1.9.
|
|
343
|
+
| Installer/update command | `npm exec --yes codex-overleaf-link@1.9.5 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.5 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.5 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.5 -- install-managed --browser chromium` |
|
|
344
|
+
| Uninstall command | `npm exec --yes codex-overleaf-link@1.9.5 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.5 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.5 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.5 -- uninstall-managed --browser chromium` |
|
|
345
345
|
| Manifest/registry path | `~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.codex.overleaf.json` | `HKCU\Software\Google\Chrome\NativeMessagingHosts\com.codex.overleaf` -> `%LOCALAPPDATA%\CodexOverleaf\native-host-runtime\com.codex.overleaf.json` | `~/.config/google-chrome/NativeMessagingHosts/com.codex.overleaf.json` | `~/.config/chromium/NativeMessagingHosts/com.codex.overleaf.json` |
|
|
346
346
|
| Bridge/runtime/source path | Bridge `~/.codex-overleaf/codex-overleaf-bridge`; runtime `~/.codex-overleaf/native-host-runtime`; source `~/.codex-overleaf/source`. | Bridge `%LOCALAPPDATA%\CodexOverleaf\codex-overleaf-bridge.cmd`; runtime `%LOCALAPPDATA%\CodexOverleaf\native-host-runtime`; source `%LOCALAPPDATA%\CodexOverleaf\source`. | Bridge `~/.codex-overleaf/codex-overleaf-bridge`; runtime `~/.codex-overleaf/native-host-runtime`; source `~/.codex-overleaf/source`. | Bridge `~/.codex-overleaf/codex-overleaf-bridge`; runtime `~/.codex-overleaf/native-host-runtime`; source `~/.codex-overleaf/source`. |
|
|
347
347
|
| Node/Git/Codex/TeX | Node.js >= 20; Git; Codex CLI installed and logged in; TeX optional. | Node.js >= 20; Git; Codex CLI installed and logged in; TeX optional. | Node.js >= 20; Git; Codex CLI installed and logged in; TeX optional. | Node.js >= 20; Git; Codex CLI installed and logged in; TeX optional. |
|
|
@@ -377,7 +377,7 @@ Contributions are welcome. Please open an issue before submitting large changes
|
|
|
377
377
|
The recommended v1.9 installation owns one stable unpacked-extension directory and a versioned native-host directory:
|
|
378
378
|
|
|
379
379
|
```bash
|
|
380
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
380
|
+
npm exec --yes codex-overleaf-link@1.9.5 -- install-managed
|
|
381
381
|
```
|
|
382
382
|
|
|
383
383
|
Load the printed extension path once from `chrome://extensions`. Starting with the next signed stable release, Codex Overleaf Link checks GitHub Releases automatically, downloads and verifies the coordinated extension/native-host bundle, waits until every connected Overleaf tab is saved and idle, and then updates both components together. A failed health check restores the previous version automatically.
|
|
@@ -387,11 +387,11 @@ The stable updater ignores drafts and prereleases, performs no telemetry, and ca
|
|
|
387
387
|
The legacy native-only installer remains available for source or unmanaged extension directories:
|
|
388
388
|
|
|
389
389
|
```bash
|
|
390
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
390
|
+
npm exec --yes codex-overleaf-link@1.9.5 -- install-native
|
|
391
391
|
```
|
|
392
392
|
|
|
393
393
|
Legacy native-only installations can be removed with:
|
|
394
394
|
|
|
395
395
|
```bash
|
|
396
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
396
|
+
npm exec --yes codex-overleaf-link@1.9.5 -- uninstall-native
|
|
397
397
|
```
|
|
@@ -530,3 +530,23 @@ if (!globalThis.CodexOverleafCompatibility) {
|
|
|
530
530
|
return true;
|
|
531
531
|
}
|
|
532
532
|
})();
|
|
533
|
+
|
|
534
|
+
(function loadConsentDrivenUpdateRuntime(root) {
|
|
535
|
+
'use strict';
|
|
536
|
+
|
|
537
|
+
try {
|
|
538
|
+
const workerPath = chrome.runtime.getManifest().background?.service_worker || '';
|
|
539
|
+
const runtimePrefix = workerPath.startsWith('bootstrap/') ? 'runtime/' : '';
|
|
540
|
+
if (!root.CodexOverleafUpdateConsent) {
|
|
541
|
+
importScripts(chrome.runtime.getURL(runtimePrefix + 'src/shared/updateConsent.js'));
|
|
542
|
+
}
|
|
543
|
+
if (!root.CodexOverleafUpdateCoordinator) {
|
|
544
|
+
importScripts(chrome.runtime.getURL(runtimePrefix + 'src/backgroundUpdateCoordinator.js'));
|
|
545
|
+
}
|
|
546
|
+
root.CodexOverleafUpdateCoordinator?.init?.({
|
|
547
|
+
nativeBridge: root.CodexOverleafNativeBridge
|
|
548
|
+
});
|
|
549
|
+
} catch (error) {
|
|
550
|
+
console.error('Consent-driven updater failed to initialize:', error?.message || String(error));
|
|
551
|
+
}
|
|
552
|
+
})(globalThis);
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
(function initCodexOverleafUpdateCoordinator(root) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const UPDATE_STATE_KEY = 'codex-overleaf-managed-update-state-v1';
|
|
5
|
+
const CONSENT_STATE_KEY = 'codex-overleaf-update-consent-v1';
|
|
6
|
+
const CHECK_ALARM = 'codex-overleaf-consent-update-check';
|
|
7
|
+
const CHECK_INTERVAL_MINUTES = 24 * 60;
|
|
8
|
+
const SNOOZE_MS = 24 * 60 * 60 * 1000;
|
|
9
|
+
const CANDIDATE_MAX_AGE_MS = 5 * 60 * 1000;
|
|
10
|
+
const LEGACY_GUARD = Number.MAX_SAFE_INTEGER;
|
|
11
|
+
const OVERLEAF_MATCHES = [
|
|
12
|
+
'https://www.overleaf.com/project/*',
|
|
13
|
+
'https://overleaf.com/project/*'
|
|
14
|
+
];
|
|
15
|
+
const MESSAGE_TYPES = new Set([
|
|
16
|
+
'codex-overleaf/consent-update-get-state',
|
|
17
|
+
'codex-overleaf/consent-update-check',
|
|
18
|
+
'codex-overleaf/consent-update-install',
|
|
19
|
+
'codex-overleaf/consent-update-later'
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
const policy = root.CodexOverleafUpdateConsent;
|
|
23
|
+
let nativeBridge = null;
|
|
24
|
+
let initialized = false;
|
|
25
|
+
let policyTail = Promise.resolve();
|
|
26
|
+
|
|
27
|
+
function init(options = {}) {
|
|
28
|
+
if (initialized || !policy) return;
|
|
29
|
+
initialized = true;
|
|
30
|
+
nativeBridge = options.nativeBridge || root.CodexOverleafNativeBridge;
|
|
31
|
+
|
|
32
|
+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
33
|
+
if (!MESSAGE_TYPES.has(message?.type)) return undefined;
|
|
34
|
+
if (!isAllowedSender(sender)) {
|
|
35
|
+
sendResponse({ ok: false, error: { code: 'forbidden_sender', message: 'Update actions are limited to this extension and Overleaf project tabs.' } });
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
enqueuePolicyAction(() => handleMessage(message))
|
|
39
|
+
.then(result => sendResponse({ ok: true, result }))
|
|
40
|
+
.catch(error => sendResponse({ ok: false, error: safeError(error) }));
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
chrome.alarms?.onAlarm?.addListener(alarm => {
|
|
45
|
+
if (alarm?.name === CHECK_ALARM) {
|
|
46
|
+
void enqueuePolicyAction(() => checkOnly({ manual: false })).catch(() => {});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
chrome.storage?.onChanged?.addListener((changes, area) => {
|
|
51
|
+
if (area !== 'local' || (!changes[UPDATE_STATE_KEY] && !changes[CONSENT_STATE_KEY])) return;
|
|
52
|
+
void handleObservedStateChange();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
void startup();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function startup() {
|
|
59
|
+
chrome.alarms?.create?.(CHECK_ALARM, {
|
|
60
|
+
delayInMinutes: 0.5,
|
|
61
|
+
periodInMinutes: CHECK_INTERVAL_MINUTES
|
|
62
|
+
});
|
|
63
|
+
await settleTerminalConsent();
|
|
64
|
+
await armLegacyGuard();
|
|
65
|
+
await publishView();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function handleMessage(message) {
|
|
69
|
+
switch (message.type) {
|
|
70
|
+
case 'codex-overleaf/consent-update-get-state':
|
|
71
|
+
return getView();
|
|
72
|
+
case 'codex-overleaf/consent-update-check':
|
|
73
|
+
return checkOnly({ manual: true });
|
|
74
|
+
case 'codex-overleaf/consent-update-install':
|
|
75
|
+
return installUpdate();
|
|
76
|
+
case 'codex-overleaf/consent-update-later':
|
|
77
|
+
return postponeUpdate();
|
|
78
|
+
default:
|
|
79
|
+
throw codedError('unknown_update_action', 'Unknown update action.');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function checkOnly({ manual }) {
|
|
84
|
+
const [currentState, consent] = await Promise.all([getUpdateState(), getConsentState()]);
|
|
85
|
+
if (consent.authorizedVersion || policy.isExecutionState(currentState.state)) {
|
|
86
|
+
return getView();
|
|
87
|
+
}
|
|
88
|
+
await setUpdateState({
|
|
89
|
+
...currentState,
|
|
90
|
+
state: 'checking',
|
|
91
|
+
code: '',
|
|
92
|
+
message: '',
|
|
93
|
+
blocker: '',
|
|
94
|
+
blockers: []
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const result = await requestNative('update.check', {
|
|
99
|
+
currentVersion: currentVersion(),
|
|
100
|
+
etag: currentState.etag || ''
|
|
101
|
+
});
|
|
102
|
+
const checkedAt = Date.now();
|
|
103
|
+
if (result.available) {
|
|
104
|
+
const nextConsent = result.latestVersion !== consent.snoozedVersion
|
|
105
|
+
? { ...consent, snoozedVersion: '', snoozedUntil: 0 }
|
|
106
|
+
: consent;
|
|
107
|
+
await setConsentState({
|
|
108
|
+
...nextConsent,
|
|
109
|
+
lastPromptedVersion: result.latestVersion,
|
|
110
|
+
lastPromptedAt: manual ? checkedAt : nextConsent.lastPromptedAt
|
|
111
|
+
});
|
|
112
|
+
await setUpdateState({
|
|
113
|
+
...currentState,
|
|
114
|
+
state: 'update_available',
|
|
115
|
+
managed: true,
|
|
116
|
+
currentVersion: result.currentVersion || currentVersion(),
|
|
117
|
+
latestVersion: result.latestVersion,
|
|
118
|
+
etag: result.etag || currentState.etag || '',
|
|
119
|
+
lastCheckedAt: checkedAt,
|
|
120
|
+
postponeUntil: LEGACY_GUARD,
|
|
121
|
+
code: '',
|
|
122
|
+
message: ''
|
|
123
|
+
});
|
|
124
|
+
} else if (result.reason === 'not_modified' &&
|
|
125
|
+
policy.compareStableVersions(currentState.latestVersion, currentVersion()) > 0) {
|
|
126
|
+
await setUpdateState({
|
|
127
|
+
...currentState,
|
|
128
|
+
state: 'update_available',
|
|
129
|
+
lastCheckedAt: checkedAt,
|
|
130
|
+
postponeUntil: LEGACY_GUARD,
|
|
131
|
+
code: '',
|
|
132
|
+
message: ''
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
await setUpdateState({
|
|
136
|
+
...currentState,
|
|
137
|
+
state: 'idle',
|
|
138
|
+
currentVersion: result.currentVersion || currentVersion(),
|
|
139
|
+
latestVersion: result.latestVersion || result.currentVersion || currentVersion(),
|
|
140
|
+
etag: result.etag || currentState.etag || '',
|
|
141
|
+
lastCheckedAt: checkedAt,
|
|
142
|
+
postponeUntil: LEGACY_GUARD,
|
|
143
|
+
transactionId: '',
|
|
144
|
+
code: '',
|
|
145
|
+
message: ''
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return getView();
|
|
149
|
+
} catch (error) {
|
|
150
|
+
await setUpdateState({
|
|
151
|
+
...currentState,
|
|
152
|
+
state: 'failed',
|
|
153
|
+
postponeUntil: LEGACY_GUARD,
|
|
154
|
+
code: safeCode(error),
|
|
155
|
+
message: safeMessage(error)
|
|
156
|
+
});
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function installUpdate() {
|
|
162
|
+
let state = await getUpdateState();
|
|
163
|
+
let consent = await getConsentState();
|
|
164
|
+
const candidateStale = !state.lastCheckedAt || Date.now() - state.lastCheckedAt > CANDIDATE_MAX_AGE_MS;
|
|
165
|
+
if (state.state !== 'update_available' || candidateStale) {
|
|
166
|
+
await checkOnly({ manual: true });
|
|
167
|
+
state = await getUpdateState();
|
|
168
|
+
consent = await getConsentState();
|
|
169
|
+
}
|
|
170
|
+
if (state.state !== 'update_available' ||
|
|
171
|
+
policy.compareStableVersions(state.latestVersion, currentVersion()) <= 0) {
|
|
172
|
+
throw codedError('update_candidate_missing', 'No newer signed stable update is available.');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const authorizationId = crypto.randomUUID();
|
|
176
|
+
await requestNative('update.authorize', {
|
|
177
|
+
authorizationId,
|
|
178
|
+
targetVersion: state.latestVersion,
|
|
179
|
+
currentVersion: currentVersion()
|
|
180
|
+
});
|
|
181
|
+
await setConsentState({
|
|
182
|
+
...consent,
|
|
183
|
+
snoozedVersion: '',
|
|
184
|
+
snoozedUntil: 0,
|
|
185
|
+
authorizedVersion: state.latestVersion,
|
|
186
|
+
authorizationId,
|
|
187
|
+
authorizedAt: Date.now()
|
|
188
|
+
});
|
|
189
|
+
await setUpdateState({ ...state, postponeUntil: 0, code: '', message: '' });
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
const result = await chrome.runtime.sendMessage({ type: 'codex-overleaf/update-check-now' });
|
|
193
|
+
if (result === undefined) {
|
|
194
|
+
throw codedError('update_executor_unavailable', 'The managed update executor is unavailable.');
|
|
195
|
+
}
|
|
196
|
+
return getView();
|
|
197
|
+
} catch (error) {
|
|
198
|
+
await bestEffortRevoke({
|
|
199
|
+
authorizationId,
|
|
200
|
+
targetVersion: state.latestVersion,
|
|
201
|
+
transactionId: ''
|
|
202
|
+
});
|
|
203
|
+
await setConsentState({
|
|
204
|
+
...consent,
|
|
205
|
+
authorizedVersion: '',
|
|
206
|
+
authorizationId: '',
|
|
207
|
+
authorizedAt: 0
|
|
208
|
+
});
|
|
209
|
+
await armLegacyGuard();
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function postponeUpdate() {
|
|
215
|
+
const [state, consent] = await Promise.all([getUpdateState(), getConsentState()]);
|
|
216
|
+
if (['applying', 'awaiting_health'].includes(state.state)) {
|
|
217
|
+
throw codedError('update_revoke_too_late', 'The update is already being installed.');
|
|
218
|
+
}
|
|
219
|
+
if (consent.authorizationId) {
|
|
220
|
+
try {
|
|
221
|
+
await requestNative('update.revoke', {
|
|
222
|
+
authorizationId: consent.authorizationId,
|
|
223
|
+
targetVersion: consent.authorizedVersion || state.latestVersion,
|
|
224
|
+
transactionId: state.transactionId || ''
|
|
225
|
+
});
|
|
226
|
+
} catch (error) {
|
|
227
|
+
if (error?.code === 'update_revoke_too_late') {
|
|
228
|
+
return getView();
|
|
229
|
+
}
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
} else if (['staged', 'waiting_for_idle'].includes(state.state)) {
|
|
233
|
+
throw codedError('update_consent_mismatch', 'The staged update has no matching runtime authorization.');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const snoozedUntil = Date.now() + SNOOZE_MS;
|
|
237
|
+
await setUpdateState({
|
|
238
|
+
...state,
|
|
239
|
+
state: 'update_available',
|
|
240
|
+
transactionId: '',
|
|
241
|
+
stagedAt: 0,
|
|
242
|
+
blocker: '',
|
|
243
|
+
blockers: [],
|
|
244
|
+
postponeUntil: LEGACY_GUARD,
|
|
245
|
+
code: '',
|
|
246
|
+
message: ''
|
|
247
|
+
});
|
|
248
|
+
await setConsentState({
|
|
249
|
+
...consent,
|
|
250
|
+
snoozedVersion: state.latestVersion,
|
|
251
|
+
snoozedUntil,
|
|
252
|
+
authorizedVersion: '',
|
|
253
|
+
authorizationId: '',
|
|
254
|
+
authorizedAt: 0
|
|
255
|
+
});
|
|
256
|
+
return getView();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function settleTerminalConsent() {
|
|
260
|
+
const [state, consent] = await Promise.all([getUpdateState(), getConsentState()]);
|
|
261
|
+
if (!policy.isTerminalState(state.state) || !consent.authorizationId) return;
|
|
262
|
+
await setConsentState({
|
|
263
|
+
...consent,
|
|
264
|
+
authorizedVersion: '',
|
|
265
|
+
authorizationId: '',
|
|
266
|
+
authorizedAt: 0
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function handleObservedStateChange() {
|
|
271
|
+
await settleTerminalConsent();
|
|
272
|
+
const [state, consent] = await Promise.all([getUpdateState(), getConsentState()]);
|
|
273
|
+
if (!consent.authorizationId && !policy.isExecutionState(state.state)) {
|
|
274
|
+
await armLegacyGuard();
|
|
275
|
+
}
|
|
276
|
+
await publishView();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async function armLegacyGuard() {
|
|
280
|
+
const [state, consent] = await Promise.all([getUpdateState(), getConsentState()]);
|
|
281
|
+
if (consent.authorizationId || state.postponeUntil === LEGACY_GUARD) return state;
|
|
282
|
+
return setUpdateState({ ...state, postponeUntil: LEGACY_GUARD });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function getView() {
|
|
286
|
+
const [state, consent] = await Promise.all([getUpdateState(), getConsentState()]);
|
|
287
|
+
return policy.deriveViewModel(state, consent, {
|
|
288
|
+
currentVersion: currentVersion(),
|
|
289
|
+
now: Date.now()
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async function publishView() {
|
|
294
|
+
const view = await getView();
|
|
295
|
+
await setBadge(view.badge);
|
|
296
|
+
const tabs = await chrome.tabs.query({ url: OVERLEAF_MATCHES }).catch(() => []);
|
|
297
|
+
await Promise.all((tabs || []).map(tab => {
|
|
298
|
+
if (!Number.isInteger(tab?.id)) return Promise.resolve();
|
|
299
|
+
return chrome.tabs.sendMessage(tab.id, {
|
|
300
|
+
type: 'codex-overleaf/consent-update-state',
|
|
301
|
+
view
|
|
302
|
+
}).catch(() => {});
|
|
303
|
+
}));
|
|
304
|
+
return view;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function setBadge(badge = {}) {
|
|
308
|
+
try {
|
|
309
|
+
await chrome.action.setBadgeText({ text: String(badge.text || '').slice(0, 4) });
|
|
310
|
+
if (badge.text) {
|
|
311
|
+
await chrome.action.setBadgeBackgroundColor({ color: badge.color || '#3578bd' });
|
|
312
|
+
}
|
|
313
|
+
} catch (_error) {
|
|
314
|
+
// Badge rendering is best-effort and never participates in update state.
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function getUpdateState() {
|
|
319
|
+
const stored = await chrome.storage.local.get(UPDATE_STATE_KEY);
|
|
320
|
+
return policy.normalizeUpdateState(stored?.[UPDATE_STATE_KEY], currentVersion());
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async function setUpdateState(value) {
|
|
324
|
+
const next = policy.normalizeUpdateState(value, currentVersion());
|
|
325
|
+
await chrome.storage.local.set({ [UPDATE_STATE_KEY]: next });
|
|
326
|
+
return next;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
async function getConsentState() {
|
|
330
|
+
const stored = await chrome.storage.local.get(CONSENT_STATE_KEY);
|
|
331
|
+
return policy.normalizeConsentState(stored?.[CONSENT_STATE_KEY]);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
async function setConsentState(value) {
|
|
335
|
+
const next = policy.normalizeConsentState(value);
|
|
336
|
+
await chrome.storage.local.set({ [CONSENT_STATE_KEY]: next });
|
|
337
|
+
return next;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async function requestNative(method, params = {}) {
|
|
341
|
+
const response = await nativeBridge?.requestInternal?.({
|
|
342
|
+
id: crypto.randomUUID(),
|
|
343
|
+
method,
|
|
344
|
+
params
|
|
345
|
+
});
|
|
346
|
+
if (!response?.ok) {
|
|
347
|
+
throw codedError(
|
|
348
|
+
response?.error?.code || 'native_connection_failed',
|
|
349
|
+
response?.error?.message || 'Native Host update request failed.'
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
return response.result || {};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async function bestEffortRevoke(params) {
|
|
356
|
+
try {
|
|
357
|
+
await requestNative('update.revoke', params);
|
|
358
|
+
} catch (_error) {
|
|
359
|
+
// Native authorization remains the hard gate if cleanup cannot connect.
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function enqueuePolicyAction(action) {
|
|
364
|
+
const result = policyTail.then(action, action);
|
|
365
|
+
policyTail = result.catch(() => {});
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function isAllowedSender(sender) {
|
|
370
|
+
if (sender?.id && sender.id !== chrome.runtime.id) return false;
|
|
371
|
+
if (!sender?.tab) return true;
|
|
372
|
+
try {
|
|
373
|
+
const url = new URL(sender.tab.url || '');
|
|
374
|
+
return url.protocol === 'https:' &&
|
|
375
|
+
(url.hostname === 'www.overleaf.com' || url.hostname === 'overleaf.com') &&
|
|
376
|
+
url.pathname.startsWith('/project/');
|
|
377
|
+
} catch (_error) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function currentVersion() {
|
|
383
|
+
return String(
|
|
384
|
+
root.CodexOverleafCompatibility?.BUILD_TARGET_VERSION ||
|
|
385
|
+
chrome.runtime.getManifest().version ||
|
|
386
|
+
''
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function codedError(code, message) {
|
|
391
|
+
const error = new Error(message);
|
|
392
|
+
error.code = code;
|
|
393
|
+
return error;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function safeError(error) {
|
|
397
|
+
return { code: safeCode(error), message: safeMessage(error) };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function safeCode(error) {
|
|
401
|
+
const code = String(error?.code || '');
|
|
402
|
+
return /^[a-z0-9_]{1,80}$/.test(code) ? code : 'update_failed';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function safeMessage(error) {
|
|
406
|
+
return String(error?.message || 'Update failed.')
|
|
407
|
+
.replace(/(?:file:\/\/)?(?:[A-Za-z]:[\\/]|\/Users\/|\/home\/)[^\s]*/g, '[local path]')
|
|
408
|
+
.replace(/\s+/g, ' ')
|
|
409
|
+
.trim()
|
|
410
|
+
.slice(0, 300);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
root.CodexOverleafUpdateCoordinator = Object.freeze({ init });
|
|
414
|
+
})(globalThis);
|
|
@@ -778,6 +778,9 @@
|
|
|
778
778
|
storageKey = getProjectStorageKey(LEGACY_STORAGE_KEY, window.location.href);
|
|
779
779
|
state = normalizePanelState(await loadStoredState(), { restoreRunningRuns: true });
|
|
780
780
|
ensurePanelOpen();
|
|
781
|
+
root.CodexOverleafUpdateNotice?.mount?.(panel?.panelEl || panel, {
|
|
782
|
+
getLocale: () => state?.locale || 'en'
|
|
783
|
+
});
|
|
781
784
|
// v1.8.1: on a non-editor route the panel must NEVER first paint the
|
|
782
785
|
// per-project session UI (composer + probe line) and then swap — mount
|
|
783
786
|
// the dashboard shell synchronously; the account-scope resolution below
|