|
146 | 146 | initialize(); |
147 | 147 | } |
148 | 148 |
|
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 | + // } |
189 | 189 |
|
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 | + // } |
197 | 197 |
|
198 | 198 | async function openSaveLocation() { |
199 | 199 | disabled = true; |
|
302 | 302 | } |
303 | 303 | items = matches.matches; |
304 | 304 |
|
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 | + // } |
332 | 335 |
|
333 | 336 | // check if current page url is a userscript |
334 | 337 | if (strippedUrl.endsWith(".user.js")) { |
|
344 | 347 | disabled = false; |
345 | 348 | } |
346 | 349 |
|
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 | + // } |
356 | 362 |
|
357 | 363 | /** @type {import("svelte/elements").UIEventHandler<Window>} */ |
358 | 364 | // async function resizeHandler(event) { |
|
473 | 479 | loading={disabled} |
474 | 480 | closeClick={() => (showUpdates = false)} |
475 | 481 | showLoaderOnDisabled={true} |
476 | | - abortClick={abortUpdates} |
477 | 482 | abort={showUpdates} |
478 | 483 | > |
479 | 484 | <UpdateView |
|
565 | 570 | </div> |
566 | 571 | <div class="main {rowColors || ''}" bind:this={main}> |
567 | 572 | {#if loading} |
568 | | - <Loader abortClick={abortUpdates} {abort} /> |
| 573 | + <Loader {abort} /> |
569 | 574 | {:else if inactive} |
570 | 575 | <div class="none">Popup inactive on extension page</div> |
571 | 576 | {:else if firstGuide} |
|
0 commit comments