Skip to content

Commit

Permalink
fix: error code 1 when launching an instance (#1420)
Browse files Browse the repository at this point in the history
* fix: add required java args if missing

* fix: replace required args if not missing

* fix
  • Loading branch information
Ladvace authored Aug 8, 2022
1 parent 391dd9c commit cdae501
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 289 deletions.
47 changes: 28 additions & 19 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,6 @@ const userAgent = new UserAgent({
// app.allowRendererProcessReuse = true;
Menu.setApplicationMenu(Menu.buildFromTemplate(edit));

let oldLauncherUserData = path.join(app.getPath('userData'), 'instances');

// Read config and eventually use new path
try {
const configFile = fss.readFileSync(
path.join(app.getPath('userData'), 'config.json')
);
const config = JSON.parse(configFile);
if (config.settings.instancesPath) {
oldLauncherUserData = config.settings.instancesPath;
}
} catch {
// Do nothing
}

app.setPath('userData', path.join(app.getPath('appData'), 'gdlauncher_next'));

let allowUnstableReleases = false;
Expand Down Expand Up @@ -219,6 +204,34 @@ if (
}
}

// Read config and eventually use new path
try {
const configPath = path.join(app.getPath('userData'), 'config.json');
const configFile = fss.readFileSync(configPath);
const config = JSON.parse(configFile);

const requiredArgs = [
'-Dfml.ignorePatchDiscrepancies=true',
'-Dfml.ignoreInvalidMinecraftCertificates=true'
];

const javaArgs = config.settings.java.args;

if (config.settings.java.args) {
const cleanedJavaArgs = javaArgs
.split(' ')
.filter(arg => !requiredArgs.includes(arg))
.join(' ');

if (cleanedJavaArgs.split(' ').length !== javaArgs.split(' ').length) {
config.settings.java.args = cleanedJavaArgs;
fss.writeFileSync(configPath, JSON.stringify(config));
}
}
} catch {
// Do nothing
}

log.log(process.env.REACT_APP_RELEASE_TYPE, app.getVersion());

const get7zPath = async () => {
Expand Down Expand Up @@ -553,10 +566,6 @@ ipcMain.handle('getSentryDsn', () => {
return process.env.SENTRY_DSN;
});

ipcMain.handle('getOldLauncherUserData', () => {
return oldLauncherUserData;
});

ipcMain.handle('getExecutablePath', () => {
return path.dirname(app.getPath('exe'));
});
Expand Down
4 changes: 3 additions & 1 deletion src/app/desktop/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export const LINUX = 'linux';
export const DARWIN = 'darwin';
export const DESKTOP_PATH = path.join(homedir(), 'Desktop');
export const CLASSPATH_DIVIDER_CHAR = platform() === WINDOWS ? ';' : ':';
export const DEFAULT_JAVA_ARGS = `-Dfml.ignorePatchDiscrepancies=true -Dfml.ignoreInvalidMinecraftCertificates=true ${
export const DEFAULT_JAVA_ARGS = `${
platform() === WINDOWS
? '-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump'
: ''
} -Xms256m`;
export const REQUIRED_JAVA_ARGS =
'-Dfml.ignorePatchDiscrepancies=true -Dfml.ignoreInvalidMinecraftCertificates=true';
export const DEFAULT_MEMORY = 4096;

export const resolutionPresets = [
Expand Down
12 changes: 9 additions & 3 deletions src/app/desktop/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { getAddon, getAddonFile, mcGetPlayerSkin } from '../../../common/api';
import { downloadFile } from './downloader';
import browserDownload from '../../../common/utils/browserDownload';
import { REQUIRED_JAVA_ARGS } from './constants';

export const isDirectory = source =>
fs.lstat(source).then(r => r.isDirectory());
Expand Down Expand Up @@ -495,14 +496,17 @@ export const getJVMArguments112 = (
.join(process.platform === 'win32' ? ';' : ':')
);

const javaArgs = jvmOptions.filter(Boolean);

// if (process.platform === "darwin") {
// args.push("-Xdock:name=instancename");
// args.push("-Xdock:icon=instanceicon");
// }

args.push(`-Xmx${memory}m`);
args.push(`-Xms${memory}m`);
args.push(...jvmOptions);
args.push(...REQUIRED_JAVA_ARGS.split(' '));
if (javaArgs.length > 0) args.push(...javaArgs);
args.push(
`-Djava.library.path=${addQuotes(
needsQuote,
Expand Down Expand Up @@ -600,11 +604,11 @@ export const getJVMArguments113 = (
let args = mcJson.arguments.jvm.filter(v => !skipLibrary(v));
const needsQuote = process.platform !== 'win32';

const javaArgs = jvmOptions.filter(Boolean);
// if (process.platform === "darwin") {
// args.push("-Xdock:name=instancename");
// args.push("-Xdock:icon=instanceicon");
// }

args.push(`-Xmx${memory}m`);
args.push(`-Xms${memory}m`);
args.push(
Expand All @@ -613,7 +617,9 @@ export const getJVMArguments113 = (
if (mcJson.logging) {
args.push(mcJson?.logging?.client?.argument || '');
}
args.push(...jvmOptions);

args.push(...REQUIRED_JAVA_ARGS.split(' '));
if (javaArgs.length > 0) args.push(...javaArgs);

// Eventually inject additional arguments (from 1.17 (?))
if (mcJson?.forge?.arguments?.jvm) {
Expand Down
3 changes: 0 additions & 3 deletions src/common/components/ModalsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ const modalsComponentLookupTable = {
lazy(() => import('../modals/InstanceCrashed'))
),
ChangeLogs: AsyncComponent(lazy(() => import('../modals/ChangeLogs'))),
InstancesMigration: AsyncComponent(
lazy(() => import('../modals/InstancesMigration'))
),
McVersionChanger: AsyncComponent(
lazy(() => import('../modals/McVersionChanger'))
),
Expand Down
Loading

0 comments on commit cdae501

Please sign in to comment.