Skip to content

Commit c314366

Browse files
authored
fix file watch on linux/mac
1 parent 7932cb7 commit c314366

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/main/kotlin/com/github/oldmegit/goframehelper/listener/Listener.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Listener(private val project: Project): BulkFileListener {
3232
}
3333

3434
try {
35-
var command = if (Gf.isApiFile(project, file) && Gf.enableApiWatch(project)) {
35+
val commandRaw = if (Gf.isApiFile(project, file) && Gf.enableApiWatch(project)) {
3636
Gf.gfGenCtrl(project)
3737
} else if (Gf.isLogicFile(project, file) && Gf.enableLogicWatch(project)) {
3838
Gf.gfGenService(project)
@@ -41,26 +41,28 @@ class Listener(private val project: Project): BulkFileListener {
4141
}
4242

4343
val os = System.getProperty("os.name").lowercase(Locale.getDefault())
44-
if (os.contains("windows")) {
45-
command = "cmd /c $command"
44+
val process = if (os.contains("windows")) {
45+
Runtime.getRuntime().exec(commandRaw, null, File(project.basePath.toString()))
4646
} else if (os.contains("linux") || os.contains("mac")) {
47-
command = "/bin/sh -c $command"
47+
val workDir = project.basePath
48+
val command = arrayOf("sh", "-c", "cd $workDir && $commandRaw")
49+
ProcessBuilder(*command).start()
50+
} else {
51+
throw Exception(Bundle.getMessage("gfExecNotSupport"))
4852
}
4953

50-
val process = Runtime.getRuntime().exec(command, null, File(project.basePath.toString()))
5154
val code = process.waitFor()
5255
if (code != 0) {
53-
throw Exception("execute command fail")
56+
throw Exception(Bundle.getMessage("gfExecErrNotify"))
5457
}
55-
} catch (_: Exception) {
56-
val message = Bundle.getMessage("gfExecErrNotify")
58+
} catch (e: Exception) {
5759
val settings = AppSettingsState.getInstance(project)
5860
settings.gfEnableApiWatch = false
5961
settings.gfEnableLogicWatch = false
6062

6163
NotificationGroupManager.getInstance()
6264
.getNotificationGroup("GoFrame Help Notify")
63-
.createNotification(message, NotificationType.INFORMATION)
65+
.createNotification(e.toString(), NotificationType.INFORMATION)
6466
.notify(project)
6567
}
6668
}

src/main/resources/message/GoFrameHelperBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ setting.service.watch = Enable Service watch, it will auto exec `gf gen service`
1010
setting.custom.i18n = Custom i18n folder
1111

1212
gfExecErrNotify = gf-cli is not available, auto closing File Watch. You can re-enable it in Setting-Tools-GoFrame Helper.
13+
gfExecNotSupport = The current system is not supported by file watch

src/main/resources/message/GoFrameHelperBundle_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ setting.service.watch = \u542f\u7528 Service watch, \u5b83\u4f1a\u81ea\u52a8\u62
1010
setting.custom.i18n = \u81ea\u5b9a\u4e49\u0069\u0031\u0038\u006e\u76ee\u5f55
1111

1212
gfExecErrNotify = \u0067\u0066\u002d\u0063\u006c\u0069\u0020\u4e0d\u53ef\u7528\uff0c\u5c06\u81ea\u52a8\u5173\u95ed\u0020\u0046\u0049\u006c\u0065\u0020\u0057\u0061\u0074\u0063\u0068\uff0c\u60a8\u53ef\u4ee5\u5728\u0020\u0053\u0065\u0074\u0074\u0069\u006e\u0067\u002d\u0054\u006f\u006f\u006c\u0073\u002d\u0047\u006f\u0046\u0072\u0061\u006d\u0065\u0020\u0048\u0065\u006c\u0070\u0065\u0072\u0020\u4e2d\u91cd\u65b0\u542f\u7528\u3002
13+
gfExecNotSupport = \u5f53\u524d\u7cfb\u7edf\u4e0d\u652f\u6301\u0020\u0066\u0069\u006c\u0065\u0020\u0077\u0061\u0074\u0063\u0068

0 commit comments

Comments
 (0)