Skip to content

Commit

Permalink
feat: enhance profile & account
Browse files Browse the repository at this point in the history
  • Loading branch information
ResetPower committed Aug 16, 2021
1 parent 228af67 commit 1bc8b1b
Show file tree
Hide file tree
Showing 29 changed files with 368 additions and 166 deletions.
24 changes: 16 additions & 8 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
## New Features 🚀🚀🚀

- Fixed a bunch of bugs 😢
- Fixed the problem that there is a certain chance of JVM crash when starting the Mod version under macOS
- Fixed the issue of UI freeze on the download page
- There is still a bunch of bugs 🤮
- Added useless "Developer Mode" (preparing for the arrival of the extensions)
- Too many to describe
- Enhanced skin management
- The new file is filled with Minecraft official JVM optimization parameters by default
- Support displaying "Epherome" in the lower left corner of the Minecraft page
- Adjusted some things you won't notice

## Notice

-The next version will definitely be downloaded by Forge/Fabric/LiteLoader/Optifine! ! !

## 新特性 🚀🚀🚀

- 修复了一坨 Bug 😢
- 修复了在 macOS 下启动 Mod 版本有一定几率 JVM 参数失调的问题
- 修复了下载页面 UI 卡顿的问题
- 还有一坨 Bug 🤮
- 增加了没用的「开发者模式」(为扩展系统的到来做准备)
- 多到无法描述
- 增强了皮肤管理功能
- 对新档案默认填充了 Minecraft 官方的 JVM 优化参数
- 支持在 Minecraft 页面左下角展示「Epherome」
- 调整了一些你不会注意到的东西

## 注意

- 下个版本一定会有 Forge/Fabric/LiteLoader/Optifine 下载的!!!
58 changes: 50 additions & 8 deletions src/components/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ReactNode } from "react";
import { t } from "../intl";
import { showOverlay } from "../renderer/overlays";
import { DefaultFn, unwrapFunction } from "../tools";
import { Button } from "./inputs";
import { Button, Link } from "./inputs";

export default function Dialog(props: {
children: ReactNode;
Expand All @@ -21,17 +22,17 @@ export default function Dialog(props: {

export function AlertDialog(props: {
title: string;
message: string;
message: ReactNode;
anyway?: string;
onAnyway?: DefaultFn;
close: DefaultFn;
}): JSX.Element {
return (
<Dialog indentBottom>
<p className="text-xl font-semibold">{props.title}</p>
{props.message.split("\n").map((val) => (
<p>{val}</p>
))}
{typeof props.message === "string"
? props.message.split("\n").map((val) => <p>{val}</p>)
: props.message}
<div className="flex">
{props.anyway && (
<Button
Expand All @@ -54,7 +55,7 @@ export function AlertDialog(props: {

export function ConfirmDialog(props: {
title: string;
message: string;
message: ReactNode;
action: DefaultFn;
close: DefaultFn;
positiveClassName?: string;
Expand Down Expand Up @@ -82,15 +83,56 @@ export function ConfirmDialog(props: {
);
}

export function ExportedDialog(props: {
target: string;
close: DefaultFn;
}): JSX.Element {
return (
<AlertDialog
title={t("tip")}
message={
<>
{t("exportedAt")}
<br />
<Link href={props.target} type="file">
{props.target}
</Link>
</>
}
close={props.close}
/>
);
}

export function ErrorDialog(props: {
stacktrace: string;
onClose: DefaultFn;
close: DefaultFn;
}): JSX.Element {
return (
<AlertDialog
title={t("errorOccurred")}
message={props.stacktrace}
close={props.onClose}
close={props.close}
/>
);
}

export const showInternetNotAvailableDialog = (): void => {
showOverlay((close) => (
<AlertDialog
title={t("tip")}
message={t("internetNotAvailable")}
close={close}
/>
));
};

export const showNotSupportedDialog = (): void => {
showOverlay((close) => (
<AlertDialog
title={t("tip")}
message={t("notSupportedYet")}
close={close}
/>
));
};
25 changes: 25 additions & 0 deletions src/components/Image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useState } from "react";
import { DefaultFn, LoadingStatus, unwrapFunction } from "../tools";

export default function Image(props: {
src: string;
className?: string;
rounded?: boolean;
onError?: DefaultFn;
}): JSX.Element {
const [status, setStatus] = useState<LoadingStatus>("pending");

return (
<img
className={`${props.className ?? ""} ${
props.rounded ? "rounded-lg" : ""
} ${status !== "done" ? "invisible" : ""}`}
src={props.src}
onLoad={() => setStatus("done")}
onError={() => {
setStatus("error");
unwrapFunction(props.onError)();
}}
/>
);
}
11 changes: 7 additions & 4 deletions src/components/Spin.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export default function Spin(props: { className?: string }): JSX.Element {
export default function Spin(props: {
className?: string;
indent?: boolean;
}): JSX.Element {
return (
<svg
className={`animate-spin -ml-1 m-3 h-5 w-5 text-gray-700 dark:text-white ${
props.className ?? ""
}`}
className={`animate-spin ${
props.indent ? "" : "m-3"
} h-5 w-5 text-gray-700 dark:text-white ${props.className ?? ""}`}
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
Expand Down
11 changes: 11 additions & 0 deletions src/components/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function TextField(props: {
maxLength?: number;
noSpinButton?: boolean;
required?: boolean;
onEnter?: DefaultFn;
}): JSX.Element {
return (
<div className={props.className}>
Expand All @@ -123,12 +124,22 @@ export function TextField(props: {
<div className={`flex ${props.fieldClassName ?? ""}`}>
{props.icon && <div className="eph-textfield-icon">{props.icon}</div>}
<input
spellCheck="false"
maxLength={props.maxLength}
min={props.min}
max={props.max}
type={props.type}
value={props.value}
placeholder={props.placeholder}
onKeyDown={
props.onEnter
? (event) => {
if (event.key === "Enter") {
unwrapFunction(props.onEnter)();
}
}
: undefined
}
onChange={(ev) => unwrapFunction(props.onChange)(ev.target.value)}
className={`${
props.icon && props.trailing
Expand Down
8 changes: 5 additions & 3 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isCompliant, osName } from "./rules";
import { unzipNatives } from "./unzip";
import { runMinecraft } from "./runner";
import { createDirIfNotExist, downloadFile } from "../models/files";
import { DefaultFn } from "../tools";
import { adapt, DefaultFn } from "../tools";
import {
isJava16Required,
isJava8Required,
Expand Down Expand Up @@ -218,7 +218,9 @@ export async function launchMinecraft(
auth_access_token: account.token,
user_type: "mojang",
user_properties: `{}`,
version_type: parsed.type,
version_type: adapt([undefined, true], profile.showEpherome)
? "Epherome"
: parsed.type,
// jvm args
natives_directory: nativeDir,
launcher_name: "Epherome",
Expand Down Expand Up @@ -260,6 +262,7 @@ export async function launchMinecraft(
};

// jvm arguments
profile.jvmArgs && buff.push(...profile.jvmArgs.split(" "));
if (parsed.arguments && parsed.arguments.jvm) {
resolveMinecraftArgs(parsed.arguments.jvm);
} else {
Expand All @@ -275,7 +278,6 @@ export async function launchMinecraft(
argumentsMap.classpath
);
}
profile.jvmArgs && buff.push(profile.jvmArgs);
buff.push(parsed["mainClass"]);

// game arguments
Expand Down
3 changes: 0 additions & 3 deletions src/core/libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ export async function analyzeAssets(
await downloadFile(
MinecraftUrlUtils.assetIndex(assetIndex),
assetIndexPath,
(error) => {
throw error;
},
cancellerWrapper
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/craft/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export async function downloadMinecraft(
await downloadFile(
MinecraftUrlUtils.clientJson(version),
jsonPath,
onError,
cancellerWrapper
);
).catch(onError);

// read content from json file
const data = fs.readFileSync(jsonPath).toString();
Expand Down
49 changes: 49 additions & 0 deletions src/craft/jvm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { spawnSync } from "child_process";
import findJavaHome from "find-java-home";
import { nanoid } from "nanoid";
import path from "path";
import { Java } from "../struct/java";

export function defaultJvmArgs(): string {
return "-Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M";
}

export function checkJavaVersion(dir: string): Promise<Java | null> {
return new Promise((resolve) => {
try {
const proc = spawnSync(dir, ["-version"]);
if (proc.error) {
resolve(null);
} else {
const data = proc.stderr.toString();
const name = data.match(/"(.*?)"/)?.pop();
if (name) {
resolve({
nanoid: nanoid(),
dir,
name,
is64Bit: data.toLowerCase().includes("64-bit"),
});
} else {
resolve(null);
}
}
} catch {
resolve(null);
}
});
}

export function detectJava(): Promise<Java | null> {
return new Promise((resolve, reject) =>
findJavaHome((err, res) => {
if (err) {
resolve(null);
} else {
checkJavaVersion(path.join(res, "bin", "java"))
.then(resolve)
.catch(reject);
}
})
);
}
34 changes: 34 additions & 0 deletions src/craft/skin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import path from "path";
import Image from "../components/Image";
import { downloadFile } from "../models/files";
import { userDataPath } from "../struct/config";

export const steveId = "MHF_Steve";
export const alexId = "MHF_Alex";

export function Avatar(props: { uuid: string }): JSX.Element {
return (
<Image
src={`https://mc-heads.net/avatar/${props.uuid}`}
className="w-7 h-7"
rounded
/>
);
}

export function Body(props: { uuid: string }): JSX.Element {
return (
<Image
className="w-40"
src={`https://mc-heads.net/body/${props.uuid}`}
rounded
/>
);
}

export async function downloadSkin(uuid: string): Promise<string> {
const skinsDir = path.join(userDataPath, "skins");
const target = path.join(skinsDir, `${uuid}.png`);
await downloadFile(`https://mc-heads.net/download/${uuid}`, target);
return target;
}
5 changes: 5 additions & 0 deletions src/intl/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface LanguageDefinition {
expand: string;
useDefault: string;
haveNot: string;
export: string;
"account.mojang": string;
"account.microsoft": string;
"account.authlib": string;
Expand All @@ -65,6 +66,9 @@ export interface LanguageDefinition {
"profile.enable": string;
"profile.import": string;
"profile.gameDirIsolation": string;
"profile.showEpherome": string;
"profile.gameDirIsolation.description": string;
"profile.showEpherome.description": string;
"settings.epheromePath": string;
"settings.officialSite": string;
"settings.openSourceSoftware": string;
Expand Down Expand Up @@ -124,4 +128,5 @@ export interface LanguageDefinition {
continueAnyway: string;
moveToTrash: string;
confirmMoveSomethingToTrash: string;
exportedAt: string;
}
Loading

0 comments on commit 1bc8b1b

Please sign in to comment.