diff --git a/src/main/Background.ts b/src/main/Background.ts index 0d0e1878..539e31a7 100644 --- a/src/main/Background.ts +++ b/src/main/Background.ts @@ -20,7 +20,6 @@ import { getMainWindow, getMainWindowUATrimmed } from "./Bootstrap"; const LOGIN_START = "https://login.live.com/oauth20_authorize.srf?client_id=00000000402b5328&response_type=code&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf"; let loginWindow: BrowserWindow | null = null; -const logoutWindow: BrowserWindow | null = null; const CODE_REGEX = /(?<=\?code=)[^&]+/gi; const ERROR_REGEX = /(?<=\?error=)[^&]+/gi; const ERROR_DESCRIPTION = /(?<=&error_description=)[^&]+/gi; @@ -45,9 +44,6 @@ export function registerBackgroundListeners(): void { try { loginWindow?.destroy(); } catch {} - try { - logoutWindow?.destroy(); - } catch {} try { getMainWindow()?.destroy(); } catch {} diff --git a/src/modules/auth/Account.ts b/src/modules/auth/Account.ts index 173edc6a..994b5b46 100644 --- a/src/modules/auth/Account.ts +++ b/src/modules/auth/Account.ts @@ -207,8 +207,8 @@ export function updateAccount( base.selectedProfile = status.selectedProfile; base.availableProfiles = status.availableProfiles; if (status.selectedProfile) { - base.lastUsedUUID = status.selectedProfile?.id; - base.lastUsedUsername = status.selectedProfile?.name; + base.lastUsedUUID = status.selectedProfile.id; + base.lastUsedUsername = status.selectedProfile.name; } } } diff --git a/src/modules/auth/AccountUtil.ts b/src/modules/auth/AccountUtil.ts index e6b1d219..875de631 100644 --- a/src/modules/auth/AccountUtil.ts +++ b/src/modules/auth/AccountUtil.ts @@ -4,12 +4,7 @@ import { abortableBasicHash, abortableUniqueHash } from "../commons/BasicHash"; import { Pair, Trio } from "../commons/Collections"; import { ALICORN_ENCRYPTED_DATA_SUFFIX } from "../commons/Constants"; import { isFileExist } from "../commons/FileUtil"; -import { - getActualDataPath, - loadData, - saveData, - saveDataSync, -} from "../config/DataSupport"; +import { getActualDataPath, loadData, saveData } from "../config/DataSupport"; import { decrypt2, decryptByMachine, encrypt2 } from "../security/Encrypt"; import { skinTypeFor } from "../skin/LocalYggdrasilServer"; import { Account } from "./Account"; diff --git a/src/modules/auth/MicrosoftAccount.ts b/src/modules/auth/MicrosoftAccount.ts index 4a148ff5..a94d8c69 100644 --- a/src/modules/auth/MicrosoftAccount.ts +++ b/src/modules/auth/MicrosoftAccount.ts @@ -259,14 +259,13 @@ async function tokenRequest( const refreshToken = String(safeGet(ret, ["refresh_token"], "")); // @ts-ignore const expires = parseInt(safeGet(ret, ["expires_in"], null)); - if (typeof expires === "number") { - if (!isNaN(expires)) { - localStorage.setItem( - ACCOUNT_EXPIRES_KEY, - (expires - 3600).toString() // SAFE - ); - } + if (!isNaN(expires)) { + localStorage.setItem( + ACCOUNT_EXPIRES_KEY, + (expires - 3600).toString() // SAFE + ); } + if (isNull(accessToken) || isNull(refreshToken)) { return { success: false }; } diff --git a/src/modules/config/ConfigSupport.ts b/src/modules/config/ConfigSupport.ts index 144649aa..71f306e6 100644 --- a/src/modules/config/ConfigSupport.ts +++ b/src/modules/config/ConfigSupport.ts @@ -46,7 +46,7 @@ export function getString(key: string, def = "", nonEmpty = false): string { return val; } } - if (typeof val === "object" && val !== undefined && val !== null) { + if (typeof val === "object" && val !== null) { return val.toString(); } return String(val) || def; diff --git a/src/modules/container/ContainerUtil.ts b/src/modules/container/ContainerUtil.ts index 179aba40..ac2da4ed 100644 --- a/src/modules/container/ContainerUtil.ts +++ b/src/modules/container/ContainerUtil.ts @@ -1,10 +1,7 @@ import { schedulePromiseTask } from "../../renderer/Schedule"; -import { randsl } from "../../renderer/Translator"; import { ALICORN_DATA_SUFFIX } from "../commons/Constants"; -import { isFileExist } from "../commons/FileUtil"; import { buildMap, parseMap } from "../commons/MapUtil"; import { loadData, saveData, saveDataSync } from "../config/DataSupport"; -import { createNewContainer } from "./ContainerWrapper"; import { MinecraftContainer } from "./MinecraftContainer"; let GlobalContainerDescriptorTable: Map = new Map(); diff --git a/src/modules/crhelper/CrashLoader.ts b/src/modules/crhelper/CrashLoader.ts index ccfe2f9e..ab1272ea 100644 --- a/src/modules/crhelper/CrashLoader.ts +++ b/src/modules/crhelper/CrashLoader.ts @@ -102,7 +102,6 @@ export async function analyzeCrashReport( loader = CMC_CRASH_LOADER ): Promise> { try { - let f: string; const c = new CrashReportCursor(crashReport); while (c.getLine() !== undefined) { diff --git a/src/modules/cutie/BootEdge.ts b/src/modules/cutie/BootEdge.ts index f27dd25d..068a7ee3 100644 --- a/src/modules/cutie/BootEdge.ts +++ b/src/modules/cutie/BootEdge.ts @@ -123,10 +123,11 @@ function waitUNIXEdgeBoot( // eslint-disable-next-line @typescript-eslint/no-explicit-any const fun = (d: any) => { if (!resolved) { + resolved = true; if (d.toString().toLowerCase().includes("error")) { rej("Elevate cancelled by user"); + return; } - resolved = true; res(); } }; diff --git a/src/modules/java/WhereJava.ts b/src/modules/java/WhereJava.ts index ea4f9c4c..0bf5ba94 100644 --- a/src/modules/java/WhereJava.ts +++ b/src/modules/java/WhereJava.ts @@ -19,7 +19,7 @@ export async function whereJava( all.push(findJavaInPATH()); if (justExist && all.length > 0) { const p = await chkJava(all); - if (justExist && p.length > 0) { + if (p.length > 0) { return p; } } diff --git a/src/modules/launch/LaunchTracker.ts b/src/modules/launch/LaunchTracker.ts index 3e296202..192c37c0 100644 --- a/src/modules/launch/LaunchTracker.ts +++ b/src/modules/launch/LaunchTracker.ts @@ -1,5 +1,3 @@ -import { ProfileType } from "../profile/WhatProfile"; - export class LaunchTracker { javaReport: JavaReport = { runtime: "", version: 0 }; libraryReport: FileOperateReport = { diff --git a/src/modules/modx/ModDynLoad.ts b/src/modules/modx/ModDynLoad.ts index 875116dd..86c14a9c 100644 --- a/src/modules/modx/ModDynLoad.ts +++ b/src/modules/modx/ModDynLoad.ts @@ -2,8 +2,8 @@ import fs from "fs-extra"; import path from "path"; import { getBoolean } from "../config/ConfigSupport"; import { MinecraftContainer } from "../container/MinecraftContainer"; -import { JAR_SUFFIX } from "../launch/NativesLint"; import { FileOperateReport, LaunchTracker } from "../launch/LaunchTracker"; +import { JAR_SUFFIX } from "../launch/NativesLint"; import { GameProfile } from "../profile/GameProfile"; import { ProfileType } from "../profile/WhatProfile"; import { loadModInfo, ModInfo, ModLoader } from "./ModInfo"; @@ -61,7 +61,7 @@ async function moveModsTo( mi.loader === ModLoader.UNKNOWN ) { tFile.operateRecord.push({ - file: `${mi.displayName} (${mi.fileName})` || "", + file: `${mi.displayName} (${mi.fileName})`, operation: "SKIPPED", }); continue; @@ -78,7 +78,7 @@ async function moveModsTo( toProcess.push(mi); } else { tFile.operateRecord.push({ - file: `${mi.displayName} (${mi.fileName})` || "", + file: `${mi.displayName} (${mi.fileName})`, operation: "SKIPPED", }); } @@ -101,12 +101,12 @@ async function moveModsTo( if (e) { tFile.resolved--; tFile.operateRecord.push({ - file: `${mi.displayName} (${mi.fileName})` || "", + file: `${mi.displayName} (${mi.fileName})`, operation: "FAILED", }); } else { tFile.operateRecord.push({ - file: `${mi.displayName} (${mi.fileName})` || "", + file: `${mi.displayName} (${mi.fileName})`, operation: "OPERATED", }); } @@ -114,7 +114,7 @@ async function moveModsTo( }); } else { tFile.operateRecord.push({ - file: `${mi.displayName} (${mi.fileName})` || "", + file: `${mi.displayName} (${mi.fileName})`, operation: "FAILED", }); tFile.resolved--; diff --git a/src/modules/pff/get/FabricGet.ts b/src/modules/pff/get/FabricGet.ts index 977b3d58..eadacf6e 100644 --- a/src/modules/pff/get/FabricGet.ts +++ b/src/modules/pff/get/FabricGet.ts @@ -50,7 +50,7 @@ async function _getLatestFabricInstallerAndLoader( // @ts-ignore window[FABRIC_INSTALLER_MANIFEST_CACHE_KEY] !== undefined && // @ts-ignore - Object.keys(window[FABRIC_INSTALLER_MANIFEST_CACHE_KEY].length > 0) + Object.keys(window[FABRIC_INSTALLER_MANIFEST_CACHE_KEY]).length > 0 ) { // @ts-ignore jInstaller = window[FABRIC_INSTALLER_MANIFEST_CACHE_KEY]; @@ -88,7 +88,7 @@ async function _getLatestFabricInstallerAndLoader( // @ts-ignore window[FABRIC_LOADER_MANIFEST_CACHE_KEY] !== undefined && // @ts-ignore - Object.keys(window[FABRIC_LOADER_MANIFEST_CACHE_KEY].length > 0) + Object.keys(window[FABRIC_LOADER_MANIFEST_CACHE_KEY]).length > 0 ) { // @ts-ignore jLoader = window[FABRIC_LOADER_MANIFEST_CACHE_KEY]; diff --git a/src/modules/profile/InheritedProfileAdaptor.ts b/src/modules/profile/InheritedProfileAdaptor.ts index ba99c3e7..54136ae3 100644 --- a/src/modules/profile/InheritedProfileAdaptor.ts +++ b/src/modules/profile/InheritedProfileAdaptor.ts @@ -6,9 +6,7 @@ // You builds FREE software rather than SPONSOR ones, thank you very much! // Anyway, we'll keep on supporting Forge since there are tremendous requirements. import { copy, remove } from "fs-extra"; -import objectHash from "object-hash"; import path from "path"; -import { schedulePromiseTask } from "../../renderer/Schedule"; import { ReleaseType, SPACE } from "../commons/Constants"; import { isFileExistAndNonEmpty } from "../commons/FileUtil"; import { isNull } from "../commons/Null"; diff --git a/src/modules/profile/Meta.ts b/src/modules/profile/Meta.ts index 132fa2c6..c160c990 100644 --- a/src/modules/profile/Meta.ts +++ b/src/modules/profile/Meta.ts @@ -61,25 +61,14 @@ export class ArtifactMeta { if (typeof sz !== "number") { sz = parseInt(String(sz)); } - // Ugh! Just trying to avoid ignoring ts - if (typeof sz === "number") { - if (isNaN(sz)) { - sz = 0; - } - } - if (typeof sz === "number") { - return new ArtifactMeta( - String(obj["url"]), - String(obj["sha1"]), - String(obj["path"] || obj["id"]), - sz - ); + if (isNaN(sz as number)) { + sz = 0; } return new ArtifactMeta( String(obj["url"]), String(obj["sha1"]), String(obj["path"] || obj["id"]), - 0 + sz as number ); } } diff --git a/src/modules/skin/LocalYggdrasilServer.ts b/src/modules/skin/LocalYggdrasilServer.ts index e90a5f46..4c62570a 100644 --- a/src/modules/skin/LocalYggdrasilServer.ts +++ b/src/modules/skin/LocalYggdrasilServer.ts @@ -176,15 +176,13 @@ export function initLocalYggdrasilServer( ) { let uname = ""; let uid = ""; - if (req.url) { - const unameResult = req.url.match(MATCH_USERNAME_REGEX); - if (unameResult) { - uname = unameResult[0] || ""; - } - const uidResult = req.url.match(MATCH_UUID_REGEX); - if (uidResult) { - uid = uidResult[0] || ""; - } + const unameResult = req.url.match(MATCH_USERNAME_REGEX); + if (unameResult) { + uname = unameResult[0] || ""; + } + const uidResult = req.url.match(MATCH_UUID_REGEX); + if (uidResult) { + uid = uidResult[0] || ""; } if (uname) { NAME_MAP_UUID.set( diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index d2f2d179..6e1e1397 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -175,7 +175,7 @@ export function App(): JSX.Element { }; }); useEffect(() => { - window.addEventListener("changePageWarn", (e) => { + const f1 = (e: Event) => { setOpenChangePageWarn(true); const s = safeGet(e, ["detail"], {}); // @ts-ignore @@ -184,20 +184,30 @@ export function App(): JSX.Element { const history = !!s.history; setHaveHistory(history); setJumpPageTarget(target); - }); - window.addEventListener("changePageWarnTitle", (e) => { + }; + window.addEventListener("changePageWarn", f1); + const f = (e: Event) => { setPageTarget(String(safeGet(e, ["detail"], "Welcome"))); - }); + }; + window.addEventListener("changePageWarnTitle", f); + return () => { + window.removeEventListener("changePageWarn", f1); + window.removeEventListener("changePageWarnTitle", f); + }; }, []); useEffect(() => { - document.addEventListener("setPage", (e) => { + const f = (e: Event) => { // @ts-ignore if (window[CHANGE_PAGE_WARN]) { setPageTarget(String(safeGet(e, ["detail"], "Welcome"))); return; } setPage(String(safeGet(e, ["detail"], "Welcome"))); - }); + }; + document.addEventListener("setPage", f); + return () => { + document.removeEventListener("setPage", f); + }; }, []); useEffect(() => { ipcRenderer.once("YouAreGoingToBeKilled", () => { @@ -213,7 +223,7 @@ export function App(): JSX.Element { }; }, []); useEffect(() => { - window.addEventListener("sysError", (e) => { + const f3 = (e: Event) => { setErr(String(safeGet(e, ["detail"], "Unknown Error"))); clearSnacks(); setNoticeOpen(true); @@ -221,22 +231,34 @@ export function App(): JSX.Element { "reportError", String(safeGet(e, ["detail"], "Unknown Error")) ); - }); - window.addEventListener("sysWarn", (e) => { + }; + window.addEventListener("sysError", f3); + const f1 = (e: Event) => { setWarn(String(safeGet(e, ["detail"], "Unknown Warning"))); clearSnacks(); setWarnOpen(true); - }); - window.addEventListener("sysInfo", (e) => { + }; + window.addEventListener("sysWarn", f1); + + const f0 = (e: Event) => { setInfo(String(safeGet(e, ["detail"], ""))); clearSnacks(); setInfoOpen(true); - }); - window.addEventListener("sysSucc", (e) => { + }; + window.addEventListener("sysInfo", f0); + + const f = (e: Event) => { setSucc(String(safeGet(e, ["detail"], ""))); clearSnacks(); setSuccOpen(true); - }); + }; + window.addEventListener("sysSucc", f); + return () => { + window.removeEventListener("sysError", f3); + window.removeEventListener("sysSucc", f); + window.removeEventListener("sysInfo", f0); + window.removeEventListener("sysWarn", f1); + }; }, []); return ( diff --git a/src/renderer/CrashReportDisplay.tsx b/src/renderer/CrashReportDisplay.tsx index 69cbf2c1..69054eaf 100644 --- a/src/renderer/CrashReportDisplay.tsx +++ b/src/renderer/CrashReportDisplay.tsx @@ -69,9 +69,13 @@ export function CrashReportDisplay(): JSX.Element { const [oc, setOC] = useState([]); const [showFullLogsReport, setShowFullLogsReport] = useState(false); useEffect(() => { - window.addEventListener("EnableShowFullLogsReport", () => { + const f = () => { setShowFullLogsReport(true); - }); + }; + window.addEventListener("EnableShowFullLogsReport", f); + return () => { + window.removeEventListener("EnableShowFullLogsReport", f); + }; }, []); const mounted = useRef(false); useEffect(() => { @@ -394,7 +398,7 @@ function Analyze(props: { {cr?.report.map((r) => { if (r.by === undefined || r.reason === undefined) { - return <>; + return ""; } return ( diff --git a/src/renderer/PffFront.tsx b/src/renderer/PffFront.tsx index daf48a6d..9bea168e 100644 --- a/src/renderer/PffFront.tsx +++ b/src/renderer/PffFront.tsx @@ -214,7 +214,7 @@ export function PffFront(): JSX.Element { ) : ( { start(packageName); @@ -373,7 +373,7 @@ export function PffFront(): JSX.Element { "" )} - {allMods?.map((m) => { + {allMods.map((m) => { if (m.displayName && m.fileName) { return ( ({ marginTop: theme.spacing(-2), }, })); - -const useTextStylesLight = makeStyles((theme: AlicornTheme) => ({ - root: {}, - firstText: { - color: theme.palette.secondary.light, - fontSize: "large", - }, - secondText: { - color: theme.palette.secondary.light, - fontSize: sessionStorage.getItem("smallFontSize") || "1rem", - }, - mediumText: { - color: theme.palette.secondary.light, - fontSize: "medium", - }, - link: { - color: theme.palette.primary.light, - fontSize: sessionStorage.getItem("smallFontSize") || "1rem", - }, - thirdText: { - color: theme.palette.primary.light, - fontSize: "medium", - }, -}));