Skip to content

Commit c6ad1f4

Browse files
committed
尝试修复m1 mac上无法启动的问题
1 parent 7aab073 commit c6ad1f4

2 files changed

Lines changed: 25 additions & 53 deletions

File tree

src/main/java/com/github/balloonupdate/mcpatch/client/Main.java

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static boolean modloader(boolean enableLogFile, boolean disableTheme) thr
8080
*/
8181
static boolean AppMain(boolean graphicsMode, StartMethod startMethod, boolean enableLogFile, boolean disableTheme) throws Throwable {
8282
// 记录有无更新
83-
final boolean[] hasUpdate = {false};
83+
boolean hasUpdate = false;
8484

8585
McPatchWindow window = null;
8686

@@ -126,6 +126,14 @@ static boolean AppMain(boolean graphicsMode, StartMethod startMethod, boolean en
126126
window.show();
127127
}
128128

129+
// // 点击窗口的叉时停止更新任务
130+
// if (window != null) {
131+
// window.onWindowClosing = w -> {
132+
// if (workThread.isAlive())
133+
// workThread.interrupt();
134+
// };
135+
// }
136+
129137
Work work = new Work();
130138
work.window = window;
131139
work.config = config;
@@ -135,63 +143,29 @@ static boolean AppMain(boolean graphicsMode, StartMethod startMethod, boolean en
135143
work.graphicsMode = graphicsMode;
136144
work.startMethod = startMethod;
137145

138-
// 将更新任务单独放进单独线程执行,方便随时打断线程
139-
final Throwable[] ex = { null };
140-
141-
Thread workThread = new Thread(() -> {
142-
try {
143-
hasUpdate[0] = work.run();
144-
} catch (McpatchBusinessException e) {
145-
ex[0] = e;
146-
}
147-
});
148-
149-
workThread.setDaemon(true);
150-
workThread.setUncaughtExceptionHandler((ignored, e) -> ex[0] = e);
151-
152-
// 点击窗口的叉时停止更新任务
153-
if (window != null) {
154-
window.onWindowClosing = w -> {
155-
if (workThread.isAlive())
156-
workThread.interrupt();
157-
};
158-
}
159-
160-
// 启动更新任务
161-
workThread.start();
162146
try {
163-
workThread.join();
164-
} catch (InterruptedException e) {
165-
throw new RuntimeException(e);
166-
}
167-
168-
// 退出窗口
169-
if (window != null)
170-
window.destroy();
171-
172-
// 处理工作线程里的异常
173-
McpatchBusinessException ex1 = (McpatchBusinessException) ex[0];
174-
175-
if (ex1 != null) {
176-
boolean a = ex1.getCause() instanceof InterruptedException;
177-
boolean b = ex1.getCause() instanceof ClosedByInterruptException;
147+
// 启动更新任务
148+
hasUpdate = work.run();
149+
} catch (McpatchBusinessException e) {
150+
boolean a = e.getCause() instanceof InterruptedException;
151+
boolean b = e.getCause() instanceof ClosedByInterruptException;
178152

179153
if (!a && !b) {
180154
// 打印异常日志
181155
try {
182156
Log.openIndent("Crash");
183-
Log.error(ex1.toString());
157+
Log.error(e.toString());
184158
Log.closeIndent();
185-
} catch (Exception e) {
159+
} catch (Exception ex) {
186160
System.out.println("------------------------");
187-
System.out.println(ex1);
161+
System.out.println(ex);
188162
}
189163

190164
// 图形模式下弹框显示错误
191165
if (graphicsMode) {
192166
boolean sp = startMethod == StartMethod.Standalone;
193167

194-
String errMsg = ex1.getMessage() != null ? ex1.getMessage() : "<No Exception Message>";
168+
String errMsg = e.getMessage() != null ? e.getMessage() : "<No Exception Message>";
195169
String errMessage = BytesUtils.stringBreak(errMsg, 80, "\n");
196170
String title = "发生错误 " + Env.getVersion();
197171
String content = errMessage + "\n";
@@ -204,15 +178,15 @@ static boolean AppMain(boolean graphicsMode, StartMethod startMethod, boolean en
204178
{
205179
if (choice)
206180
{
207-
DialogUtility.error("错误详情 " + Env.getVersion(), ex1.toString());
181+
DialogUtility.error("错误详情 " + Env.getVersion(), e.toString());
208182

209-
throw ex1;
183+
throw e;
210184
}
211185
} else {
212186
if (choice)
213-
DialogUtility.error("错误详情 " + Env.getVersion(), ex1.toString());
187+
DialogUtility.error("错误详情 " + Env.getVersion(), e.toString());
214188

215-
throw ex1;
189+
throw e;
216190
}
217191
}
218192
} else {
@@ -223,13 +197,14 @@ static boolean AppMain(boolean graphicsMode, StartMethod startMethod, boolean en
223197
if (window != null)
224198
window.destroy();
225199

226-
Log.info("RAM: " + BytesUtils.convertBytes(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
200+
if (startMethod != Main.StartMethod.Standalone)
201+
Log.info("continue to start Minecraft!");
227202

228203
// if (startMethod == StartMethod.Standalone)
229204
// Runtime.getRuntime().exit(0);
230205
}
231206

232-
return hasUpdate[0];
207+
return hasUpdate;
233208
}
234209

235210
/**

src/main/java/com/github/balloonupdate/mcpatch/client/Work.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,6 @@ boolean run2(Servers server) throws IOException, McpatchBusinessException {
611611
}
612612
}
613613

614-
if (startMethod != Main.StartMethod.Standalone)
615-
Log.info("continue to start Minecraft!");
616-
617614
return hasUpdate;
618615
}
619616
}

0 commit comments

Comments
 (0)