Skip to content

Commit 047591d

Browse files
authored
Merge pull request #895 from quoid/disable-auto-scripts-update-check
fix: temporarily disable auto scripts update check
2 parents 4b0e167 + 89c0129 commit 047591d

3 files changed

Lines changed: 92 additions & 93 deletions

File tree

src/ext/action-popup/App.svelte

Lines changed: 90 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -146,54 +146,54 @@
146146
initialize();
147147
}
148148
149-
async function shouldCheckForUpdates() {
150-
// if there's no network connectivity, do not check for updates
151-
if (!window || !window.navigator || !window.navigator.onLine) {
152-
console.info("user is offline, not running update check");
153-
return false;
154-
}
155-
// when an update check is run, a timestamp is saved to extension storage
156-
// only check for updates every n milliseconds to avoid delaying popup load regularly
157-
const checkInterval = 24 * 60 * 60 * 1000; // 24hr, 86400000
158-
const timestampMs = Date.now();
159-
let lastUpdateCheck = 0;
160-
// check extension storage for saved key/val
161-
// if there's an issue getting extension storage, skip the check
162-
let lastUpdateCheckObj;
163-
try {
164-
lastUpdateCheckObj = await browser.storage.local.get(["lastUpdateCheck"]);
165-
} catch (error) {
166-
console.error(`Error checking extension storage ${error}`);
167-
return false;
168-
}
169-
// if extension storage doesn't have key, run the check
170-
// key/val will be saved after the update check runs
171-
if (Object.keys(lastUpdateCheckObj).length === 0) {
172-
console.info("no last check saved, running update check");
173-
return true;
174-
}
175-
// if the val is not a number, something went wrong, check anyway
176-
// when update re-runs, new val of the proper type will be saved
177-
if (!Number.isFinite(lastUpdateCheckObj.lastUpdateCheck)) {
178-
console.info("run check saved with wrong type, running update check");
179-
return true;
180-
}
181-
// at this point it is known that key exists and value is a number
182-
// update local var with the val saved to extension storage
183-
lastUpdateCheck = lastUpdateCheckObj.lastUpdateCheck;
184-
// if less than n milliseconds have passed, don't check
185-
if (timestampMs - lastUpdateCheck < checkInterval) {
186-
console.info("not enough time has passed, not running update check");
187-
return false;
188-
}
149+
// async function shouldCheckForUpdates() {
150+
// // if there's no network connectivity, do not check for updates
151+
// if (!window || !window.navigator || !window.navigator.onLine) {
152+
// console.info("user is offline, not running update check");
153+
// return false;
154+
// }
155+
// // when an update check is run, a timestamp is saved to extension storage
156+
// // only check for updates every n milliseconds to avoid delaying popup load regularly
157+
// const checkInterval = 24 * 60 * 60 * 1000; // 24hr, 86400000
158+
// const timestampMs = Date.now();
159+
// let lastUpdateCheck = 0;
160+
// // check extension storage for saved key/val
161+
// // if there's an issue getting extension storage, skip the check
162+
// let lastUpdateCheckObj;
163+
// try {
164+
// lastUpdateCheckObj = await browser.storage.local.get(["lastUpdateCheck"]);
165+
// } catch (error) {
166+
// console.error(`Error checking extension storage ${error}`);
167+
// return false;
168+
// }
169+
// // if extension storage doesn't have key, run the check
170+
// // key/val will be saved after the update check runs
171+
// if (Object.keys(lastUpdateCheckObj).length === 0) {
172+
// console.info("no last check saved, running update check");
173+
// return true;
174+
// }
175+
// // if the val is not a number, something went wrong, check anyway
176+
// // when update re-runs, new val of the proper type will be saved
177+
// if (!Number.isFinite(lastUpdateCheckObj.lastUpdateCheck)) {
178+
// console.info("run check saved with wrong type, running update check");
179+
// return true;
180+
// }
181+
// // at this point it is known that key exists and value is a number
182+
// // update local var with the val saved to extension storage
183+
// lastUpdateCheck = lastUpdateCheckObj.lastUpdateCheck;
184+
// // if less than n milliseconds have passed, don't check
185+
// if (timestampMs - lastUpdateCheck < checkInterval) {
186+
// console.info("not enough time has passed, not running update check");
187+
// return false;
188+
// }
189189
190-
console.info(
191-
`${(timestampMs - lastUpdateCheck) / (1000 * 60 * 60)} hours have passed`,
192-
);
193-
console.info("running update check");
194-
// otherwise run the check
195-
return true;
196-
}
190+
// console.info(
191+
// `${(timestampMs - lastUpdateCheck) / (1000 * 60 * 60)} hours have passed`,
192+
// );
193+
// console.info("running update check");
194+
// // otherwise run the check
195+
// return true;
196+
// }
197197
198198
async function openSaveLocation() {
199199
disabled = true;
@@ -302,33 +302,36 @@
302302
}
303303
items = matches.matches;
304304
305-
// get updates
306-
const checkUpdates = await shouldCheckForUpdates();
307-
if (checkUpdates) {
308-
let updatesResponse;
309-
try {
310-
// save timestamp in ms to extension storage
311-
const timestampMs = Date.now();
312-
await browser.storage.local.set({ lastUpdateCheck: timestampMs });
313-
abort = true;
314-
updatesResponse = await sendNativeMessage({ name: "POPUP_UPDATES" });
315-
} catch (error) {
316-
console.error(`Error for updates promise: ${error}`);
317-
initError = true;
318-
loading = false;
319-
abort = false;
320-
return;
321-
}
322-
if (updatesResponse.error) {
323-
errorNotification = updatesResponse.error;
324-
loading = false;
325-
disabled = false;
326-
abort = false;
327-
return;
328-
}
329-
updates = updatesResponse.updates;
330-
abort = false;
331-
}
305+
/**
306+
* get updates
307+
* disabled due to - https://github.com/quoid/userscripts/issues/894
308+
*/
309+
// const checkUpdates = await shouldCheckForUpdates();
310+
// if (checkUpdates) {
311+
// let updatesResponse;
312+
// try {
313+
// // save timestamp in ms to extension storage
314+
// const timestampMs = Date.now();
315+
// await browser.storage.local.set({ lastUpdateCheck: timestampMs });
316+
// abort = true;
317+
// updatesResponse = await sendNativeMessage({ name: "POPUP_UPDATES" });
318+
// } catch (error) {
319+
// console.error(`Error for updates promise: ${error}`);
320+
// initError = true;
321+
// loading = false;
322+
// abort = false;
323+
// return;
324+
// }
325+
// if (updatesResponse.error) {
326+
// errorNotification = updatesResponse.error;
327+
// loading = false;
328+
// disabled = false;
329+
// abort = false;
330+
// return;
331+
// }
332+
// updates = updatesResponse.updates;
333+
// abort = false;
334+
// }
332335
333336
// check if current page url is a userscript
334337
if (strippedUrl.endsWith(".user.js")) {
@@ -344,15 +347,18 @@
344347
disabled = false;
345348
}
346349
347-
async function abortUpdates() {
348-
// sends message to swift side canceling all URLSession tasks
349-
sendNativeMessage({ name: "CANCEL_REQUESTS" });
350-
// timestamp for checking updates happens right before update fetching
351-
// that means when this function runs the timestamp has already been saved
352-
// reloading the window will essentially skip the update check
353-
// since the subsequent popup load will not check for updates
354-
window.location.reload();
355-
}
350+
/**
351+
* Not working due to: https://github.com/quoid/userscripts/issues/276#issuecomment-3507547737
352+
*/
353+
// async function abortUpdates() {
354+
// // sends message to swift side canceling all URLSession tasks
355+
// sendNativeMessage({ name: "CANCEL_REQUESTS" });
356+
// // timestamp for checking updates happens right before update fetching
357+
// // that means when this function runs the timestamp has already been saved
358+
// // reloading the window will essentially skip the update check
359+
// // since the subsequent popup load will not check for updates
360+
// window.location.reload();
361+
// }
356362
357363
/** @type {import("svelte/elements").UIEventHandler<Window>} */
358364
// async function resizeHandler(event) {
@@ -473,7 +479,6 @@
473479
loading={disabled}
474480
closeClick={() => (showUpdates = false)}
475481
showLoaderOnDisabled={true}
476-
abortClick={abortUpdates}
477482
abort={showUpdates}
478483
>
479484
<UpdateView
@@ -565,7 +570,7 @@
565570
</div>
566571
<div class="main {rowColors || ''}" bind:this={main}>
567572
{#if loading}
568-
<Loader abortClick={abortUpdates} {abort} />
573+
<Loader {abort} />
569574
{:else if inactive}
570575
<div class="none">Popup inactive on extension page</div>
571576
{:else if firstGuide}

src/ext/action-popup/Components/View.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
export let closeClick;
1010
export let showLoaderOnDisabled = true;
1111
export let abort = false;
12-
export let abortClick = () => {};
1312
1413
function slide(node, params) {
1514
return {
@@ -28,7 +27,7 @@
2827
</div>
2928
<div class="view__body">
3029
{#if loading && showLoaderOnDisabled}
31-
<Loader backgroundColor="var(--color-bg-primary)" {abortClick} {abort} />
30+
<Loader backgroundColor="var(--color-bg-primary)" {abort} />
3231
{:else}
3332
<slot><div>Slot content is required...</div></slot>
3433
{/if}

src/ext/shared/Components/Loader.svelte

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import iconLoader from "../../shared/img/icon-loader.svg?raw";
44
55
export let abort = false;
6-
export let abortClick = () => {};
76
export let backgroundColor = "var(--color-bg-secondary)";
87
98
/**
@@ -27,11 +26,7 @@
2726
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
2827
{@html iconLoader}
2928
{#if abort}
30-
<div>
31-
Fetching resources, <button class="link" on:click={abortClick}>
32-
cancel request
33-
</button>
34-
</div>
29+
<div>Fetching resources, please wait... (timeout after 30s)</div>
3530
{/if}
3631
</div>
3732

0 commit comments

Comments
 (0)