Skip to content

Commit cdae501

Browse files
authored
fix: error code 1 when launching an instance (#1420)
* fix: add required java args if missing * fix: replace required args if not missing * fix
1 parent 391dd9c commit cdae501

File tree

5 files changed

+40
-289
lines changed

5 files changed

+40
-289
lines changed

public/electron.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,6 @@ const userAgent = new UserAgent({
168168
// app.allowRendererProcessReuse = true;
169169
Menu.setApplicationMenu(Menu.buildFromTemplate(edit));
170170

171-
let oldLauncherUserData = path.join(app.getPath('userData'), 'instances');
172-
173-
// Read config and eventually use new path
174-
try {
175-
const configFile = fss.readFileSync(
176-
path.join(app.getPath('userData'), 'config.json')
177-
);
178-
const config = JSON.parse(configFile);
179-
if (config.settings.instancesPath) {
180-
oldLauncherUserData = config.settings.instancesPath;
181-
}
182-
} catch {
183-
// Do nothing
184-
}
185-
186171
app.setPath('userData', path.join(app.getPath('appData'), 'gdlauncher_next'));
187172

188173
let allowUnstableReleases = false;
@@ -219,6 +204,34 @@ if (
219204
}
220205
}
221206

207+
// Read config and eventually use new path
208+
try {
209+
const configPath = path.join(app.getPath('userData'), 'config.json');
210+
const configFile = fss.readFileSync(configPath);
211+
const config = JSON.parse(configFile);
212+
213+
const requiredArgs = [
214+
'-Dfml.ignorePatchDiscrepancies=true',
215+
'-Dfml.ignoreInvalidMinecraftCertificates=true'
216+
];
217+
218+
const javaArgs = config.settings.java.args;
219+
220+
if (config.settings.java.args) {
221+
const cleanedJavaArgs = javaArgs
222+
.split(' ')
223+
.filter(arg => !requiredArgs.includes(arg))
224+
.join(' ');
225+
226+
if (cleanedJavaArgs.split(' ').length !== javaArgs.split(' ').length) {
227+
config.settings.java.args = cleanedJavaArgs;
228+
fss.writeFileSync(configPath, JSON.stringify(config));
229+
}
230+
}
231+
} catch {
232+
// Do nothing
233+
}
234+
222235
log.log(process.env.REACT_APP_RELEASE_TYPE, app.getVersion());
223236

224237
const get7zPath = async () => {
@@ -553,10 +566,6 @@ ipcMain.handle('getSentryDsn', () => {
553566
return process.env.SENTRY_DSN;
554567
});
555568

556-
ipcMain.handle('getOldLauncherUserData', () => {
557-
return oldLauncherUserData;
558-
});
559-
560569
ipcMain.handle('getExecutablePath', () => {
561570
return path.dirname(app.getPath('exe'));
562571
});

src/app/desktop/utils/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ export const LINUX = 'linux';
66
export const DARWIN = 'darwin';
77
export const DESKTOP_PATH = path.join(homedir(), 'Desktop');
88
export const CLASSPATH_DIVIDER_CHAR = platform() === WINDOWS ? ';' : ':';
9-
export const DEFAULT_JAVA_ARGS = `-Dfml.ignorePatchDiscrepancies=true -Dfml.ignoreInvalidMinecraftCertificates=true ${
9+
export const DEFAULT_JAVA_ARGS = `${
1010
platform() === WINDOWS
1111
? '-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump'
1212
: ''
1313
} -Xms256m`;
14+
export const REQUIRED_JAVA_ARGS =
15+
'-Dfml.ignorePatchDiscrepancies=true -Dfml.ignoreInvalidMinecraftCertificates=true';
1416
export const DEFAULT_MEMORY = 4096;
1517

1618
export const resolutionPresets = [

src/app/desktop/utils/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { getAddon, getAddonFile, mcGetPlayerSkin } from '../../../common/api';
2525
import { downloadFile } from './downloader';
2626
import browserDownload from '../../../common/utils/browserDownload';
27+
import { REQUIRED_JAVA_ARGS } from './constants';
2728

2829
export const isDirectory = source =>
2930
fs.lstat(source).then(r => r.isDirectory());
@@ -495,14 +496,17 @@ export const getJVMArguments112 = (
495496
.join(process.platform === 'win32' ? ';' : ':')
496497
);
497498

499+
const javaArgs = jvmOptions.filter(Boolean);
500+
498501
// if (process.platform === "darwin") {
499502
// args.push("-Xdock:name=instancename");
500503
// args.push("-Xdock:icon=instanceicon");
501504
// }
502505

503506
args.push(`-Xmx${memory}m`);
504507
args.push(`-Xms${memory}m`);
505-
args.push(...jvmOptions);
508+
args.push(...REQUIRED_JAVA_ARGS.split(' '));
509+
if (javaArgs.length > 0) args.push(...javaArgs);
506510
args.push(
507511
`-Djava.library.path=${addQuotes(
508512
needsQuote,
@@ -600,11 +604,11 @@ export const getJVMArguments113 = (
600604
let args = mcJson.arguments.jvm.filter(v => !skipLibrary(v));
601605
const needsQuote = process.platform !== 'win32';
602606

607+
const javaArgs = jvmOptions.filter(Boolean);
603608
// if (process.platform === "darwin") {
604609
// args.push("-Xdock:name=instancename");
605610
// args.push("-Xdock:icon=instanceicon");
606611
// }
607-
608612
args.push(`-Xmx${memory}m`);
609613
args.push(`-Xms${memory}m`);
610614
args.push(
@@ -613,7 +617,9 @@ export const getJVMArguments113 = (
613617
if (mcJson.logging) {
614618
args.push(mcJson?.logging?.client?.argument || '');
615619
}
616-
args.push(...jvmOptions);
620+
621+
args.push(...REQUIRED_JAVA_ARGS.split(' '));
622+
if (javaArgs.length > 0) args.push(...javaArgs);
617623

618624
// Eventually inject additional arguments (from 1.17 (?))
619625
if (mcJson?.forge?.arguments?.jvm) {

src/common/components/ModalsManager.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ const modalsComponentLookupTable = {
7575
lazy(() => import('../modals/InstanceCrashed'))
7676
),
7777
ChangeLogs: AsyncComponent(lazy(() => import('../modals/ChangeLogs'))),
78-
InstancesMigration: AsyncComponent(
79-
lazy(() => import('../modals/InstancesMigration'))
80-
),
8178
McVersionChanger: AsyncComponent(
8279
lazy(() => import('../modals/McVersionChanger'))
8380
),

0 commit comments

Comments
 (0)