Prechádzať zdrojové kódy

feat: version notif changelog stuff

Sv443 1 rok pred
rodič
commit
2481a297b4

+ 16 - 4
src/dialogs/versionNotif.ts

@@ -1,5 +1,5 @@
 import { host, scriptInfo } from "../constants";
 import { host, scriptInfo } from "../constants";
-import { BytmDialog, t } from "../utils";
+import { BytmDialog, getChangelogMd, parseMarkdown, t } from "../utils";
 import pkg from "../../package.json" assert { type: "json" };
 import pkg from "../../package.json" assert { type: "json" };
 
 
 let verNotifDialog: BytmDialog | null = null;
 let verNotifDialog: BytmDialog | null = null;
@@ -9,22 +9,32 @@ export type VersionNotifDialogRenderProps = {
 };
 };
 
 
 /** Creates and/or returns the dialog to be shown when a new version is available */
 /** Creates and/or returns the dialog to be shown when a new version is available */
-export function getVersionNotifDialog({
+export async function getVersionNotifDialog({
   latestTag,
   latestTag,
 }: VersionNotifDialogRenderProps) {
 }: VersionNotifDialogRenderProps) {
   if(!verNotifDialog) {
   if(!verNotifDialog) {
+    const changelogMdFull = await getChangelogMd();
+    const changelogMd = changelogMdFull.split("<div class=\"split\">")[1];
+    const changelogHtml = await parseMarkdown(changelogMd);
+
     verNotifDialog = new BytmDialog({
     verNotifDialog = new BytmDialog({
       id: "version-notif",
       id: "version-notif",
       closeOnBgClick: false,
       closeOnBgClick: false,
       closeOnEscPress: false,
       closeOnEscPress: false,
       destroyOnClose: true,
       destroyOnClose: true,
-      renderBody: () => renderBody(latestTag),
+      renderBody: () => renderBody({ latestTag, changelogHtml }),
     });
     });
   }
   }
   return verNotifDialog!;
   return verNotifDialog!;
 }
 }
 
 
-function renderBody(latestTag: string) {
+function renderBody({
+  latestTag,
+  changelogHtml,
+}: {
+  latestTag: string;
+  changelogHtml: string;
+}) {
   const platformNames: Record<typeof host, string> = {
   const platformNames: Record<typeof host, string> = {
     github: "GitHub",
     github: "GitHub",
     greasyfork: "GreasyFork",
     greasyfork: "GreasyFork",
@@ -32,6 +42,8 @@ function renderBody(latestTag: string) {
   };
   };
 
 
   // TODO:
   // TODO:
+  void changelogHtml;
+
   const wrapperEl = document.createElement("div");
   const wrapperEl = document.createElement("div");
 
 
   const pEl = document.createElement("p");
   const pEl = document.createElement("p");

+ 4 - 11
src/features/versionCheck.ts

@@ -1,8 +1,7 @@
-import { scriptInfo, host, platformNames } from "../constants";
+import { scriptInfo } from "../constants";
 import { getFeatures } from "../config";
 import { getFeatures } from "../config";
-import { error, info, sendRequest, t } from "../utils";
+import { error, info, sendRequest } from "../utils";
 import { getVersionNotifDialog } from "../dialogs";
 import { getVersionNotifDialog } from "../dialogs";
-import pkg from "../../package.json" assert { type: "json" };
 
 
 const releaseURL = "https://github.com/Sv443/BetterYTM/releases/latest";
 const releaseURL = "https://github.com/Sv443/BetterYTM/releases/latest";
 
 
@@ -27,19 +26,13 @@ export async function checkVersion() {
     if(!latestTag)
     if(!latestTag)
       return;
       return;
 
 
-    // const latestTag = "1.2.0";
-
     const versionComp = compareVersions(scriptInfo.version, latestTag);
     const versionComp = compareVersions(scriptInfo.version, latestTag);
 
 
     info("Version check - current version:", scriptInfo.version, "- latest version:", latestTag);
     info("Version check - current version:", scriptInfo.version, "- latest version:", latestTag);
 
 
     if(versionComp < 0) {
     if(versionComp < 0) {
-      // const dialog = getVersionNotifDialog({ latestTag });
-      // await dialog.open();
-
-      // TODO: replace with custom dialog
-      if(confirm(t("new_version_available", scriptInfo.name, scriptInfo.version, latestTag, platformNames[host])))
-        window.open(pkg.updates[host]);
+      const dialog = await getVersionNotifDialog({ latestTag });
+      await dialog.open();
     }
     }
   }
   }
   catch(err) {
   catch(err) {

+ 4 - 4
src/menu/menu_old.ts

@@ -1,8 +1,8 @@
-import { compress, decompress, debounce, isScrollable, fetchAdvanced } from "@sv443-network/userutils";
+import { compress, decompress, debounce, isScrollable } from "@sv443-network/userutils";
 import { defaultConfig, getFeatures, migrations, saveFeatures, setDefaultFeatures } from "../config";
 import { defaultConfig, getFeatures, migrations, saveFeatures, setDefaultFeatures } from "../config";
 import { host, scriptInfo } from "../constants";
 import { host, scriptInfo } from "../constants";
 import { featInfo, disableBeforeUnload } from "../features/index";
 import { featInfo, disableBeforeUnload } from "../features/index";
-import { error, getResourceUrl, info, log, resourceToHTMLString, warn, getLocale, hasKey, initTranslations, setLocale, t, parseMarkdown } from "../utils";
+import { error, getResourceUrl, info, log, resourceToHTMLString, warn, getLocale, hasKey, initTranslations, setLocale, t, parseMarkdown, getChangelogMd } from "../utils";
 import { formatVersion } from "../config";
 import { formatVersion } from "../config";
 import { emitSiteEvent, siteEvents } from "../siteEvents";
 import { emitSiteEvent, siteEvents } from "../siteEvents";
 import type { FeatureCategory, FeatureKey, FeatureConfig, HotkeyObj, FeatureInfo } from "../types";
 import type { FeatureCategory, FeatureKey, FeatureConfig, HotkeyObj, FeatureInfo } from "../types";
@@ -1232,8 +1232,8 @@ async function addChangelogMenu() {
 
 
   const getChangelogHtml = (async () => {
   const getChangelogHtml = (async () => {
     try {
     try {
-      const changelogHtmlFull = await (await fetchAdvanced(await getResourceUrl("doc-changelog"))).text();
-      return await parseMarkdown(changelogHtmlFull);
+      const changelogMd = await getChangelogMd();
+      return await parseMarkdown(changelogMd);
     }
     }
     catch(err) {
     catch(err) {
       return `Error: ${err}`;
       return `Error: ${err}`;

+ 5 - 0
src/utils/misc.ts

@@ -104,3 +104,8 @@ export function parseMarkdown(md: string) {
     gfm: true,
     gfm: true,
   });
   });
 }
 }
+
+/** Returns the content of the changelog markdown file */
+export async function getChangelogMd() {
+  return await (await fetchAdvanced(await getResourceUrl("doc-changelog"))).text();
+}