Skip to content

Commit 176c82b

Browse files
authored
fix #9
1 parent 5b88403 commit 176c82b

File tree

1 file changed

+22
-6
lines changed
  • src/main/kotlin/com/github/oldmegit/goframehelper/listener

1 file changed

+22
-6
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import com.github.oldmegit.goframehelper.gf.Gf
55
import com.github.oldmegit.goframehelper.gf.GfGoMod
66
import com.github.oldmegit.goframehelper.ui.AppSettingsState
77
import com.goide.GoFileType
8+
import com.intellij.notification.NotificationGroupManager
9+
import com.intellij.notification.NotificationType
810
import com.intellij.openapi.project.Project
911
import com.intellij.openapi.vfs.newvfs.BulkFileListener
1012
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
11-
import com.intellij.notification.NotificationGroupManager
12-
import com.intellij.notification.NotificationType
1313
import java.io.File
14+
import java.util.*
15+
1416

1517
class Listener(private val project: Project): BulkFileListener {
1618
override fun after(events: MutableList<out VFileEvent>) {
@@ -29,12 +31,26 @@ class Listener(private val project: Project): BulkFileListener {
2931
return
3032
}
3133

32-
val runtime = Runtime.getRuntime()
3334
try {
34-
if (Gf.isApiFile(project, file) && Gf.enableApiWatch(project)) {
35-
runtime.exec(Gf.gfGenCtrl(project), null, File(project.basePath.toString()))
35+
var command = if (Gf.isApiFile(project, file) && Gf.enableApiWatch(project)) {
36+
Gf.gfGenCtrl(project)
3637
} else if (Gf.isLogicFile(project, file) && Gf.enableLogicWatch(project)) {
37-
runtime.exec(Gf.gfGenService(project), null, File(project.basePath.toString()))
38+
Gf.gfGenService(project)
39+
} else {
40+
return
41+
}
42+
43+
val os = System.getProperty("os.name").lowercase(Locale.getDefault())
44+
if (os.contains("windows")) {
45+
command = "cmd /c $command"
46+
} else if (os.contains("linux") || os.contains("mac")) {
47+
command = "/bin/sh -c $command"
48+
}
49+
50+
val process = Runtime.getRuntime().exec(command, null, File(project.basePath.toString()))
51+
val code = process.waitFor()
52+
if (code != 0) {
53+
throw Exception("execute command fail")
3854
}
3955
} catch (_: Exception) {
4056
val message = Bundle.getMessage("gfExecErrNotify")

0 commit comments

Comments
 (0)