@@ -4,10 +4,10 @@ import com.github.oldmegit.goframehelper.data.Bundle
44import com.github.oldmegit.goframehelper.gf.Gf
55import com.github.oldmegit.goframehelper.gf.GfGoMod
66import com.github.oldmegit.goframehelper.ui.AppSettingsState
7+ import com.github.oldmegit.goframehelper.ui.Notification
78import com.goide.GoFileType
8- import com.intellij.notification.NotificationGroupManager
9- import com.intellij.notification.NotificationType
109import com.intellij.openapi.project.Project
10+ import com.intellij.openapi.vfs.VirtualFile
1111import com.intellij.openapi.vfs.newvfs.BulkFileListener
1212import com.intellij.openapi.vfs.newvfs.events.VFileEvent
1313import java.io.File
@@ -31,40 +31,45 @@ class Listener(private val project: Project): BulkFileListener {
3131 return
3232 }
3333
34- try {
35- val commandRaw = if (Gf .isApiFile(project, file) && Gf .enableApiWatch(project)) {
36- Gf .gfGenCtrl(project)
37- } else if (Gf .isLogicFile(project, file) && Gf .enableLogicWatch(project)) {
38- Gf .gfGenService(project)
39- } else {
40- return
41- }
34+ fileWatch(file)
35+ }
36+ }
4237
43- val os = System .getProperty(" os.name" ).lowercase(Locale .getDefault())
44- val process = if (os.contains(" windows" )) {
45- Runtime .getRuntime().exec(commandRaw, null , File (project.basePath.toString()))
46- } else if (os.contains(" linux" ) || os.contains(" mac" )) {
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" ))
52- }
38+ // file watch exec command
39+ private fun fileWatch (file : VirtualFile ) {
40+ try {
41+ // get commandRaw
42+ val commandRaw = if (Gf .isApiFile(project, file) && Gf .enableApiWatch(project)) {
43+ Gf .gfGenCtrl(project)
44+ } else if (Gf .isLogicFile(project, file) && Gf .enableLogicWatch(project)) {
45+ Gf .gfGenService(project)
46+ } else {
47+ return
48+ }
5349
54- val code = process.waitFor()
55- if (code != 0 ) {
56- throw Exception (Bundle .getMessage(" gfExecErrNotify" ))
57- }
58- } catch (e: Exception ) {
59- val settings = AppSettingsState .getInstance(project)
60- settings.gfEnableApiWatch = false
61- settings.gfEnableLogicWatch = false
50+ // exec command based on different systems
51+ val os = System .getProperty(" os.name" ).lowercase(Locale .getDefault())
52+ val process = if (os.contains(" windows" )) {
53+ Runtime .getRuntime().exec(commandRaw, null , File (project.basePath.toString()))
54+ } else if (os.contains(" linux" ) || os.contains(" mac" )) {
55+ val workDir = project.basePath
56+ val command = arrayOf(" sh" , " -c" , " cd $workDir && $commandRaw " )
57+ ProcessBuilder (* command).start()
58+ } else {
59+ Notification .message(project, Bundle .getMessage(" fileWatch.NotSupport" ))
60+ return
61+ }
6262
63- NotificationGroupManager .getInstance()
64- .getNotificationGroup(" GoFrame Help Notify" )
65- .createNotification(e.toString(), NotificationType .INFORMATION )
66- .notify(project)
63+ val code = process.waitFor()
64+ if (code != 0 ) {
65+ throw Exception (code.toString())
6766 }
67+ } catch (_: Exception ) {
68+ val message = Bundle .getMessage(" fileWatch.ExecErr" )
69+ val settings = AppSettingsState .getInstance(project)
70+ settings.gfEnableApiWatch = false
71+ settings.gfEnableLogicWatch = false
72+ Notification .message(project, message)
6873 }
6974 }
7075}
0 commit comments