Skip to content

Commit

Permalink
* java version dropdown now shows if java install is jre or jdk
Browse files Browse the repository at this point in the history
* bug fixes
* minor visual improvements and optimizations
  • Loading branch information
Davis-Software committed Oct 23, 2022
1 parent 92287f7 commit 7774142
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
9 changes: 6 additions & 3 deletions back/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const os = require("os");
const {registerIpcListener} = require("./ipc-handler");
const {platform} = require("./config");
const childProcess = require("child_process");
const fs = require("fs");
const path = require("path");


registerIpcListener("get-ram-amount", () => {
Expand All @@ -19,9 +21,10 @@ function findJavaPaths() {
paths = childProcess.execSync("which java").toString().trim().split("\n")
}

paths = paths.map(path => ({
path,
version: childProcess.execSync(`"${path}" -version 2>&1`).toString().trim().split('"')[1]
paths = paths.map(jPath => ({
path: jPath,
version: childProcess.execSync(`"${jPath}" -version 2>&1`).toString().trim().split('"')[1],
jdk: fs.existsSync(path.join(path.dirname(jPath), platform !== "win32" ? "javac" : "javac.exe"))
}))

return paths
Expand Down
4 changes: 1 addition & 3 deletions front_src/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ function Sidebar(props: SidebarProps) {
<img src={general.applicationIcon} height={32} width={32} alt="" />
<h6 style={{marginTop: ".7rem", marginLeft: "15px"}}>{general.applicationName}</h6>
</Toolbar>
<List>
<List className="host-candle">
{Object.keys(pageMapping).filter(i => !pageMapping[i].hide).map((key, index) => (
<ListItemButton
disabled={props.disableSidebar}
className="attach-candle"
sx={{
paddingLeft: props.page === key ? "30px" : "16px",
borderLeft: props.page === key ? "4px solid #3f51b5" : "none",
Expand All @@ -60,7 +59,6 @@ function Sidebar(props: SidebarProps) {
{props.modPacks && Object.keys(props.modPacks).map((key, index) => (
<ListItemButton
disabled={props.disableSidebar}
className="attach-candle"
sx={{
paddingLeft: props.page === key ? "30px" : "16px",
borderLeft: props.page === key ? "4px solid #3f51b5" : "none",
Expand Down
2 changes: 2 additions & 0 deletions front_src/src/pages/PageBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ function PageBase(props: PageBaseProps) {
style={{
width: "100%",
height: "100%",
overflowY: "auto",
overflowX: "hidden",
...bgOptions
}}
>
Expand Down
27 changes: 19 additions & 8 deletions front_src/src/pages/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface SettingsInputProps {
type: "text" | "number" | "path" | "file" | "dropdown-file"
value: string | number
onChange: (value: string | number | null) => void
debugMode?: boolean
}
function SettingsInput(props: SettingsInputProps){
const id = `settings-input-${props.name.replace(/ /, "_").toLowerCase()}`
Expand Down Expand Up @@ -63,7 +64,7 @@ function SettingsInput(props: SettingsInputProps){
/>
)
case "dropdown-file":
const [javaPaths, setJavaPaths] = React.useState<{path: string, version: string}[]>([])
const [javaPaths, setJavaPaths] = React.useState<{path: string, version: string, jdk: boolean}[]>([])
const [javaPathsItems, setJavaPathsItems] = React.useState<React.ReactNode[]>([])

function handleClick(e: React.MouseEvent<HTMLLIElement>){
Expand All @@ -80,19 +81,29 @@ function SettingsInput(props: SettingsInputProps){
}, [])
useEffect(() => {
let paths = javaPaths.map((path, index) => (
<MenuItem key={index} value={path.path}>{path.version} {path.path.includes("jdk") ? "(JDK)" : <></>}</MenuItem>
<MenuItem key={index} value={path.path}>
{path.version}
<span
className={path.jdk? "text-warning": "text-success"}
style={{position: "absolute", right: "25px"}}
>
{path.jdk ? "JDK" : "JRE"}
</span>
</MenuItem>
))
paths.push(<MenuItem key={paths.length} value="custom" onClick={handleClick}>Custom (Buggy)</MenuItem>)
if(props.debugMode){
paths.push(<MenuItem key={paths.length} value="custom" onClick={handleClick}>Custom (Buggy)</MenuItem>)
}
setJavaPathsItems(paths)
}, [javaPaths])
}, [javaPaths, props.debugMode])

return (
<TextField
sx={{width: "100%"}}
variant="standard"
aria-labelledby={id}
type="text"
value={props.value}
value={javaPathsItems && javaPathsItems.length > 0 ? props.value : ""}
onChange={(e) => props.onChange(e.target.value)}
select
>
Expand Down Expand Up @@ -266,7 +277,7 @@ function Settings(){
<tbody>
<tr>
<SettingsInput name="Minecraft Path" type="path" value={mcPath!} onChange={(v) => setMcPath(v as string)} />
<SettingsInput name="Java Installation" type="dropdown-file" value={javaPath!} onChange={(v) => setJavaPath(v as string)} />
<SettingsInput name="Java Installation" type="dropdown-file" debugMode={debugLogging} value={javaPath!} onChange={(v) => setJavaPath(v as string)} />
</tr>
<tr>
<SettingsInput name="SplashScreen Width" type="number" value={width} onChange={(v) => setWidth(v as number)} />
Expand All @@ -290,12 +301,12 @@ function Settings(){
<table className="table table-borderless mt-3 mb-3">
<tbody>
<tr>
<SettingsInput name="Java Launch Arguments" type="text" value={launchArgs} onChange={(v) => setLaunchArgs(v as string)} />
<SettingsInput name="Java Launch Arguments" type="text" value={launchArgs ? launchArgs : ""} onChange={(v) => setLaunchArgs(v as string)} />
</tr>
</tbody>
</table>

<SettingsCheckbox name="Debug logging" value={debugLogging} onChange={setDebugLogging} />
<SettingsCheckbox name="Debug Mode" value={debugLogging} onChange={setDebugLogging} />
</div>
</PageBase>
)
Expand Down
20 changes: 20 additions & 0 deletions static/js/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@
}


function hostCandleOnChildren(elem, size=1){
elem.classList.add("candle-host")

elem.childNodes.forEach(child => {
if(child.nodeType === 1) {
attachCandle(child, size)
}
})
}


function addListeners(list, callback, className){
list = Array.from(list).map(selector => selector + `:not(.${className})`)
if(list.join(", ") === "") return
Expand All @@ -94,14 +105,23 @@
".attach-candle"
], attachCandle, "candle-attached")
}
function addCandleHosts(){
addListeners([
".host-candle"
], hostCandleOnChildren, "candle-host")
}

addRipples()
addCandles()
addCandleHosts()
setInterval(addRipples, 1000)
setInterval(addCandles, 1000)
setInterval(addCandleHosts, 1000)
document.addEventListener("click", addListeners)
document.addEventListener("click", addCandles)
document.addEventListener("click", addCandleHosts)

namespaces.createRipple = createRipple
namespaces.attachCandle = attachCandle
namespaces.hostCandleOnChildren = hostCandleOnChildren
})()

0 comments on commit 7774142

Please sign in to comment.