|
1 | 1 | /* eslint-disable @typescript-eslint/explicit-function-return-type, object-curly-newline */
|
2 |
| -import { React, Reqwq, ProfilesStore, pluginMaster, $ as $0, xmcl, openConfirmDialog, |
3 |
| - version as launcherBrand, constants, notice, Avatar, getVersionTypeText } from '@plugin' |
| 2 | +import { React, Reqwq, ProfilesStore, pluginMaster, $ as $0, xmcl, openConfirmDialog, getSuitableMemory, fs, |
| 3 | + version as launcherBrand, constants, notice, Avatar, getVersionTypeText, resolveJavaPath } from '@plugin' |
4 | 4 | import { join } from 'path'
|
5 | 5 | import $ from './langs'
|
6 | 6 |
|
@@ -54,7 +54,7 @@ const MultiInstances: React.FC = () => {
|
54 | 54 | <div style={css[1]}>
|
55 | 55 | <span style={css[2]}>{$.account}: </span>
|
56 | 56 | <select style={css[3]} onChange={e => setAccount(e.target.value)} value={account}>
|
57 |
| - {accounts.map(it => <option value={it.key} key={it.key}>{it.username}</option>)} |
| 57 | + {accounts.map(it => <option value={it.key} key={it.key}>{it.username} ({it.type})</option>)} |
58 | 58 | </select>
|
59 | 59 | </div>
|
60 | 60 | <div style={css[1]}>
|
@@ -90,25 +90,48 @@ const MultiInstances: React.FC = () => {
|
90 | 90 | }
|
91 | 91 | }
|
92 | 92 | try {
|
93 |
| - const versionId = await ps.resolveVersion(version) |
| 93 | + const v = { version } |
| 94 | + await pluginMaster.emitSync('launchResolveVersion', v) |
| 95 | + await pluginMaster.emitSync('launchPostResolvedVersion', v) |
| 96 | + |
| 97 | + await pluginMaster.emit('launchPreUpdate', v.version) |
| 98 | + await pluginMaster.emit('launchPostUpdate', v.version) |
| 99 | + |
| 100 | + const versionId = await ps.resolveVersion(v.version) |
| 101 | + await ps.checkModsDirectoryOfVersion(versionId, |
| 102 | + (await fs.readJson(constants.RESOURCES_VERSIONS_INDEX_PATH, { throws: false }) || { })[version]) |
| 103 | + await pluginMaster.emit('launchEnsureFiles', versionId) |
| 104 | + |
| 105 | + const versionDir = join(constants.VERSIONS_PATH, versionId) |
| 106 | + const javaPath = await resolveJavaPath(ps.extraJson.javaPath) |
| 107 | + const json = (await fs.readJson(constants.RESOURCES_VERSIONS_INDEX_PATH, { throws: false }) || { })[versionId] |
94 | 108 | const option: import('@xmcl/core').LaunchOption & { prechecks: import('@xmcl/core').LaunchPrecheck[] } = {
|
95 |
| - resourcePath: constants.GAME_ROOT, |
96 |
| - prechecks: ps.extraJson.noChecker ? [] : undefined, |
97 | 109 | launcherBrand,
|
| 110 | + minMemory: 512, |
98 | 111 | properties: {},
|
99 | 112 | userType: 'mojang',
|
100 | 113 | version: versionId,
|
101 |
| - gamePath: constants.GAME_ROOT, |
102 | 114 | launcherName: 'pure-launcher',
|
103 | 115 | accessToken: a.accessToken || '',
|
104 | 116 | versionType: getVersionTypeText(),
|
| 117 | + resourcePath: constants.GAME_ROOT, |
| 118 | + extraExecOption: { detached: true }, |
105 | 119 | javaPath: ps.extraJson.javaPath || 'javaw',
|
106 | 120 | gameProfile: { id: a.uuid, name: a.username },
|
| 121 | + prechecks: ps.extraJson.noChecker ? [] : undefined, |
107 | 122 | extraJVMArgs: (ps.extraJson.javaArgs || '').split(' '),
|
108 |
| - extraExecOption: { detached: true } |
| 123 | + maxMemory: getSuitableMemory(!!JSON.parse(localStorage.getItem('javaArches') || '{}')[javaPath]), |
| 124 | + gamePath: json?.isolation || (await fs.readJson(join(versionDir, versionId + '.json'), |
| 125 | + { throws: false }))?.isolation ? versionDir : constants.GAME_ROOT |
109 | 126 | }
|
110 |
| - await pluginMaster.emitSync('preLaunch', versionId, option) |
111 |
| - await launch(option) |
| 127 | + await pluginMaster.emitSync('preLaunch', versionId, option, a) |
| 128 | + const p = (await launch(option)) |
| 129 | + .on('error', e => { |
| 130 | + console.error(e) |
| 131 | + notice({ content: $.launchFailed + ': ' + e.message, error: true }) |
| 132 | + }) |
| 133 | + .on('exit', code => code && notice({ content: $.launchFailed + ': ' + code, error: true })) |
| 134 | + await pluginMaster.emit('postLaunch', p, versionId, option) |
112 | 135 | notice({ content: $.launched })
|
113 | 136 | } catch (e) {
|
114 | 137 | console.error(e)
|
|
0 commit comments