Skip to content

Commit 377a9ab

Browse files
Merge pull request #8 from StoppedwummPython:gui-preview
Implement UI for console and mod dashboard with testing enhancements
2 parents f023dc7 + 6494a36 commit 377a9ab

File tree

15 files changed

+2392
-268
lines changed

15 files changed

+2392
-268
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ config.json
88
java-runtime
99
.DS_Store
1010
dist
11-
build
11+
build
12+
__pycache__
13+
test.txt
14+
coverage

1.21.1.json

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -49,62 +49,6 @@
4949
"--height",
5050
"${resolution_height}"
5151
]
52-
},
53-
{
54-
"rules": [
55-
{
56-
"action": "allow",
57-
"features": {
58-
"has_quick_plays_support": true
59-
}
60-
}
61-
],
62-
"value": [
63-
"--quickPlayPath",
64-
"${quickPlayPath}"
65-
]
66-
},
67-
{
68-
"rules": [
69-
{
70-
"action": "allow",
71-
"features": {
72-
"is_quick_play_singleplayer": true
73-
}
74-
}
75-
],
76-
"value": [
77-
"--quickPlaySingleplayer",
78-
"${quickPlaySingleplayer}"
79-
]
80-
},
81-
{
82-
"rules": [
83-
{
84-
"action": "allow",
85-
"features": {
86-
"is_quick_play_multiplayer": true
87-
}
88-
}
89-
],
90-
"value": [
91-
"--quickPlayMultiplayer",
92-
"${quickPlayMultiplayer}"
93-
]
94-
},
95-
{
96-
"rules": [
97-
{
98-
"action": "allow",
99-
"features": {
100-
"is_quick_play_realms": true
101-
}
102-
}
103-
],
104-
"value": [
105-
"--quickPlayRealms",
106-
"${quickPlayRealms}"
107-
]
10852
}
10953
],
11054
"jvm": [

api.test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// windows only test
2+
import index from "./index.js"
3+
import * as java from "./java.js"
4+
import { describe, it, expect } from "vitest"
5+
import fs from "fs/promises"
6+
7+
describe("API exists", () => {
8+
it("Should be defined", () => {
9+
expect(index).toBeDefined()
10+
})
11+
})
12+
13+
describe("API methods", () => {
14+
it("Can get OS name", () => {
15+
expect(index.getOSName()).toBeDefined()
16+
expect(index.getOSName()).eq("windows")
17+
})
18+
it("Can check rules", () => {
19+
expect(index.checkRule({
20+
"action": "allow",
21+
"os": {
22+
"name": "osx"
23+
}
24+
})).eq(false)
25+
expect(index.checkRule({
26+
"action": "allow",
27+
"os": {
28+
"name": "linux"
29+
}
30+
})).eq(false)
31+
expect(index.checkRule({
32+
"action": "allow",
33+
"os": {
34+
"name": "windows"
35+
}
36+
})).eq(true)
37+
})
38+
})
39+
40+
describe("Java API", () => {
41+
it("Should be defined", () => {
42+
expect(java.downloadJava).toBeDefined()
43+
expect(java.downloadJava).toBeTypeOf("function")
44+
})
45+
})
46+
47+
describe("Can handle manifest", () => {
48+
it("Should be defined", async () => {
49+
expect(await index.loadManifest("neoforge-21.1.162.json")).toBeDefined()
50+
})
51+
it("Should merge Manifests", async () => {
52+
expect(await index.mergeManifests(await index.loadManifest("neoforge-21.1.162.json"), await index.loadManifest("1.21.1.json"))).toBeDefined()
53+
expect(await index.mergeManifests(await index.loadManifest("neoforge-21.1.162.json"), await index.loadManifest("1.21.1.json"))).toBeTypeOf("object")
54+
})
55+
})
56+
57+
describe("Misc functions", () => {
58+
it("Should be defined", async () => {
59+
expect(index.downloadFile).toBeDefined()
60+
})
61+
it("Should download file", async () => {
62+
await fs.rm("test.txt", { force: true })
63+
const download = await index.downloadFile("https://sample-files.com/downloads/documents/txt/simple.txt", "test.txt")
64+
expect(download).toBeDefined()
65+
expect(download).toBeTypeOf("boolean")
66+
expect(download).eq(true)
67+
})
68+
})

index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ async function main() {
812812
});
813813
})
814814
// removing old backup
815-
await fs.rmdir(BACKUP_PATH, { recursive: true, force: true });
815+
await fs.rm(BACKUP_PATH, { recursive: true, force: true });
816816

817817
} catch (error) {
818818
console.error(`Failed to create backup: ${error}`);
@@ -822,9 +822,25 @@ async function main() {
822822

823823

824824
} // End of main function
825+
// --ui adds fix to the launcher (when the ui launches, it returns ui_index.cjs as the entry point script, which will trigger module logic, which is now fixed)
826+
const entryPointScript = process.argv[1].split(path.sep).pop();
827+
if (entryPointScript === __filename || entryPointScript === __dirname.split(path.sep).pop() || (process.argv.length == 3 && process.argv[2] == "--ui")) {
828+
main().catch(error => {
829+
console.error("\n--- An error occurred during setup or launch ---");
830+
console.error(error);
831+
process.exit(1);
832+
});
833+
}
825834

826-
main().catch(error => {
827-
console.error("\n--- An error occurred during setup or launch ---");
828-
console.error(error);
829-
process.exit(1);
830-
});
835+
export default {
836+
downloadFile,
837+
extractNatives,
838+
getOSName,
839+
getArchName,
840+
checkRule,
841+
checkItemRules,
842+
ensureLauncherProfiles,
843+
loadManifest,
844+
mergeManifests,
845+
main
846+
}

0 commit comments

Comments
 (0)