From 3ba78dec7848af0b36d8cff8c97f9c3d72e2a4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 20 Jul 2022 14:23:28 +0300 Subject: [PATCH] Changes for updated SingleFile submodule --- .../zotero/xpcom/utilities_internal.js | 22 +++++++++++-------- scripts/babel-worker.js | 2 +- scripts/config.js | 6 ++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index 00ea03dc1b..e91528ed3c 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -598,11 +598,10 @@ Zotero.Utilities.Internal = { const SCRIPTS = [ // This first script replace in the INDEX_SCRIPTS from the single file cli loader - "dist/single-file.js", + "lib/single-file.js", // Web SCRIPTS - "dist/web/hooks/hooks-frames-web.js", - "dist/web/hooks/hooks-web.js", + "lib/single-file-hooks-frames.js", ]; const { loadSubScript } = Components.classes['@mozilla.org/moz/jssubscript-loader;1'] @@ -628,8 +627,8 @@ Zotero.Utilities.Internal = { // List of scripts from: // resource/SingleFile/extension/lib/single-file/core/bg/scripts.js const frameScripts = [ - "dist/web/hooks/hooks-frames-web.js", - "dist/single-file-frames.js", + "lib/single-file-hooks-frames.js", + "lib/single-file-frames.js", ]; // Create sandboxes for all the frames we find @@ -681,7 +680,7 @@ Zotero.Utilities.Internal = { // Mostly copied from: // resources/SingleFile/extension/lib/single-file/fetch/bg/fetch.js::fetchResource sandbox.coFetch = Components.utils.exportFunction( - function (url, onDone) { + function (url, options, onDone) { const xhrRequest = new XMLHttpRequest(); xhrRequest.withCredentials = true; xhrRequest.responseType = "arraybuffer"; @@ -707,6 +706,11 @@ Zotero.Utilities.Internal = { } }; xhrRequest.open("GET", url, true); + if (options && options.headers) { + for (const entry of Object.entries(options.headers)) { + xhrRequest.setRequestHeader(entry[0], entry[1]); + } + } xhrRequest.send(); }, sandbox @@ -717,14 +721,14 @@ Zotero.Utilities.Internal = { // resources/SingleFile/extension/lib/single-file/fetch/content/content-fetch.js::fetch Components.utils.evalInSandbox( ` - ZoteroFetch = async function (url) { + ZoteroFetch = async function (url, options) { try { - let response = await fetch(url, { cache: "force-cache" }); + let response = await fetch(url, { cache: "force-cache", headers: options.headers }); return response; } catch (error) { let response = await new Promise((resolve, reject) => { - coFetch(url, (response) => { + coFetch(url, { headers: options.headers }, (response) => { if (response.error) { Zotero.debug("Error retrieving url: " + url); Zotero.debug(response); diff --git a/scripts/babel-worker.js b/scripts/babel-worker.js index 3882cd6978..32605633a5 100644 --- a/scripts/babel-worker.js +++ b/scripts/babel-worker.js @@ -48,7 +48,7 @@ async function babelWorker(ev) { .replace('document.body.removeChild(scrollDiv)', 'document.documentElement.removeChild(scrollDiv)'); } // Patch single-file - else if (sourcefile === 'resource/SingleFile/dist/single-file.js') { + else if (sourcefile === 'resource/SingleFile/lib/single-file.js') { // Change for what I assume is a bug in Firefox. We create a singlefile // sandbox which is based on a document.defaultView of a hidden browser. // The minified single-file then uses globalThis.Set which for some reason diff --git a/scripts/config.js b/scripts/config.js index 508850c649..3e45c74ecb 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -37,8 +37,8 @@ const symlinkFiles = [ // Only include dist directory of singleFile // Also do a little bit of manipulation similar to React '!resource/SingleFile/**/*', - 'resource/SingleFile/dist/**/*', - '!resource/SingleFile/dist/single-file.js', + 'resource/SingleFile/lib/**/*', + '!resource/SingleFile/lib/single-file.js', // We only need a couple Ace Editor files '!resource/ace/**/*', 'resource/ace/ace.js', @@ -112,7 +112,7 @@ const jsFiles = [ 'resource/react.js', 'resource/react-dom.js', 'resource/react-virtualized.js', - 'resource/SingleFile/dist/single-file.js', + 'resource/SingleFile/lib/single-file.js', 'resource/citeproc_rs_wasm.js', ];