@@ -4,10 +4,10 @@ import com.github.oldmegit.goframehelper.data.Bundle
4
4
import com.github.oldmegit.goframehelper.gf.Gf
5
5
import com.github.oldmegit.goframehelper.gf.GfGoMod
6
6
import com.github.oldmegit.goframehelper.ui.AppSettingsState
7
+ import com.github.oldmegit.goframehelper.ui.Notification
7
8
import com.goide.GoFileType
8
- import com.intellij.notification.NotificationGroupManager
9
- import com.intellij.notification.NotificationType
10
9
import com.intellij.openapi.project.Project
10
+ import com.intellij.openapi.vfs.VirtualFile
11
11
import com.intellij.openapi.vfs.newvfs.BulkFileListener
12
12
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
13
13
import java.io.File
@@ -31,40 +31,45 @@ class Listener(private val project: Project): BulkFileListener {
31
31
return
32
32
}
33
33
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
+ }
42
37
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
+ }
53
49
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
+ }
62
62
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())
67
66
}
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)
68
73
}
69
74
}
70
75
}
0 commit comments