@@ -3,6 +3,7 @@ package shop.itbug.fluttercheckversionx.socket.service
33import cn.hutool.core.lang.Console
44import cn.hutool.http.HttpUtil
55import com.google.gson.Gson
6+ import com.intellij.notification.NotificationType
67import com.intellij.openapi.application.ApplicationManager
78import com.intellij.openapi.project.Project
89import kotlinx.coroutines.DelicateCoroutinesApi
@@ -14,6 +15,7 @@ import org.smartboot.socket.StateMachineEnum
1415import org.smartboot.socket.transport.AioQuickServer
1516import org.smartboot.socket.transport.AioSession
1617import shop.itbug.fluttercheckversionx.form.socket.Request
18+ import shop.itbug.fluttercheckversionx.form.socket.mylogger
1719import shop.itbug.fluttercheckversionx.model.example.ExampleResult
1820import shop.itbug.fluttercheckversionx.model.example.ResourceModel
1921import 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