Skip to content

Commit

Permalink
added a check for java and an error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Davis-Software committed Oct 19, 2022
1 parent 420f6f8 commit 1bf2480
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
10 changes: 8 additions & 2 deletions back/electron-tools.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { BrowserWindow } = require("electron")
const { BrowserWindow, dialog } = require("electron")


function getMainWindow(){
Expand All @@ -12,6 +12,12 @@ function getMainWindow(){
}


function errorWindow(title, message){
dialog.showErrorBox(title, message)
}


module.exports = {
getMainWindow
getMainWindow,
errorWindow
}
15 changes: 14 additions & 1 deletion back/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@ const fs = require("fs")
const path = require("path")
const {appDataDir} = require("./config")
const {findJava} = require("./utils");
const {errorWindow} = require("./electron-tools");

const javaPath = findJava()
if(javaPath === null){
errorWindow(
"Java not found",
"No Java installation was found on your system.\n" +
"Please install at least one Java version and try again.\n\n" +
"If you have already installed Java, please make sure that it is in your PATH environment variable.\n\n" +
"Java can be downloaded from https://java.com/download"
)
process.exit(1)
}

class Settings {
constructor(){
this.settings = {
credentials: null,
ram: 1024,
mcPath: path.join(appDataDir, "..", ".minecraft_swc"),
javaPath: findJava(),
javaPath: javaPath,
"splash-width": "1280",
"splash-height": "720",
"launch-args": ""
Expand Down
12 changes: 8 additions & 4 deletions back/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ registerIpcListener("get-ram-amount", () => {


function findJava() {
if(platform === "win32"){
return child_process.execSync("where java.exe").toString().split("\r\n")[0]
}else{
return child_process.execSync("which java").toString().split("\n")[0]
try{
if(platform === "win32"){
return child_process.execSync("where java.exe").toString().split("\r\n")[0]
}else{
return child_process.execSync("which java").toString().split("\n")[0]
}
} catch(e){
return null
}
}

Expand Down

0 comments on commit 1bf2480

Please sign in to comment.