Skip to content

Commit 39554dd

Browse files
committed
添加socket的初始化成功判断
1 parent ae9372f commit 39554dd

4 files changed

Lines changed: 41 additions & 11 deletions

File tree

src/main/kotlin/shop/itbug/fluttercheckversionx/form/socket/LeftActionTools.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,5 @@ class ViewGetQueryParamsAction(private val request: Request?, private val projec
165165

166166
fun Any.mylogger() : org.slf4j.Logger {
167167
return LoggerFactory.getLogger(this::class.java)
168-
}
168+
}
169+

src/main/kotlin/shop/itbug/fluttercheckversionx/form/socket/SocketRequestForm.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ class SocketRequestForm(val project: Project) : ListSelectionListener { /// 表
262262
) {
263263
RewardDialog(project).show()
264264
}
265+
val socketIsInited = service.socketIsInit;
266+
if(socketIsInited.not()){
267+
appendLine("")
268+
appendText("Socket(端口9999)没有正常启动,请检查网络连接或者本地代理,点我重连",SimpleTextAttributes(SimpleTextAttributes.STYLE_CLICKABLE,JBUI.CurrentTheme.Link.Foreground.ENABLED)){
269+
service.initSocketService(project)
270+
}
271+
}
265272
}
266273
}
267274

src/main/kotlin/shop/itbug/fluttercheckversionx/linemark/PluginDartIconLineMark.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ class PluginDartIconLineMark : LineMarkerProvider {
3434

3535
///处理点击
3636
class PluginDartIconLineMarkNavHandler(val element: YAMLKeyValueImpl) : GutterIconNavigationHandler<PsiElement> {
37-
3837
override fun navigate(e: MouseEvent?, elt: PsiElement?) {
3938
if (e != null && e.clickCount == 1) {
4039
JBPopupFactory.getInstance().createListPopup(PluginDartIconActioinMenuList(element = element))
4140
.show(RelativePoint(e.locationOnScreen))
4241
}
4342
}
44-
4543
}
4644

4745
data class PluginDartIconActionMenuItem(val title: String, val type: String, val icon: Icon)
@@ -58,13 +56,12 @@ class PluginDartIconActioinMenuList(val element: YAMLKeyValueImpl) : BaseListPop
5856
}
5957

6058

61-
6259
override fun getTextFor(value: PluginDartIconActionMenuItem?): String {
6360
return value?.title ?: "未知选项"
6461
}
6562

6663
override fun onChosen(selectedValue: PluginDartIconActionMenuItem?, finalChoice: Boolean): PopupStep<*>? {
67-
when(selectedValue?.type){
64+
when (selectedValue?.type) {
6865
menus[0].type -> {
6966
BrowserUtil.browse("$PUB_URL${element.keyText}")
7067
}

src/main/kotlin/shop/itbug/fluttercheckversionx/socket/service/AppService.kt

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package shop.itbug.fluttercheckversionx.socket.service
33
import cn.hutool.core.lang.Console
44
import cn.hutool.http.HttpUtil
55
import com.google.gson.Gson
6+
import com.intellij.notification.NotificationType
67
import com.intellij.openapi.application.ApplicationManager
78
import com.intellij.openapi.project.Project
89
import kotlinx.coroutines.DelicateCoroutinesApi
@@ -14,6 +15,7 @@ import org.smartboot.socket.StateMachineEnum
1415
import org.smartboot.socket.transport.AioQuickServer
1516
import org.smartboot.socket.transport.AioSession
1617
import shop.itbug.fluttercheckversionx.form.socket.Request
18+
import shop.itbug.fluttercheckversionx.form.socket.mylogger
1719
import shop.itbug.fluttercheckversionx.model.example.ExampleResult
1820
import shop.itbug.fluttercheckversionx.model.example.ResourceModel
1921
import shop.itbug.fluttercheckversionx.services.SocketMessageBus
@@ -25,11 +27,16 @@ class AppService {
2527

2628

2729
lateinit var project: Project
30+
2831
/**
2932
* 全局的socket监听服务
3033
*/
3134
private var server: AioQuickServer? = null
3235

36+
37+
/**
38+
* 组件示例
39+
*/
3340
var examples = emptyList<ResourceModel>()
3441

3542
/**
@@ -41,6 +48,12 @@ class AppService {
4148
private var flutterProjects = mutableMapOf<String, List<ProjectSocketService.SocketResponseModel>>()
4249

4350

51+
/**
52+
* socket服务是否已经正常运行
53+
*/
54+
var socketIsInit = false
55+
56+
4457
// init {
4558
// setTestData()
4659
// }
@@ -64,18 +77,26 @@ class AppService {
6477
) {
6578
super.stateEvent(session, stateMachineEnum, throwable)
6679
println("状态机:${stateMachineEnum}")
67-
when(stateMachineEnum){
80+
when (stateMachineEnum) {
6881
StateMachineEnum.NEW_SESSION -> {
6982
newSessionHandle(session)
7083
}
84+
7185
else -> {}
7286
}
7387
}
7488
})
7589
server!!.setReadBufferSize(10485760) // 10m
7690
try {
7791
server!!.start()
78-
} catch (_: Exception) {
92+
socketIsInit = true
93+
} catch (e: Exception) {
94+
socketIsInit = false
95+
mylogger().error("启动socket服务失败:${e.localizedMessage}")
96+
MyNotifactionUtil.socketNotif(
97+
message = "启动dio监听模块失败,异常:${e.localizedMessage}", project = project,
98+
NotificationType.ERROR
99+
)
79100
}
80101
}
81102
}
@@ -85,7 +106,10 @@ class AppService {
85106
* 当有新连接进来的时候处理函数
86107
*/
87108
private fun newSessionHandle(session: AioSession?) {
88-
MyNotifactionUtil.socketNotif("梁典典: 检测到APP连接成功,现在可以在底部工具栏监听dio请求了", project = project)
109+
MyNotifactionUtil.socketNotif(
110+
"梁典典: 检测到APP连接成功,现在可以在底部工具栏监听dio请求了,${session?.sessionID}",
111+
project = project
112+
)
89113
}
90114

91115
@OptIn(DelicateCoroutinesApi::class)
@@ -160,10 +184,11 @@ class AppService {
160184
}
161185

162186

163-
fun setTestData(){
187+
fun setTestData() {
164188
flutterProjects = mutableMapOf(
165189
Pair(
166-
"test",ProjectSocketService.genList()
167-
))
190+
"test", ProjectSocketService.genList()
191+
)
192+
)
168193
}
169194
}

0 commit comments

Comments
 (0)