@@ -5,7 +5,7 @@ import ClassDumpRuntime
55import  FoundationToolbox
66import  RuntimeViewerCommunication
77
8- public  final   actor  RuntimeEngine  { 
8+ public  actor  RuntimeEngine  { 
99    public  static  let  shared =  RuntimeEngine ( ) 
1010
1111    private  static  let  logger =  Logger ( label:  " RuntimeEngine " ) 
@@ -15,7 +15,7 @@ public final actor RuntimeEngine {
1515    @Published   private  var  protocolList :  [ String ]  =  [ ] 
1616
1717    @Published   private  var  protocolToImage :  [ String :  String ]  =  [ : ] 
18-      
18+ 
1919    @Published   private  var  imageToProtocols :  [ String :  [ String ] ]  =  [ : ] 
2020
2121    @Published   public  private( set)   var  imageList :  [ String ]  =  [ ] 
@@ -24,6 +24,10 @@ public final actor RuntimeEngine {
2424
2525    @Published   public  private( set)   var  imageToSwiftSections :  [ String :  RuntimeSwiftSections ]  =  [ : ] 
2626
27+     private  let  reloadDataSubject =  PassthroughSubject < Void ,  Never > ( ) 
28+     
29+     public  var  reloadDataPublisher :  some  Publisher < Void ,  Never >  {  reloadDataSubject. eraseToAnyPublisher ( )  } 
30+     
2731    fileprivate  enum  CommandNames :  String ,  CaseIterable  { 
2832        case  classList
2933        case  protocolList
@@ -43,6 +47,7 @@ public final actor RuntimeEngine {
4347        case  observeRuntime
4448        case  interfaceForRuntimeObjectInImageWithOptions
4549        case  namesOfKindInImage
50+         case  reloadData
4651
4752        var  commandName :  String  {  " com.JH.RuntimeViewerCore.RuntimeEngine. \( rawValue) "  } 
4853    } 
@@ -137,13 +142,20 @@ public final actor RuntimeEngine {
137142            try await  perform ( self ,  response) 
138143        } 
139144    } 
145+     
146+     private  func  setMessageHandlerBinding( forName name:  CommandNames ,  perform:  @escaping  ( isolated  RuntimeEngine)  async  throws  ->  Void )  { 
147+         connection? . setMessageHandler ( name:  name. commandName)  {  [ weak self]  in 
148+             guard  let  self else  {  return  } 
149+             try await  perform ( self ) 
150+         } 
151+     } 
140152
141153    public  func  reloadData( )  { 
142154        Self . logger. debug ( " Start reload " ) 
143155        classList =  ObjCRuntime . classNames ( ) 
144156        protocolList =  ObjCRuntime . protocolNames ( ) 
145157        imageList =  DyldUtilities . imageNames ( ) 
146-         imageNodes =  [ DyldUtilities . dyldSharedCacheImageRootNode,  DyldUtilities . otherImageRootNode] 
158+ //         imageNodes = [DyldUtilities.dyldSharedCacheImageRootNode, DyldUtilities.otherImageRootNode]
147159        Self . logger. debug ( " End reload " ) 
148160        sendRemoteDataIfNeeded ( ) 
149161    } 
@@ -157,25 +169,10 @@ public final actor RuntimeEngine {
157169        )  ??  ( [ : ] ,  [ : ] ) 
158170        self . protocolToImage =  protocolToImage
159171        self . imageToProtocols =  imageToProtocols
160-         Task . detached  { 
161-             await  self . setImageNodes ( [ DyldUtilities . dyldSharedCacheImageRootNode,  DyldUtilities . otherImageRootNode] ) 
162-         } 
163172
164- //        Task.detached { [self] in
165- //            await withTaskGroup { group in
166- //                for imagePath in await imageList {
167- //                    group.addTask {
168- //                        do {
169- //                            let section = try RuntimeSwiftSections(imagePath: imagePath)
170- //                            await self.setSwiftSection(section, forImage: imagePath)
171- //                        } catch {
172- //                            print(imagePath)
173- //                        }
174- //                    }
175- //                }
176- //                await group.waitForAll()
177- //            }
178- //        }
173+         await  Task . detached  { 
174+             await  self . setImageNodes ( [ DyldUtilities . dyldSharedCacheImageRootNode,  DyldUtilities . otherImageRootNode] ) 
175+         } . value
179176
180177        shouldReload
181178            . debounce ( for:  . milliseconds( 15 ) ,  scheduler:  DispatchQueue . main) 
@@ -325,7 +322,7 @@ public final actor RuntimeEngine {
325322            } 
326323        } 
327324    } 
328-      
325+ 
329326    private  func  getOrCreateSwiftSections( for imagePath:  String )  async  throws  ->  RuntimeSwiftSections  { 
330327        if  let  swiftSections =  imageToSwiftSections [ imagePath]  { 
331328            return  swiftSections
@@ -367,8 +364,10 @@ extension RuntimeEngine {
367364            let  section  =  try RuntimeSwiftSections ( imagePath:  path) 
368365            await  setSwiftSection ( section,  forImage:  path) 
369366            reloadData ( ) 
367+             reloadDataSubject. send ( ( ) ) 
370368        }  remote:  { 
371369            try await  $0. sendMessage ( name:  . loadImage,  request:  path) 
370+             reloadDataSubject. send ( ( ) ) 
372371        } 
373372    } 
374373
0 commit comments