@@ -19,6 +19,8 @@ use log::{debug, error, info, trace, warn};
1919use serde:: { Deserialize , Serialize } ;
2020use tokio:: time:: interval;
2121use tauri:: { AppHandle , Emitter , command, State , Manager } ;
22+ use crate :: IPC :: AdvancedFeatures :: PerformanceStats ;
23+ use Common :: FileSystem :: FileSystemReader :: FileSystemReader ;
2224
2325use crate :: RunTime :: ApplicationRunTime :: ApplicationRunTime ;
2426use Common :: Environment :: Requires :: Requires ;
@@ -33,49 +35,6 @@ pub struct WindAdvancedSync {
3335}
3436
3537impl WindAdvancedSync {
36- /// Create a new WindAdvancedSync instance
37- pub fn new ( runtime : Arc < ApplicationRunTime > ) -> Self {
38- Self {
39- runtime,
40- document_sync : Arc :: new ( Mutex :: new ( DocumentSynchronization {
41- synchronized_documents : HashMap :: new ( ) ,
42- pending_changes : HashMap :: new ( ) ,
43- last_sync_time : 0 ,
44- sync_status : SyncStatus {
45- total_documents : 0 ,
46- synced_documents : 0 ,
47- conflicted_documents : 0 ,
48- offline_documents : 0 ,
49- last_sync_duration_ms : 0 ,
50- } ,
51- } ) ) ,
52- ui_state_sync : Arc :: new ( Mutex :: new ( UIStateSynchronization {
53- active_editor : None ,
54- cursor_positions : HashMap :: new ( ) ,
55- selection_ranges : HashMap :: new ( ) ,
56- view_state : ViewState {
57- zoom_level : 1.0 ,
58- sidebar_visible : true ,
59- panel_visible : true ,
60- status_bar_visible : true ,
61- } ,
62- theme : "default" . to_string ( ) ,
63- layout : LayoutState {
64- editor_groups : Vec :: new ( ) ,
65- active_group : 0 ,
66- grid_layout : GridLayout {
67- rows : 1 ,
68- columns : 1 ,
69- cell_width : 100 ,
70- cell_height : 100 ,
71- } ,
72- } ,
73- } ) ) ,
74- real_time_updates : Arc :: new ( Mutex :: new ( RealTimeUpdates {
75- updates : Vec :: new ( ) ,
76- subscribers : HashMap :: new ( ) ,
77- } ) ) ,
78- performance_stats : Arc :: new ( Mutex :: new ( PerformanceStats {
7938 total_messages_sent: 0 ,
8039 total_messages_received: 0 ,
8140 average_processing_time_ms: 0 . 0 ,
@@ -107,7 +66,7 @@ impl WindAdvancedSync {
10766 let runtime = self . runtime . clone ( ) ;
10867
10968 tokio:: spawn ( async move {
110- let mut interval = interval ( Duration :: from_secs ( 5 ) ) ;
69+ let mut interval = tokio :: time :: interval ( Duration :: from_secs ( 5 ) ) ;
11170
11271 loop {
11372 interval. tick ( ) . await ;
@@ -128,7 +87,7 @@ impl WindAdvancedSync {
12887 sync. sync_status = Self :: calculate_sync_status ( & sync. synchronized_documents ) ;
12988
13089 // Emit sync event
131- let _ = runtime. emit (
90+ let _ = runtime. Environment . ApplicationHandle . emit (
13291 "mountain_sync_status_update" ,
13392 sync. sync_status . clone ( )
13493 ) ;
@@ -145,7 +104,7 @@ impl WindAdvancedSync {
145104 let runtime = self . runtime . clone ( ) ;
146105
147106 tokio:: spawn ( async move {
148- let mut interval = interval ( Duration :: from_secs ( 10 ) ) ;
107+ let mut interval = tokio :: time :: interval ( Duration :: from_secs ( 10 ) ) ;
149108
150109 loop {
151110 interval. tick ( ) . await ;
@@ -158,7 +117,7 @@ impl WindAdvancedSync {
158117 stats. connection_uptime += 10 ;
159118
160119 // Emit performance update
161- let _ = runtime. emit (
120+ let _ = runtime. Environment . ApplicationHandle . emit (
162121 "mountain_performance_update" ,
163122 stats. clone ( )
164123 ) ;
@@ -234,7 +193,7 @@ pub enum ChangeType {
234193}
235194
236195/// Sync state
237- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
196+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
238197pub enum SyncState {
239198 Synced ,
240199 Modified ,
@@ -407,51 +366,22 @@ impl WindAdvancedSync {
407366 // ADVANCED PERFORMANCE TRACKING: Microsoft-inspired initialization metrics
408367 let sync_duration = sync_start. elapsed ( ) ;
409368 info ! ( "[WindAdvancedSync] Initialization completed in {:.2}ms" , sync_duration. as_millis( ) ) ;
410-
411- Self {
412- runtime,
413- document_sync : Arc :: new ( Mutex :: new ( DocumentSynchronization {
414- synchronized_documents : HashMap :: new ( ) ,
415- pending_changes : HashMap :: new ( ) ,
416- last_sync_time : SystemTime :: now ( )
417- . duration_since ( SystemTime :: UNIX_EPOCH )
418- . unwrap_or_default ( )
419- . as_secs ( ) ,
420- sync_status : SyncStatus {
421- total_documents : 0 ,
422- synced_documents : 0 ,
423- conflicted_documents : 0 ,
424- offline_documents : 0 ,
425- last_sync_duration_ms : 0 ,
426- } ,
427- } ) ) ,
428- ui_state_sync : Arc :: new ( Mutex :: new ( UIStateSynchronization {
429- active_editor : None ,
430- cursor_positions : HashMap :: new ( ) ,
431- selection_ranges : HashMap :: new ( ) ,
432- view_state : ViewState {
433- zoom_level : 1.0 ,
434- sidebar_visible : true ,
435- panel_visible : false ,
436- status_bar_visible : true ,
437- } ,
438- theme : "dark" . to_string ( ) ,
439- layout : LayoutState {
440- editor_groups : Vec :: new ( ) ,
441- active_group : 0 ,
442- grid_layout : GridLayout {
443- rows : 1 ,
444- columns : 1 ,
445- cell_width : 100 ,
446- cell_height : 100 ,
447- } ,
448- } ,
449- } ) ) ,
450- real_time_updates : Arc :: new ( Mutex :: new ( RealTimeUpdates {
451- subscribers : HashMap :: new ( ) ,
452369 last_broadcast: 0 ,
453370 update_queue: Vec :: new ( ) ,
454371 } ) ) ,
372+ performance_stats: Arc :: new( Mutex :: new( PerformanceStats {
373+ total_memory_bytes: 0 ,
374+ used_memory_bytes: 0 ,
375+ cpu_usage_percent: 0 . 0 ,
376+ network_bytes_sent: 0 ,
377+ network_bytes_received: 0 ,
378+ disk_read_bytes: 0 ,
379+ disk_write_bytes: 0 ,
380+ process_count: 0 ,
381+ thread_count: 0 ,
382+ uptime_seconds: 0 ,
383+ last_update_timestamp: 0 ,
384+ } ) ) ,
455385 }
456386 }
457387
@@ -481,7 +411,7 @@ impl WindAdvancedSync {
481411
482412 /// Synchronize documents between Wind and Mountain
483413 async fn synchronize_documents ( & self ) {
484- let mut interval = interval ( Duration :: from_secs ( 5 ) ) ;
414+ let mut interval = tokio :: time :: interval ( Duration :: from_secs ( 5 ) ) ;
485415 let mut consecutive_failures = 0 ;
486416 let max_consecutive_failures = 3 ;
487417
@@ -510,7 +440,7 @@ impl WindAdvancedSync {
510440 consecutive_failures += 1 ;
511441 if consecutive_failures >= max_consecutive_failures {
512442 warn ! ( "[WindAdvancedSync] Too many consecutive failures, slowing sync interval" ) ;
513- interval = interval ( Duration :: from_secs ( 30 ) ) ; // Slow down
443+ interval = tokio :: time :: interval ( Duration :: from_secs ( 30 ) ) ; // Slow down
514444 }
515445 }
516446 }
@@ -519,7 +449,7 @@ impl WindAdvancedSync {
519449 // Reset failure counter on successful operations
520450 if success_count > 0 {
521451 consecutive_failures = 0 ;
522- interval = interval ( Duration :: from_secs ( 5 ) ) ; // Reset to normal interval
452+ interval = tokio :: time :: interval ( Duration :: from_secs ( 5 ) ) ; // Reset to normal interval
523453 }
524454
525455 // Update sync status
@@ -536,7 +466,7 @@ impl WindAdvancedSync {
536466
537467 /// Synchronize UI state
538468 async fn synchronize_ui_state ( & self ) {
539- let mut interval = interval ( Duration :: from_secs ( 1 ) ) ;
469+ let mut interval = tokio :: time :: interval ( Duration :: from_secs ( 1 ) ) ;
540470
541471 loop {
542472 interval. tick ( ) . await ;
@@ -555,7 +485,7 @@ impl WindAdvancedSync {
555485
556486 /// Broadcast real-time updates
557487 async fn broadcast_real_time_updates ( & self ) {
558- let mut interval = interval ( Duration :: from_millis ( 100 ) ) ;
488+ let mut interval = tokio :: time :: interval ( Duration :: from_millis ( 100 ) ) ;
559489
560490 loop {
561491 interval. tick ( ) . await ;
@@ -712,7 +642,7 @@ impl WindAdvancedSync {
712642 * sync = ui_state;
713643
714644 // Emit UI state update to Sky
715- if let Err ( e) = self . runtime . Environment . ApplicationHandle . emit ( "ui-state-update" , & sync) {
645+ if let Err ( e) = self . runtime . Environment . ApplicationHandle . emit ( "ui-state-update" , * sync) {
716646 error ! ( "[WindAdvancedSync] Failed to emit UI state update: {}" , e) ;
717647 }
718648
0 commit comments