Prechádzať zdrojové kódy

feat: added manual version check button

Sv443 1 rok pred
rodič
commit
53c18419bc

+ 30 - 16
assets/translations/README.md

@@ -6,15 +6,15 @@ To submit or edit a translation, please follow [this guide](../../contributing.m
 ### Translation progress:
 | Locale | Translated keys | Based on |
 | ------ | --------------- | :------: |
-| [`en_US`](./en_US.json) | 156 (default locale) |  |
-| [`de_DE`](./de_DE.json) | 🚫 `123/156` (78.8%) | ─ |
-| [`en_UK`](./en_UK.json) | ✅ `156/156` (100.0%) | `en_US` |
-| [`es_ES`](./es_ES.json) | 🚫 `123/156` (78.8%) | ─ |
-| [`fr_FR`](./fr_FR.json) | 🚫 `123/156` (78.8%) | ─ |
-| [`hi_IN`](./hi_IN.json) | 🚫 `123/156` (78.8%) | ─ |
-| [`ja_JA`](./ja_JA.json) | 🚫 `123/156` (78.8%) | ─ |
-| [`pt_BR`](./pt_BR.json) | 🚫 `123/156` (78.8%) | ─ |
-| [`zh_CN`](./zh_CN.json) | 🚫 `123/156` (78.8%) | ─ |
+| [`en_US`](./en_US.json) | 158 (default locale) |  |
+| [`de_DE`](./de_DE.json) | 🚫 `123/158` (77.8%) | ─ |
+| [`en_UK`](./en_UK.json) | ✅ `158/158` (100.0%) | `en_US` |
+| [`es_ES`](./es_ES.json) | 🚫 `123/158` (77.8%) | ─ |
+| [`fr_FR`](./fr_FR.json) | 🚫 `123/158` (77.8%) | ─ |
+| [`hi_IN`](./hi_IN.json) | 🚫 `123/158` (77.8%) | ─ |
+| [`ja_JA`](./ja_JA.json) | 🚫 `123/158` (77.8%) | ─ |
+| [`pt_BR`](./pt_BR.json) | 🚫 `123/158` (77.8%) | ─ |
+| [`zh_CN`](./zh_CN.json) | 🚫 `123/158` (77.8%) | ─ |
 
 <br>
 
@@ -25,7 +25,7 @@ This means you need to manually check against the base translations for missing
 
 ### Missing keys:
 
-<details><summary><code>de_DE</code> - 33 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>de_DE</code> - 35 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -60,12 +60,14 @@ This means you need to manually check against the base translations for missing
 | `feature_desc_clearLyricsCache` | `Clear the lyrics cache manually` |
 | `feature_helptext_clearLyricsCache` | `If the lyrics that are in the local cache are outdated or you just want to free up some space, you can clear the cache manually by pressing this button.` |
 | `feature_btn_clearLyricsCache` | `Clear cache` |
+| `feature_desc_checkVersionNow` | `Manually check for a new version` |
+| `feature_btn_checkVersionNow` | `Check now` |
 | `feature_desc_advancedMode` | `Show advanced settings (after reload)` |
 | `feature_helptext_advancedMode` | `Show advanced settings in the configuration menu after reloading the page.\nThis is useful if you want to more deeply customize the script's behavior.` |
 
 <br></details>
 
-<details><summary><code>es_ES</code> - 33 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>es_ES</code> - 35 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -100,12 +102,14 @@ This means you need to manually check against the base translations for missing
 | `feature_desc_clearLyricsCache` | `Clear the lyrics cache manually` |
 | `feature_helptext_clearLyricsCache` | `If the lyrics that are in the local cache are outdated or you just want to free up some space, you can clear the cache manually by pressing this button.` |
 | `feature_btn_clearLyricsCache` | `Clear cache` |
+| `feature_desc_checkVersionNow` | `Manually check for a new version` |
+| `feature_btn_checkVersionNow` | `Check now` |
 | `feature_desc_advancedMode` | `Show advanced settings (after reload)` |
 | `feature_helptext_advancedMode` | `Show advanced settings in the configuration menu after reloading the page.\nThis is useful if you want to more deeply customize the script's behavior.` |
 
 <br></details>
 
-<details><summary><code>fr_FR</code> - 33 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>fr_FR</code> - 35 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -140,12 +144,14 @@ This means you need to manually check against the base translations for missing
 | `feature_desc_clearLyricsCache` | `Clear the lyrics cache manually` |
 | `feature_helptext_clearLyricsCache` | `If the lyrics that are in the local cache are outdated or you just want to free up some space, you can clear the cache manually by pressing this button.` |
 | `feature_btn_clearLyricsCache` | `Clear cache` |
+| `feature_desc_checkVersionNow` | `Manually check for a new version` |
+| `feature_btn_checkVersionNow` | `Check now` |
 | `feature_desc_advancedMode` | `Show advanced settings (after reload)` |
 | `feature_helptext_advancedMode` | `Show advanced settings in the configuration menu after reloading the page.\nThis is useful if you want to more deeply customize the script's behavior.` |
 
 <br></details>
 
-<details><summary><code>hi_IN</code> - 33 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>hi_IN</code> - 35 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -180,12 +186,14 @@ This means you need to manually check against the base translations for missing
 | `feature_desc_clearLyricsCache` | `Clear the lyrics cache manually` |
 | `feature_helptext_clearLyricsCache` | `If the lyrics that are in the local cache are outdated or you just want to free up some space, you can clear the cache manually by pressing this button.` |
 | `feature_btn_clearLyricsCache` | `Clear cache` |
+| `feature_desc_checkVersionNow` | `Manually check for a new version` |
+| `feature_btn_checkVersionNow` | `Check now` |
 | `feature_desc_advancedMode` | `Show advanced settings (after reload)` |
 | `feature_helptext_advancedMode` | `Show advanced settings in the configuration menu after reloading the page.\nThis is useful if you want to more deeply customize the script's behavior.` |
 
 <br></details>
 
-<details><summary><code>ja_JA</code> - 33 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>ja_JA</code> - 35 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -220,12 +228,14 @@ This means you need to manually check against the base translations for missing
 | `feature_desc_clearLyricsCache` | `Clear the lyrics cache manually` |
 | `feature_helptext_clearLyricsCache` | `If the lyrics that are in the local cache are outdated or you just want to free up some space, you can clear the cache manually by pressing this button.` |
 | `feature_btn_clearLyricsCache` | `Clear cache` |
+| `feature_desc_checkVersionNow` | `Manually check for a new version` |
+| `feature_btn_checkVersionNow` | `Check now` |
 | `feature_desc_advancedMode` | `Show advanced settings (after reload)` |
 | `feature_helptext_advancedMode` | `Show advanced settings in the configuration menu after reloading the page.\nThis is useful if you want to more deeply customize the script's behavior.` |
 
 <br></details>
 
-<details><summary><code>pt_BR</code> - 33 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>pt_BR</code> - 35 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -260,12 +270,14 @@ This means you need to manually check against the base translations for missing
 | `feature_desc_clearLyricsCache` | `Clear the lyrics cache manually` |
 | `feature_helptext_clearLyricsCache` | `If the lyrics that are in the local cache are outdated or you just want to free up some space, you can clear the cache manually by pressing this button.` |
 | `feature_btn_clearLyricsCache` | `Clear cache` |
+| `feature_desc_checkVersionNow` | `Manually check for a new version` |
+| `feature_btn_checkVersionNow` | `Check now` |
 | `feature_desc_advancedMode` | `Show advanced settings (after reload)` |
 | `feature_helptext_advancedMode` | `Show advanced settings in the configuration menu after reloading the page.\nThis is useful if you want to more deeply customize the script's behavior.` |
 
 <br></details>
 
-<details><summary><code>zh_CN</code> - 33 missing keys <i>(click to show)</i></summary><br>
+<details><summary><code>zh_CN</code> - 35 missing keys <i>(click to show)</i></summary><br>
 
 | Key | English text |
 | --- | ------------ |
@@ -300,6 +312,8 @@ This means you need to manually check against the base translations for missing
 | `feature_desc_clearLyricsCache` | `Clear the lyrics cache manually` |
 | `feature_helptext_clearLyricsCache` | `If the lyrics that are in the local cache are outdated or you just want to free up some space, you can clear the cache manually by pressing this button.` |
 | `feature_btn_clearLyricsCache` | `Clear cache` |
+| `feature_desc_checkVersionNow` | `Manually check for a new version` |
+| `feature_btn_checkVersionNow` | `Check now` |
 | `feature_desc_advancedMode` | `Show advanced settings (after reload)` |
 | `feature_helptext_advancedMode` | `Show advanced settings in the configuration menu after reloading the page.\nThis is useful if you want to more deeply customize the script's behavior.` |
 

+ 2 - 0
assets/translations/en_US.json

@@ -167,6 +167,8 @@
     "feature_desc_locale": "Language",
     "feature_desc_versionCheck": "Check for updates every 24 hours",
     "feature_helptext_versionCheck": "This feature checks for updates every 24 hours, notifies you if a new version is available and allows you to update the script manually.\nIf your userscript manager extension updates scripts automatically, you can disable this feature.",
+    "feature_desc_checkVersionNow": "Manually check for a new version",
+    "feature_btn_checkVersionNow": "Check now",
     "feature_desc_logLevel": "How much information to log to the console",
     "feature_helptext_logLevel": "Changing this is really only needed for debugging purposes as a result of experiencing a problem.\nShould you have one, you can increase the log level here, open your browser's JavaScript console (usually with Ctrl + Shift + K) and attach screenshots of that log in a GitHub issue.",
     "feature_desc_advancedMode": "Show advanced settings (after reload)",

+ 26 - 27
src/config.ts

@@ -21,21 +21,16 @@ export const migrations: ConfigMigrationsDict = {
     };
   },
   // 2 -> 3
-  3: (oldData: Record<string, unknown>) => ({
-    ...oldData,
-    removeShareTrackingParam: getFeatureDefault("removeShareTrackingParam"),
-    numKeysSkipToTime: getFeatureDefault("numKeysSkipToTime"),
-    fixSpacing: getFeatureDefault("fixSpacing"),
-    scrollToActiveSongBtn: getFeatureDefault("scrollToActiveSongBtn"),
-    logLevel: getFeatureDefault("logLevel"),
-  }),
+  3: (oldData: FeatureConfig) => useDefaultConfig([
+    "removeShareTrackingParam", "numKeysSkipToTime",
+    "fixSpacing", "scrollToActiveSongBtn",
+    "logLevel",
+  ], oldData),
   // 3 -> 4
-  4: (oldData: Record<string, unknown>) => {
+  4: (oldData: FeatureConfig) => {
     const oldSwitchSitesHotkey = oldData.switchSitesHotkey as Record<string, unknown>;
     return {
       ...oldData,
-      rememberSongTime: getFeatureDefault("rememberSongTime"),
-      rememberSongTimeSites: getFeatureDefault("rememberSongTimeSites"),
       arrowKeySkipBy: 10,
       switchSitesHotkey: {
         code: oldSwitchSitesHotkey.key ?? "F9",
@@ -44,27 +39,31 @@ export const migrations: ConfigMigrationsDict = {
         alt: Boolean(oldSwitchSitesHotkey.meta ?? false),
       },
       listButtonsPlacement: "queueOnly",
-      volumeSliderScrollStep: getFeatureDefault("volumeSliderScrollStep"),
-      locale: getFeatureDefault("locale"),
-      versionCheck: getFeatureDefault("versionCheck"),
+      ...useDefaultConfig([
+        "rememberSongTime", "rememberSongTimeSites",
+        "volumeSliderScrollStep", "locale",
+        "versionCheck",
+      ], oldData),
     };
   },
   // 4 -> 5
-  5: (oldData: FeatureConfig) => {
-    return {
-      ...oldData,
-      geniUrlBase: getFeatureDefault("geniUrlBase"),
-      geniUrlToken: getFeatureDefault("geniUrlToken"),
-      lyricsCacheMaxSize: getFeatureDefault("lyricsCacheMaxSize"),
-      lyricsCacheTTL: getFeatureDefault("lyricsCacheTTL"),
-      clearLyricsCache: getFeatureDefault("clearLyricsCache"),
-      advancedMode: getFeatureDefault("advancedMode"),
-      lockVolume: getFeatureDefault("lockVolume"),
-      lockVolumeLevel: getFeatureDefault("lockVolumeLevel"),
-    } satisfies FeatureConfig;
-  },
+  5: (oldData: FeatureConfig) => useDefaultConfig([
+    "geniUrlBase", "geniUrlToken",
+    "lyricsCacheMaxSize", "lyricsCacheTTL",
+    "clearLyricsCache", "advancedMode",
+    "lockVolume", "lockVolumeLevel",
+    "checkVersionNow",
+  ], oldData),
 };
 
+/** Uses the passed `oldData` as the base and sets all passed `keys` to their feature default - returns a copy of the object */
+function useDefaultConfig(keys: (keyof typeof featInfo)[], oldData: FeatureConfig): Partial<FeatureConfig> {
+  const newData = { ...oldData };
+  for(const key of keys)
+    newData[key as keyof typeof featInfo] = getFeatureDefault(key as keyof typeof featInfo) as unknown as never;
+  return newData;
+}
+
 function getFeatureDefault<TKey extends keyof typeof featInfo>(key: TKey): typeof featInfo[TKey]["default"] {
   return featInfo[key].default;
 }

+ 9 - 1
src/features/index.ts

@@ -1,7 +1,8 @@
 import { getPreferredLocale, resourceToHTMLString, t, tp } from "../utils";
 import langMapping from "../../assets/locales.json" assert { type: "json" };
 import { remSongMinPlayTime } from "./behavior";
-import { clearLyricsCache, getLyricsCache } from "./lyrics";
+import { clearLyricsCache, getLyricsCache } from "./lyricsCache";
+import { doVersionCheck } from "./versionCheck";
 import { mode } from "../constants";
 import { getFeatures } from "../config";
 import { FeatureInfo } from "../types";
@@ -10,6 +11,7 @@ export * from "./layout";
 export * from "./behavior";
 export * from "./input";
 export * from "./lyrics";
+export * from "./lyricsCache";
 export * from "./songLists";
 export * from "./versionCheck";
 
@@ -354,6 +356,12 @@ export const featInfo = {
     enable: noopTODO,
     disable: noopTODO,
   },
+  checkVersionNow: {
+    type: "button",
+    category: "general",
+    default: undefined,
+    click: () => doVersionCheck(true),
+  },
   logLevel: {
     type: "select",
     category: "general",

+ 27 - 19
src/features/versionCheck.ts

@@ -1,11 +1,11 @@
 import { scriptInfo } from "../constants";
 import { getFeatures } from "../config";
-import { error, info, sendRequest } from "../utils";
+import { error, info, sendRequest, t } from "../utils";
 import { getVersionNotifDialog } from "../dialogs";
 
 const releaseURL = "https://github.com/Sv443/BetterYTM/releases/latest";
 
-export async function checkVersion() {
+export async function initVersionCheck() {
   try {
     if(getFeatures().versionCheck === false)
       return info("Version check is disabled");
@@ -14,30 +14,38 @@ export async function checkVersion() {
     if(Date.now() - lastCheck < 1000 * 60 * 60 * 24)
       return;
 
-    await GM.setValue("bytm-version-check", Date.now());
+    await doVersionCheck(false);
+  }
+  catch(err) {
+    error("Version check failed:", err);
+  }
+}
 
-    const res = await sendRequest({
-      method: "GET",
-      url: releaseURL,
-    });
+export async function doVersionCheck(notifyNoUpdatesFound = false) {
+  await GM.setValue("bytm-version-check", Date.now());
 
-    const latestTag = res.finalUrl.split("/").pop()?.replace(/[a-zA-Z]/g, "");
+  const res = await sendRequest({
+    method: "GET",
+    url: releaseURL,
+  });
 
-    if(!latestTag)
-      return;
+  // TODO: small dialog for "no update found" message?
+  const noUpdateFound = () => notifyNoUpdatesFound ? alert(t("no_updates_found")) : undefined;
 
-    const versionComp = compareVersions(scriptInfo.version, latestTag);
+  const latestTag = res.finalUrl.split("/").pop()?.replace(/[a-zA-Z]/g, "");
 
-    info("Version check - current version:", scriptInfo.version, "- latest version:", latestTag);
+  if(!latestTag)
+    return noUpdateFound();
 
-    if(versionComp < 0) {
-      const dialog = await getVersionNotifDialog({ latestTag });
-      await dialog.open();
-    }
-  }
-  catch(err) {
-    error("Version check failed:", err);
+  const versionComp = compareVersions(scriptInfo.version, latestTag);
+
+  info("Version check - current version:", scriptInfo.version, "- latest version:", latestTag);
+
+  if(versionComp < 0) {
+    const dialog = await getVersionNotifDialog({ latestTag });
+    return await dialog.open();
   }
+  return noUpdateFound();
 }
 
 /**