Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 566e9f5

Browse files
committed
feat: support debug by args
1 parent fb526a9 commit 566e9f5

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/main/java/org/code4everything/wetool/WeApplication.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cn.hutool.core.io.FileUtil;
77
import cn.hutool.core.thread.ThreadFactoryBuilder;
88
import cn.hutool.core.thread.ThreadUtil;
9+
import cn.hutool.core.util.ArrayUtil;
910
import cn.hutool.core.util.BooleanUtil;
1011
import cn.hutool.core.util.RuntimeUtil;
1112
import cn.hutool.core.util.StrUtil;
@@ -80,6 +81,8 @@
8081
@Slf4j
8182
public class WeApplication extends Application {
8283

84+
private static final Set<String> DEBUG_OPTIONS = Set.of("debug", "-d", "--debug");
85+
8386
private static final Menu PLUGIN_MENU = new Menu(TitleConsts.PLUGIN);
8487

8588
private static final ThreadFactory FACTORY = ThreadFactoryBuilder.create().setDaemon(true).setUncaughtExceptionHandler((t, e) -> log.error(ExceptionUtil.stacktraceToString(e, Integer.MAX_VALUE))).build();
@@ -103,10 +106,31 @@ private static Pane getRootPane() {
103106
}
104107

105108
public static void main(String[] args) {
109+
boolean debug = BootConfig.isDebug();
110+
if (ArrayUtil.isNotEmpty(args)) {
111+
for (String arg : args) {
112+
if (DEBUG_OPTIONS.contains(arg)) {
113+
debug = true;
114+
BootConfig.setDebug(true);
115+
break;
116+
}
117+
}
118+
}
119+
106120
log.info("starting wetool on os: {}", SystemUtil.getOsInfo().getName());
107121
log.info("default charset: {}", Charset.defaultCharset().name());
108-
checkAlreadyRunning();
122+
109123
parseConfig();
124+
if (debug) {
125+
// 因配置文件可能会修改debug mode,所以这里需要确保解析配置文件后debug模式仍然为true
126+
WeUtils.getConfig().setDebug(true);
127+
BootConfig.setDebug(true);
128+
}
129+
if (BootConfig.isDebug()) {
130+
log.info("debug mode enabled");
131+
}
132+
133+
checkAlreadyRunning();
110134
initApp();
111135
launch(args);
112136
}

startup.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
import sys
66

77
system = platform.system()
8-
option = ' '
8+
jvm_option = ''
9+
wetool_option = ''
910

1011

1112
for arg in sys.argv[1:]:
1213
if 'debug' == arg:
13-
option = ' -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 '
14+
jvm_option = '-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005'
15+
wetool_option = 'debug'
1416
break
1517

1618

1719
if 'Windows' == system:
18-
os.system('javaw -jar%swetool-win.jar' % option)
20+
os.system('javaw -jar %s wetool-win.jar %s' % (jvm_option, wetool_option))
1921
elif 'Darwin' == system:
20-
os.system('java -jar%swetool-mac.jar &' % option)
22+
os.system('java -jar %s wetool-mac.jar %s &' % (jvm_option, wetool_option))
2123
elif 'Linux' == system:
22-
os.system('java -jar%swetool-linux.jar &' % option)
24+
os.system('java -jar %s wetool-linux.jar %s &'% (jvm_option, wetool_option))
2325
else:
2426
print('unknown platform')

0 commit comments

Comments
 (0)