Skip to content

Commit

Permalink
fix(*): code quality
Browse files Browse the repository at this point in the history
Andy-K-Sparklight committed Dec 30, 2021
1 parent 96d4963 commit d550698
Showing 20 changed files with 77 additions and 105 deletions.
4 changes: 0 additions & 4 deletions src/main/Background.ts
Original file line number Diff line number Diff line change
@@ -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 {}
4 changes: 2 additions & 2 deletions src/modules/auth/Account.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
7 changes: 1 addition & 6 deletions src/modules/auth/AccountUtil.ts
Original file line number Diff line number Diff line change
@@ -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";
13 changes: 6 additions & 7 deletions src/modules/auth/MicrosoftAccount.ts
Original file line number Diff line number Diff line change
@@ -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 };
}
2 changes: 1 addition & 1 deletion src/modules/config/ConfigSupport.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 0 additions & 3 deletions src/modules/container/ContainerUtil.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> = new Map();
1 change: 0 additions & 1 deletion src/modules/crhelper/CrashLoader.ts
Original file line number Diff line number Diff line change
@@ -102,7 +102,6 @@ export async function analyzeCrashReport(
loader = CMC_CRASH_LOADER
): Promise<Map<number, { origin: string; report: CrashLoaderReport[] }>> {
try {
let f: string;
const c = new CrashReportCursor(crashReport);

while (c.getLine() !== undefined) {
3 changes: 2 additions & 1 deletion src/modules/cutie/BootEdge.ts
Original file line number Diff line number Diff line change
@@ -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();
}
};
2 changes: 1 addition & 1 deletion src/modules/java/WhereJava.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 0 additions & 2 deletions src/modules/launch/LaunchTracker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ProfileType } from "../profile/WhatProfile";

export class LaunchTracker {
javaReport: JavaReport = { runtime: "", version: 0 };
libraryReport: FileOperateReport = {
12 changes: 6 additions & 6 deletions src/modules/modx/ModDynLoad.ts
Original file line number Diff line number Diff line change
@@ -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,20 +101,20 @@ 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",
});
}
resolve();
});
} else {
tFile.operateRecord.push({
file: `${mi.displayName} (${mi.fileName})` || "",
file: `${mi.displayName} (${mi.fileName})`,
operation: "FAILED",
});
tFile.resolved--;
4 changes: 2 additions & 2 deletions src/modules/pff/get/FabricGet.ts
Original file line number Diff line number Diff line change
@@ -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];
2 changes: 0 additions & 2 deletions src/modules/profile/InheritedProfileAdaptor.ts
Original file line number Diff line number Diff line change
@@ -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";
17 changes: 3 additions & 14 deletions src/modules/profile/Meta.ts
Original file line number Diff line number Diff line change
@@ -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
);
}
}
16 changes: 7 additions & 9 deletions src/modules/skin/LocalYggdrasilServer.ts
Original file line number Diff line number Diff line change
@@ -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(
50 changes: 36 additions & 14 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
@@ -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,30 +223,42 @@ export function App(): JSX.Element {
};
}, []);
useEffect(() => {
window.addEventListener("sysError", (e) => {
const f3 = (e: Event) => {
setErr(String(safeGet(e, ["detail"], "Unknown Error")));
clearSnacks();
setNoticeOpen(true);
ipcRenderer.send(
"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 (
10 changes: 7 additions & 3 deletions src/renderer/CrashReportDisplay.tsx
Original file line number Diff line number Diff line change
@@ -69,9 +69,13 @@ export function CrashReportDisplay(): JSX.Element {
const [oc, setOC] = useState<string[]>([]);
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<boolean>(false);
useEffect(() => {
@@ -394,7 +398,7 @@ function Analyze(props: {
<List>
{cr?.report.map((r) => {
if (r.by === undefined || r.reason === undefined) {
return <></>;
return "";
}
return (
<ListItem key={r.by + r.reason}>
4 changes: 2 additions & 2 deletions src/renderer/PffFront.tsx
Original file line number Diff line number Diff line change
@@ -214,7 +214,7 @@ export function PffFront(): JSX.Element {
<CircularProgress size={"1.5rem"} />
) : (
<IconButton
disabled={isRunning || packageName.trim().length === 0}
disabled={packageName.trim().length === 0}
color={"primary"}
onClick={() => {
start(packageName);
@@ -373,7 +373,7 @@ export function PffFront(): JSX.Element {
""
)}
<List>
{allMods?.map((m) => {
{allMods.map((m) => {
if (m.displayName && m.fileName) {
return (
<SingleModDisplay
2 changes: 1 addition & 1 deletion src/renderer/ReadyToLaunch.tsx
Original file line number Diff line number Diff line change
@@ -1694,7 +1694,7 @@ function getProfileRelatedID(hash: string): string {
return sessionStorage.getItem("MinecraftID" + hash) || "";
}

const CODE_REGEX = /(?<=\?code=)[^&]+/gi;
const CODE_REGEX = /(?<=\?code=)[^&]+/i;

function AskURLDialog(): JSX.Element {
const [url, setUrl] = useState("");
24 changes: 0 additions & 24 deletions src/renderer/Stylex.tsx
Original file line number Diff line number Diff line change
@@ -160,27 +160,3 @@ export const useTextStyles = makeStyles((theme: AlicornTheme) => ({
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",
},
}));

0 comments on commit d550698

Please sign in to comment.