codex-overleaf-link 1.9.8 → 1.9.10

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 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.8-blue" alt="version">
6
+ <img src="https://img.shields.io/badge/version-1.9.10-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.8 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.8/install.sh)"
41
+ CODEX_OVERLEAF_REF=v1.9.10 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.10/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.8/install.ps1 -OutFile install.ps1
48
- $env:CODEX_OVERLEAF_REF='v1.9.8'
47
+ iwr https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.10/install.ps1 -OutFile install.ps1
48
+ $env:CODEX_OVERLEAF_REF='v1.9.10'
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.8 -- install-managed
59
+ npm exec --yes codex-overleaf-link@1.9.10 -- 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.8 -- install-managed` |
90
- | Diagnose | `npm exec --yes codex-overleaf-link@1.9.8 -- doctor` |
91
- | Uninstall | `npm exec --yes codex-overleaf-link@1.9.8 -- uninstall-managed` |
89
+ | Install / update | `npm exec --yes codex-overleaf-link@1.9.10 -- install-managed` |
90
+ | Diagnose | `npm exec --yes codex-overleaf-link@1.9.10 -- doctor` |
91
+ | Uninstall | `npm exec --yes codex-overleaf-link@1.9.10 -- 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.8 GitHub Release contains:
101
+ The v1.9.10 GitHub Release contains:
102
102
 
103
- - `codex-overleaf-link-extension-v1.9.8.zip`: loadable Chrome extension package for manual unpacked installation.
104
- - `codex-overleaf-native-host-v1.9.8.tar.gz`: native host runtime files used by the installer and release verification.
105
- - `codex-overleaf-link-1.9.8.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.8` when run directly from the release artifact.
107
- - `install.ps1`: release-pinned Windows PowerShell installer that defaults to `v1.9.8` when run directly from the release artifact.
103
+ - `codex-overleaf-link-extension-v1.9.10.zip`: loadable Chrome extension package for manual unpacked installation.
104
+ - `codex-overleaf-native-host-v1.9.10.tar.gz`: native host runtime files used by the installer and release verification.
105
+ - `codex-overleaf-link-1.9.10.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.10` when run directly from the release artifact.
107
+ - `install.ps1`: release-pinned Windows PowerShell installer that defaults to `v1.9.10` 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.8 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.8 -- uninstall-managed
118
+ npm exec --yes codex-overleaf-link@1.9.10 -- 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.8 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.8/install.sh)" -- --browser chromium
153
+ CODEX_OVERLEAF_REF=v1.9.10 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.10/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.8 -- uninstall-managed --browser chromium
159
+ npm exec --yes codex-overleaf-link@1.9.10 -- 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.8 -- install-managed
294
+ npm exec --yes codex-overleaf-link@1.9.10 -- 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.8 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.8 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.8 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.8 -- install-managed --browser chromium` |
344
- | Uninstall command | `npm exec --yes codex-overleaf-link@1.9.8 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.8 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.8 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.8 -- uninstall-managed --browser chromium` |
343
+ | Installer/update command | `npm exec --yes codex-overleaf-link@1.9.10 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.10 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.10 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.10 -- install-managed --browser chromium` |
344
+ | Uninstall command | `npm exec --yes codex-overleaf-link@1.9.10 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.10 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.10 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.10 -- 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.8 -- install-managed
380
+ npm exec --yes codex-overleaf-link@1.9.10 -- 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.8 -- install-native
390
+ npm exec --yes codex-overleaf-link@1.9.10 -- 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.8 -- uninstall-native
396
+ npm exec --yes codex-overleaf-link@1.9.10 -- uninstall-native
397
397
  ```
@@ -16,6 +16,15 @@ const OVERLEAF_MATCHES = [
16
16
  ...OVERLEAF_EDITOR_MATCHES
17
17
  ];
18
18
  const APPLYING_STATES = new Set(['applying', 'awaiting_health', 'rolling_back']);
19
+ const FAST_IDLE_RETRY_BLOCKERS = new Set(['recent_user_activity', 'save_state_not_stable']);
20
+ const FAST_IDLE_RETRY_MS = 4000;
21
+ const SLOW_IDLE_RETRY_MS = 15000;
22
+ const IDLE_RETRY_ALARM_MINUTES = 0.5;
23
+ const RUNTIME_RECOVERY_SETTLE_MS = 250;
24
+
25
+ let idleRetryTimer = null;
26
+ let idleApplyPromise = null;
27
+ let managedRuntimeAssets = null;
19
28
 
20
29
  let runtimeLoadError = null;
21
30
  try {
@@ -85,7 +94,7 @@ async function initializeBootstrap() {
85
94
  chrome.alarms.create(CHECK_ALARM, { delayInMinutes: 0.5, periodInMinutes: 24 * 60 });
86
95
  const state = await getUpdateState();
87
96
  if (state.state === 'staged' || state.state === 'waiting_for_idle') {
88
- chrome.alarms.create(IDLE_ALARM, { delayInMinutes: 0.1 });
97
+ scheduleIdleRetry(state.blockers);
89
98
  }
90
99
  }
91
100
 
@@ -96,6 +105,10 @@ async function registerManagedRuntime() {
96
105
  }
97
106
  const manifest = await response.json();
98
107
  validateRuntimeManifest(manifest);
108
+ managedRuntimeAssets = {
109
+ js: ['bootstrap/runtimeContext.js', ...manifest.js.map(value => 'runtime/' + value)],
110
+ css: manifest.css.map(value => 'runtime/' + value)
111
+ };
99
112
  const registered = await chrome.scripting.getRegisteredContentScripts({ ids: [RUNTIME_SCRIPT_ID] });
100
113
  if (registered.length) {
101
114
  await chrome.scripting.unregisterContentScripts({ ids: [RUNTIME_SCRIPT_ID] });
@@ -103,8 +116,8 @@ async function registerManagedRuntime() {
103
116
  await chrome.scripting.registerContentScripts([{
104
117
  id: RUNTIME_SCRIPT_ID,
105
118
  matches: manifest.matches,
106
- js: ['bootstrap/runtimeContext.js', ...manifest.js.map(value => 'runtime/' + value)],
107
- css: manifest.css.map(value => 'runtime/' + value),
119
+ js: managedRuntimeAssets.js,
120
+ css: managedRuntimeAssets.css,
108
121
  runAt: manifest.runAt || 'document_idle',
109
122
  persistAcrossSessions: true
110
123
  }]);
@@ -188,20 +201,31 @@ async function checkAndStage(options = {}) {
188
201
  blockers: []
189
202
  });
190
203
  await broadcastUpdateState('staged');
191
- chrome.alarms.create(IDLE_ALARM, { delayInMinutes: 0.1 });
192
204
  return tryApplyStagedUpdate();
193
205
  }
194
206
 
195
- async function tryApplyStagedUpdate() {
207
+ function tryApplyStagedUpdate() {
208
+ if (idleApplyPromise) return idleApplyPromise;
209
+ idleApplyPromise = tryApplyStagedUpdateCore().finally(() => {
210
+ idleApplyPromise = null;
211
+ });
212
+ return idleApplyPromise;
213
+ }
214
+
215
+ async function tryApplyStagedUpdateCore() {
216
+ cancelIdleRetryTimer();
196
217
  const state = await getUpdateState();
197
218
  if (!['staged', 'waiting_for_idle'].includes(state.state)) {
219
+ await clearIdleRetry();
198
220
  return state;
199
221
  }
200
222
  if (Number(state.postponeUntil || 0) > Date.now()) {
201
223
  return state;
202
224
  }
203
- const tabs = await chrome.tabs.query({ url: OVERLEAF_EDITOR_MATCHES });
204
- const probes = await Promise.all(tabs.map(tab => probeTabIdle(tab)));
225
+ const surfaceTabs = await chrome.tabs.query({ url: OVERLEAF_MATCHES });
226
+ const activeTabs = surfaceTabs.filter(tab => isEditorProjectTab(tab) && !tab.discarded && tab.status !== 'unloaded');
227
+ const refreshTabs = surfaceTabs.filter(tab => !tab.discarded && tab.status !== 'unloaded');
228
+ const probes = await Promise.all(activeTabs.map(tab => probeTabIdle(tab)));
205
229
  const nativeGate = await requestInternal({ method: 'update.canApply', params: {} }).catch(error => ({
206
230
  ok: false,
207
231
  error: { code: safeCode(error), message: safeMessage(error) }
@@ -215,11 +239,13 @@ async function tryApplyStagedUpdate() {
215
239
  blocker: blockers[0],
216
240
  blockers
217
241
  });
218
- chrome.alarms.create(IDLE_ALARM, { delayInMinutes: 1 });
242
+ await broadcastUpdateState('waiting_for_idle');
243
+ scheduleIdleRetry(blockers);
219
244
  return waiting;
220
245
  }
221
246
 
222
- await chrome.storage.local.set({ [UPDATE_RELOAD_TABS_KEY]: tabs.map(tab => tab.id).filter(Number.isInteger) });
247
+ await clearIdleRetry();
248
+ await chrome.storage.local.set({ [UPDATE_RELOAD_TABS_KEY]: refreshTabs.map(tab => tab.id).filter(Number.isInteger) });
223
249
  await setUpdateState({ ...state, state: 'applying', blocker: '', blockers: [] });
224
250
  await broadcastUpdateState('applying');
225
251
  const applied = await requestInternal({
@@ -234,18 +260,83 @@ async function tryApplyStagedUpdate() {
234
260
  return { state: 'awaiting_health' };
235
261
  }
236
262
 
263
+ function scheduleIdleRetry(blockers = []) {
264
+ cancelIdleRetryTimer();
265
+ const values = Array.isArray(blockers) ? blockers.filter(Boolean) : [];
266
+ const onlyFastBlockers = values.length > 0 && values.every(value => FAST_IDLE_RETRY_BLOCKERS.has(value));
267
+ const delayMs = onlyFastBlockers ? FAST_IDLE_RETRY_MS : SLOW_IDLE_RETRY_MS;
268
+ idleRetryTimer = setTimeout(() => {
269
+ idleRetryTimer = null;
270
+ tryApplyStagedUpdate().catch(() => {});
271
+ }, delayMs);
272
+ chrome.alarms.create(IDLE_ALARM, { delayInMinutes: IDLE_RETRY_ALARM_MINUTES });
273
+ }
274
+
275
+ function cancelIdleRetryTimer() {
276
+ if (idleRetryTimer !== null) {
277
+ clearTimeout(idleRetryTimer);
278
+ idleRetryTimer = null;
279
+ }
280
+ }
281
+
282
+ async function clearIdleRetry() {
283
+ cancelIdleRetryTimer();
284
+ await chrome.alarms.clear(IDLE_ALARM).catch(() => {});
285
+ }
286
+
237
287
  async function probeTabIdle(tab) {
238
288
  if (!Number.isInteger(tab?.id)) {
239
289
  return { idle: false, blockers: ['tab_unavailable'] };
240
290
  }
291
+ if (!isEditorProjectTab(tab)) {
292
+ return { idle: true, saved: true, ignored: true, blockers: [] };
293
+ }
294
+ if (tab.discarded || tab.status === 'unloaded') {
295
+ return { idle: true, saved: true, ignored: true, blockers: [] };
296
+ }
297
+ const firstProbe = await sendTabIdleProbe(tab.id);
298
+ if (firstProbe) return firstProbe;
299
+ if (await injectManagedRuntimeIntoTab(tab.id)) {
300
+ const recoveredProbe = await sendTabIdleProbe(tab.id);
301
+ if (recoveredProbe) return recoveredProbe;
302
+ }
303
+ return { idle: false, blockers: ['tab_probe_unavailable'] };
304
+ }
305
+
306
+ function isEditorProjectTab(tab) {
307
+ try {
308
+ const url = new URL(tab?.url || '');
309
+ return url.protocol === 'https:' &&
310
+ (url.hostname === 'www.overleaf.com' || url.hostname === 'overleaf.com') &&
311
+ /^\/project\/[^/]+(?:\/|$)/.test(url.pathname);
312
+ } catch (_error) {
313
+ return false;
314
+ }
315
+ }
316
+
317
+ async function sendTabIdleProbe(tabId) {
241
318
  try {
242
319
  return await withTimeout(
243
- chrome.tabs.sendMessage(tab.id, { type: 'codex-overleaf/update-idle-probe' }),
320
+ chrome.tabs.sendMessage(tabId, { type: 'codex-overleaf/update-idle-probe' }),
244
321
  3500,
245
322
  { idle: false, blockers: ['tab_probe_timeout'] }
246
323
  );
247
324
  } catch (_error) {
248
- return { idle: false, blockers: ['tab_probe_unavailable'] };
325
+ return null;
326
+ }
327
+ }
328
+
329
+ async function injectManagedRuntimeIntoTab(tabId) {
330
+ if (!managedRuntimeAssets) return false;
331
+ try {
332
+ if (managedRuntimeAssets.css.length) {
333
+ await chrome.scripting.insertCSS({ target: { tabId }, files: managedRuntimeAssets.css });
334
+ }
335
+ await chrome.scripting.executeScript({ target: { tabId }, files: managedRuntimeAssets.js });
336
+ await new Promise(resolve => setTimeout(resolve, RUNTIME_RECOVERY_SETTLE_MS));
337
+ return true;
338
+ } catch (_error) {
339
+ return false;
249
340
  }
250
341
  }
251
342
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Codex Overleaf Link",
4
- "version": "1.9.8",
4
+ "version": "1.9.10",
5
5
  "description": "Connect the active Overleaf project to a local Codex bridge.",
6
6
  "icons": {
7
7
  "16": "assets/icons/icon16.png",
@@ -20,14 +20,12 @@
20
20
  'codex-overleaf/consent-update-check',
21
21
  'codex-overleaf/consent-update-install',
22
22
  'codex-overleaf/consent-update-later',
23
- 'codex-overleaf/consent-update-dismiss',
24
- 'codex-overleaf/consent-update-open-center'
23
+ 'codex-overleaf/consent-update-dismiss'
25
24
  ]);
26
25
 
27
26
  const policy = root.CodexOverleafUpdateConsent;
28
27
  let nativeBridge = null;
29
28
  let initialized = false;
30
- let updateCenterWindowId = null;
31
29
  let policyTail = Promise.resolve();
32
30
 
33
31
  function init(options = {}) {
@@ -84,8 +82,6 @@
84
82
  return postponeUpdate();
85
83
  case 'codex-overleaf/consent-update-dismiss':
86
84
  return dismissCompletedUpdate();
87
- case 'codex-overleaf/consent-update-open-center':
88
- return openUpdateCenter(message.action);
89
85
  default:
90
86
  throw codedError('unknown_update_action', 'Unknown update action.');
91
87
  }
@@ -423,8 +419,7 @@
423
419
  const url = new URL(sender?.url || sender?.tab?.url || '');
424
420
  const extensionRoot = new URL(chrome.runtime.getURL(''));
425
421
  if (url.origin === extensionRoot.origin) {
426
- return url.pathname === '/bootstrap/popup.html' ||
427
- url.pathname === '/bootstrap/update.html';
422
+ return url.pathname === '/bootstrap/popup.html';
428
423
  }
429
424
  return url.protocol === 'https:' &&
430
425
  (url.hostname === 'www.overleaf.com' || url.hostname === 'overleaf.com') &&
@@ -434,42 +429,6 @@
434
429
  }
435
430
  }
436
431
 
437
- async function openUpdateCenter(requestedAction = '') {
438
- const action = String(requestedAction || '');
439
- if (action && action !== 'install' && action !== 'retry') {
440
- throw codedError('invalid_update_center_action', 'Unsupported Update Center action.');
441
- }
442
- const url = new URL(chrome.runtime.getURL('bootstrap/update.html'));
443
- if (action) url.searchParams.set('action', action);
444
-
445
- if (Number.isInteger(updateCenterWindowId)) {
446
- try {
447
- const existing = await chrome.windows.get(updateCenterWindowId, { populate: true });
448
- await chrome.windows.update(updateCenterWindowId, { focused: true });
449
- const tabId = existing?.tabs?.[0]?.id;
450
- if (action && Number.isInteger(tabId)) {
451
- await chrome.tabs.update(tabId, { url: url.href });
452
- }
453
- return { opened: true, focused: true, windowId: updateCenterWindowId };
454
- } catch (_error) {
455
- updateCenterWindowId = null;
456
- }
457
- }
458
-
459
- const created = await chrome.windows.create({
460
- url: url.href,
461
- type: 'popup',
462
- width: 420,
463
- height: 560,
464
- focused: true
465
- });
466
- if (!Number.isInteger(created?.id)) {
467
- throw codedError('update_center_open_failed', 'Could not open Update Center.');
468
- }
469
- updateCenterWindowId = created.id;
470
- return { opened: true, focused: true, windowId: created.id };
471
- }
472
-
473
432
  function currentVersion() {
474
433
  return String(
475
434
  root.CodexOverleafCompatibility?.BUILD_TARGET_VERSION ||
@@ -715,7 +715,7 @@
715
715
  reviewAction: trackedChangeInFlight.size > 0,
716
716
  dialog: Boolean(activePluginConfirmResolve)
717
717
  }),
718
- checkSaved: () => callPageBridge('waitForSaveState', { deadlineMs: 0, pollIntervalMs: 1 }),
718
+ checkSaved: () => callPageBridge('waitForSaveState', { deadlineMs: 1500, pollIntervalMs: 100, requirePositiveSignal: true }),
719
719
  onApplyingChange: applying => { if (panel) panel.dataset.updating = applying ? 'true' : 'false'; },
720
720
  showToast: (...args) => showPluginToast(...args),
721
721
  getStateMessage: state => ({
@@ -10,7 +10,8 @@
10
10
  history: '<path d="M4.2 3.4h7.6"/><path d="M4.2 8h7.6"/><path d="M4.2 12.6h4.6"/><path d="M2.2 3.4h.1"/><path d="M2.2 8h.1"/><path d="M2.2 12.6h.1"/>',
11
11
  lock: '<rect x="3.6" y="7" width="8.8" height="6.2" rx="1.2"/><path d="M5.6 7V5.3a2.4 2.4 0 0 1 4.8 0V7"/><path d="M8 9.6v1.2"/>',
12
12
  pen: '<path d="M3.2 12.8 4 9.7l6.6-6.6a1.4 1.4 0 0 1 2 2L6 11.7z"/><path d="m9.6 4.1 2.3 2.3"/>',
13
- shield: '<path d="M8 2.1 12.4 4v3.5c0 2.9-1.8 5.1-4.4 6.4-2.6-1.3-4.4-3.5-4.4-6.4V4z"/><path d="M6.1 8.1 7.5 9.5 10.2 6.6"/>'
13
+ shield: '<path d="M8 2.1 12.4 4v3.5c0 2.9-1.8 5.1-4.4 6.4-2.6-1.3-4.4-3.5-4.4-6.4V4z"/><path d="M6.1 8.1 7.5 9.5 10.2 6.6"/>',
14
+ software: '<rect x="5.1" y="5.1" width="5.8" height="5.8" rx="1.2"/><path d="M12.9 7.1A5.2 5.2 0 0 0 4.1 4.2"/><path d="M4.1 2.2v2h2"/><path d="M3.1 8.9a5.2 5.2 0 0 0 8.8 2.9"/><path d="M11.9 13.8v-2h-2"/>'
14
15
  };
15
16
  const safeName = Object.prototype.hasOwnProperty.call(icons, name) ? name : 'appearance';
16
17
  return `<span class="codex-icon codex-icon-${safeName}" aria-hidden="true"><svg viewBox="0 0 16 16" focusable="false">${icons[safeName]}</svg></span>`;
@@ -148,7 +149,7 @@
148
149
  </details>
149
150
  <details class="codex-set-group" data-set-group="updates" open>
150
151
  <summary class="codex-set-group-head">
151
- <span class="codex-set-group-title">${codexSetIcon('appearance')}<span data-i18n="softwareUpdatesTitle">Software updates</span></span>
152
+ <span class="codex-set-group-title">${codexSetIcon('software')}<span data-i18n="softwareUpdatesTitle">Software updates</span></span>
152
153
  </summary>
153
154
  <div class="codex-set-card" data-update-settings>
154
155
  <div class="codex-set-row">
@@ -6,7 +6,11 @@
6
6
  let stableSavedSince = 0;
7
7
  let applying = false;
8
8
  const documentRef = options.document || root.document;
9
- const noteActivity = () => { lastUserActivityAt = Date.now(); stableSavedSince = 0; };
9
+ const noteActivity = event => {
10
+ if (event?.target?.closest?.('#codex-overleaf-panel')) return;
11
+ lastUserActivityAt = Date.now();
12
+ stableSavedSince = 0;
13
+ };
10
14
  for (const eventName of ['input', 'keydown', 'pointerdown']) {
11
15
  documentRef?.addEventListener?.(eventName, noteActivity, true);
12
16
  }
@@ -5,11 +5,11 @@
5
5
  let currentView = null;
6
6
  let mountedPanel = null;
7
7
  let actionInFlight = false;
8
- let completionTimer = null;
9
8
  let listenerInstalled = false;
10
9
  let getLocale = () => '';
11
10
  let settingsRoot = null;
12
11
  let settingsActionInFlight = false;
12
+ const ACTIVE_UPDATE_STATES = new Set(['downloading', 'staged', 'waiting_for_idle', 'applying', 'awaiting_health']);
13
13
 
14
14
  function mount(panelLike, options = {}) {
15
15
  if (typeof options.getLocale === 'function') {
@@ -63,25 +63,17 @@
63
63
  actionInFlight = true;
64
64
  render();
65
65
  try {
66
- if (action === 'install' || action === 'retry') {
67
- await openUpdateCenter(action);
68
- } else {
69
- currentView = await request({
70
- later: 'codex-overleaf/consent-update-later'
71
- }[action]);
72
- }
66
+ currentView = await request({
67
+ install: 'codex-overleaf/consent-update-install',
68
+ retry: 'codex-overleaf/consent-update-check',
69
+ later: 'codex-overleaf/consent-update-later',
70
+ dismiss: 'codex-overleaf/consent-update-dismiss'
71
+ }[action]);
73
72
  } catch (error) {
74
- currentView = {
75
- ...(currentView || {}),
76
- state: {
77
- ...(currentView?.state || {}),
78
- state: 'failed',
79
- code: error?.code || 'update_failed',
80
- message: error?.message || tx('Update failed.', '更新失败。')
81
- },
82
- progress: { value: 0, determinate: true, phase: 'failed' },
83
- showPanel: true
84
- };
73
+ currentView = await reconcileAfterActionError(error, {
74
+ action,
75
+ fallbackMessage: tx('Update failed.', '更新失败。')
76
+ });
85
77
  } finally {
86
78
  actionInFlight = false;
87
79
  render();
@@ -99,17 +91,47 @@
99
91
  return response.result;
100
92
  }
101
93
 
102
- async function openUpdateCenter(action = '') {
103
- const response = await chrome.runtime.sendMessage({
104
- type: 'codex-overleaf/consent-update-open-center',
105
- action
106
- });
107
- if (!response?.ok) {
108
- const error = new Error(response?.error?.message || tx('Could not open Update Center.', '无法打开更新中心。'));
109
- error.code = response?.error?.code || 'update_center_open_failed';
110
- throw error;
94
+ async function reconcileAfterActionError(error, options = {}) {
95
+ if (options.action === 'install' && isRuntimeRestartError(error)) {
96
+ return buildRestartingView();
111
97
  }
112
- return response.result;
98
+ try {
99
+ const authoritativeView = await request('codex-overleaf/consent-update-get-state');
100
+ if (authoritativeView?.state) return authoritativeView;
101
+ } catch (_stateError) {
102
+ // The local fallback below is used only when the global coordinator is unavailable too.
103
+ }
104
+ return {
105
+ ...(currentView || {}),
106
+ state: {
107
+ ...(currentView?.state || {}),
108
+ state: 'failed',
109
+ code: error?.code || 'update_failed',
110
+ message: error?.message || options.fallbackMessage || tx('Update failed.', '更新失败。')
111
+ },
112
+ progress: { value: 0, determinate: true, phase: 'failed' },
113
+ showPanel: true
114
+ };
115
+ }
116
+
117
+ function isRuntimeRestartError(error) {
118
+ return /extension context invalidated|message (?:port|channel) closed|receiving end does not exist|could not establish connection|disconnected port/i.test(
119
+ String(error?.message || error || '')
120
+ );
121
+ }
122
+
123
+ function buildRestartingView() {
124
+ return {
125
+ ...(currentView || {}),
126
+ state: {
127
+ ...(currentView?.state || {}),
128
+ state: 'awaiting_health',
129
+ code: '',
130
+ message: ''
131
+ },
132
+ progress: { value: 90, determinate: false, phase: 'awaiting_health' },
133
+ showPanel: true
134
+ };
113
135
  }
114
136
 
115
137
  function bindSettingsControls(panel) {
@@ -127,28 +149,23 @@
127
149
  settingsActionInFlight = true;
128
150
  renderSettings();
129
151
  const stateName = currentView?.state?.state || 'idle';
152
+ let requestedAction = 'check';
130
153
  try {
131
154
  if (stateName === 'update_available') {
132
- await openUpdateCenter('install');
155
+ requestedAction = 'install';
156
+ currentView = await request('codex-overleaf/consent-update-install');
133
157
  } else if (['failed', 'rolled_back'].includes(stateName)) {
134
- await openUpdateCenter('retry');
135
- } else if (['downloading', 'staged', 'waiting_for_idle', 'applying', 'awaiting_health'].includes(stateName)) {
136
- await openUpdateCenter('');
137
- } else {
138
158
  currentView = await request('codex-overleaf/consent-update-check');
159
+ } else if (!ACTIVE_UPDATE_STATES.has(stateName)) {
160
+ currentView = await request('codex-overleaf/consent-update-check');
161
+ } else {
162
+ return;
139
163
  }
140
164
  } catch (error) {
141
- currentView = {
142
- ...(currentView || {}),
143
- state: {
144
- ...(currentView?.state || {}),
145
- state: 'failed',
146
- code: error?.code || 'update_failed',
147
- message: error?.message || tx('Update check failed.', '更新检查失败。')
148
- },
149
- progress: { value: 0, determinate: true, phase: 'failed' },
150
- showPanel: true
151
- };
165
+ currentView = await reconcileAfterActionError(error, {
166
+ action: requestedAction,
167
+ fallbackMessage: tx('Update check failed.', '更新检查失败。')
168
+ });
152
169
  } finally {
153
170
  settingsActionInFlight = false;
154
171
  render();
@@ -159,7 +176,6 @@
159
176
  if (!currentView) return;
160
177
  renderSettings();
161
178
  if (!notice) return;
162
- clearTimeout(completionTimer);
163
179
  if (!currentView.showPanel) {
164
180
  notice.hidden = true;
165
181
  notice.replaceChildren();
@@ -214,11 +230,6 @@
214
230
  if (focusedAction) {
215
231
  notice.querySelector('[data-update-notice-action="' + focusedAction + '"]:not(:disabled)')?.focus();
216
232
  }
217
- if (state.state === 'committed') {
218
- completionTimer = setTimeout(() => {
219
- if (notice?.dataset.state === 'committed') notice.hidden = true;
220
- }, 5000);
221
- }
222
233
  }
223
234
 
224
235
  function renderSettings() {
@@ -235,7 +246,6 @@
235
246
  : '';
236
247
  const currentVersion = state.currentVersion || manifestVersion || '';
237
248
  const latestVersion = state.latestVersion || '';
238
- const activeStates = ['downloading', 'staged', 'waiting_for_idle', 'applying', 'awaiting_health'];
239
249
  let summaryText = tx(
240
250
  `Current v${currentVersion}. Signed stable releases are checked automatically.`,
241
251
  `当前版本 v${currentVersion}。系统会自动检查签名稳定版本。`
@@ -250,9 +260,9 @@
250
260
  summaryText = tx(`Stable v${latestVersion} is available.`, `稳定版本 v${latestVersion} 已可用。`);
251
261
  statusText = tx('Ready to download and verify.', '已可下载并验证。');
252
262
  buttonText = tx('Update now', '立即更新');
253
- } else if (activeStates.includes(stateName)) {
263
+ } else if (ACTIVE_UPDATE_STATES.has(stateName)) {
254
264
  statusText = getCopy(state).detail;
255
- buttonText = tx('View update', '查看更新');
265
+ buttonText = tx('Update in progress', '更新进行中');
256
266
  } else if (stateName === 'failed' || stateName === 'rolled_back') {
257
267
  statusText = state.message || getCopy(state).detail;
258
268
  buttonText = tx('Retry', '重试');
@@ -265,7 +275,7 @@
265
275
  status.textContent = statusText;
266
276
  status.hidden = !statusText;
267
277
  button.textContent = buttonText;
268
- button.disabled = settingsActionInFlight || stateName === 'checking';
278
+ button.disabled = settingsActionInFlight || stateName === 'checking' || ACTIVE_UPDATE_STATES.has(stateName);
269
279
  }
270
280
 
271
281
  function visibleActions(state) {
@@ -282,12 +292,15 @@
282
292
  if (['failed', 'rolled_back'].includes(state)) {
283
293
  return [{ id: 'retry', label: tx('Retry', '重试'), primary: true }];
284
294
  }
295
+ if (state === 'committed') {
296
+ return [{ id: 'dismiss', label: tx('Done', '完成'), primary: true }];
297
+ }
285
298
  return [];
286
299
  }
287
300
 
288
301
  function getCopy(state) {
289
302
  const target = state.latestVersion ? 'v' + state.latestVersion : '';
290
- const blocker = blockerCopy(state.blocker);
303
+ const blocker = blockersCopy(state.blockers?.length ? state.blockers : [state.blocker]);
291
304
  return {
292
305
  update_available: {
293
306
  eyebrow: tx('Update available', '发现新版本'),
@@ -341,15 +354,35 @@
341
354
  return {
342
355
  unsaved: tx('Overleaf has not confirmed that this document is saved.', 'Overleaf 尚未确认当前文档已保存。'),
343
356
  active_run: tx('A Codex task is still running.', 'Codex 任务仍在运行。'),
357
+ run: tx('A Codex task is still running in an Overleaf tab.', '某个 Overleaf 标签页中的 Codex 任务仍在运行。'),
344
358
  cancelling: tx('Cancellation is still settling.', '取消操作仍在收尾。'),
345
359
  storage_write: tx('Extension state is still being saved.', '扩展状态仍在保存。'),
360
+ storage: tx('Extension state is still being saved.', '扩展状态仍在保存。'),
346
361
  review_action: tx('Accept or Undo is still running.', '接受或撤销操作仍在进行。'),
362
+ reviewAction: tx('Accept or Undo is still running.', '接受或撤销操作仍在进行。'),
347
363
  dialog_open: tx('A confirmation dialog is open.', '确认对话框仍处于打开状态。'),
364
+ dialog: tx('A confirmation dialog is open.', '确认对话框仍处于打开状态。'),
365
+ recent_user_activity: tx('Waiting briefly after the latest editor activity.', '正在等待最近一次编辑操作稳定下来。'),
366
+ save_state_not_stable: tx('The saved state is being confirmed.', '正在确认稳定的已保存状态。'),
367
+ save_state_unverified: tx('An Overleaf tab has not verified its saved state yet.', '某个 Overleaf 标签页尚未验证已保存状态。'),
368
+ tab_probe_timeout: tx('An Overleaf tab did not answer the safety check. Reload that tab if this persists.', '某个 Overleaf 标签页未响应安全检查;若持续出现,请刷新该标签页。'),
369
+ tab_probe_unavailable: tx('An Overleaf tab needs to be reloaded before it can join the safety check.', '某个 Overleaf 标签页需要刷新后才能参与安全检查。'),
370
+ tab_unavailable: tx('An Overleaf tab is unavailable for the safety check.', '某个 Overleaf 标签页当前无法完成安全检查。'),
371
+ idle_probe_failed: tx('The Overleaf safety check failed. Reload the affected tab and retry.', 'Overleaf 安全检查失败;请刷新受影响的标签页后重试。'),
348
372
  native_project_locked: tx('Native Host still holds a project lock.', 'Native Host 仍持有项目锁。'),
349
- native_run_active: tx('Native Host is still processing a task.', 'Native Host 仍在处理任务。')
373
+ native_run_active: tx('Native Host is still processing a task.', 'Native Host 仍在处理任务。'),
374
+ busy: tx('A component is still busy.', '某个组件仍处于忙碌状态。')
350
375
  }[value] || tx('Waiting until every Overleaf tab is saved and idle.', '正在等待所有 Overleaf 标签页完成保存并进入空闲状态。');
351
376
  }
352
377
 
378
+ function blockersCopy(values = []) {
379
+ const messages = [...new Set(values.filter(Boolean).map(blockerCopy))];
380
+ return messages.join(' ') || tx(
381
+ 'Waiting until every Overleaf tab is saved and idle.',
382
+ '正在等待所有 Overleaf 标签页完成保存并进入空闲状态。'
383
+ );
384
+ }
385
+
353
386
  function tx(english, chinese) {
354
387
  const locale = String(getLocale() || document.documentElement?.lang || 'en');
355
388
  return /^zh\b/i.test(locale) ? chinese : english;
@@ -12,7 +12,7 @@
12
12
  const MIN_NATIVE_VERSION = '1.0.0';
13
13
  const MIN_COMPATIBLE_NATIVE_VERSION = '1.0.0';
14
14
  const MIN_COMPATIBLE_EXTENSION_VERSION = '1.0.0';
15
- const BUILD_TARGET_VERSION = '1.9.8';
15
+ const BUILD_TARGET_VERSION = '1.9.10';
16
16
  const DEFAULT_CHROME_EXTENSION_ID = 'illdpneeeopfffmiepaejglgmhpmdhdc';
17
17
  const REQUIRED_CAPABILITIES = Object.freeze([
18
18
  'bridgePing',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-overleaf-link",
3
- "version": "1.9.8",
3
+ "version": "1.9.10",
4
4
  "description": "Cross-platform Chrome bridge that connects Codex to the active Overleaf project.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",