Răsfoiți Sursa

Merge remote-tracking branch 'LOCAL-main/master' into vue3

# Conflicts:
#	src/background/utils/update.js
#	src/options/views/app.vue
tophf 3 ani în urmă
părinte
comite
1bfb03b5cb

+ 1 - 1
src/background/index.js

@@ -133,7 +133,7 @@ initialize(() => {
   const api = global.chrome.declarativeContent;
   if (api) {
     // Using declarativeContent to run content scripts earlier than document_start
-    api.onPageChanged.getRules(async ([rule]) => {
+    api.onPageChanged.getRules(/* for old Chrome */ null, async ([rule]) => {
       const id = rule?.id;
       const newId = process.env.INIT_FUNC_NAME;
       if (id === newId) {

+ 1 - 1
src/background/utils/db.js

@@ -157,7 +157,7 @@ preInitialize.push(async () => {
       require.forEach(rememberUrl, pathMap);
       resources::forEachValue(rememberUrl, pathMap);
       pathMap::rememberUrl(meta.icon);
-      pathMap::rememberUrl(getScriptUpdateUrl(script));
+      getScriptUpdateUrl(script, true)?.forEach(rememberUrl, pathMap);
     } else if (key.startsWith(storage.mod.prefix)) {
       mods.push(key.slice(storage.mod.prefix.length));
     }

+ 5 - 3
src/background/utils/update.js

@@ -1,6 +1,6 @@
 import {
   compareVersion, getScriptName, getScriptUpdateUrl,
-  i18n, request, sendCmd, trueJoin,
+  i18n, sendCmd, trueJoin,
 } from '@/common';
 import { fetchResources, getScriptById, getScripts, parseScript } from './db';
 import { parseMeta } from './script';
@@ -90,7 +90,6 @@ async function downloadUpdate(script, urls) {
   announce(i18n('msgCheckingForUpdate'));
   try {
     const { data } = await requestNewer(updateURL, {
-      // TODO: do a HEAD request first to get ETag header and compare to storage.mod
       cache: 'no-cache',
       headers: { Accept: 'text/x-userscript-meta,*/*' },
     }) || {};
@@ -99,10 +98,13 @@ async function downloadUpdate(script, urls) {
       announce(i18n('msgNoUpdate'), { checking: false });
     } else if (!downloadURL) {
       announce(i18n('msgNewVersion'), { checking: false });
+    } else if (downloadURL === updateURL) {
+      announce(i18n('msgUpdated'));
+      return data;
     } else {
       announce(i18n('msgUpdating'));
       errorMessage = i18n('msgErrorFetchingScript');
-      return (await request(downloadURL, { cache: 'no-cache' })).data;
+      return (await requestNewer(downloadURL, { cache: 'no-cache' })).data;
     }
   } catch (error) {
     if (process.env.DEBUG) console.error(error);

+ 2 - 3
src/options/views/app.vue

@@ -24,7 +24,6 @@
 
 <script>
 import { i18n } from '@/common';
-import { setRoute } from '@/common/router';
 import Icon from '@/common/ui/icon';
 import { keyboardService } from '@/common/keyboard';
 import { store, installedScripts } from '../utils';
@@ -88,14 +87,14 @@ export default {
     switchTab(step) {
       const index = this.tabs.indexOf(this.current);
       const switchTo = this.tabs[(index + step + this.tabs.length) % this.tabs.length];
-      setRoute(switchTo?.name || '');
+      window.location.hash = switchTo?.name || '';
     },
   },
   created() {
     document.addEventListener('dragover', evt => {
       if (['', ABOUT, SCRIPTS].includes(this.store.route.hash)
       && /^application\/(zip|x-zip-compressed)$/.test(evt.dataTransfer.items[0]?.type)) {
-        setRoute(`#${SETTINGS}`);
+        window.location.hash = `#${SETTINGS}`;
       }
     });
   },

+ 1 - 1
src/options/views/tab-installed.vue

@@ -398,7 +398,7 @@ export default {
     onHashChange() {
       const [tab, id] = this.store.route.paths;
       if (id === '_new') {
-        this.script = {};
+        sendCmdDirectly('NewScript').then(res => { this.script = res.script; });
       } else {
         const nid = id && +id || null;
         this.script = nid && this.scripts.find(script => script.props.id === nid);