diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index 9465e6a2..ee66351c 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -11,6 +11,9 @@ namespace ServiceLib.ViewModels; public class StatusBarViewModel : MyReactiveObject { + private static readonly Lazy _instance = new(() => new(null)); + public static StatusBarViewModel Instance => _instance.Value; + #region ObservableCollection public IObservableCollection RoutingItems { get; } = new ObservableCollectionExtended(); diff --git a/v2rayN/v2rayN.Desktop/App.axaml.cs b/v2rayN/v2rayN.Desktop/App.axaml.cs index aa357ca4..515354d5 100644 --- a/v2rayN/v2rayN.Desktop/App.axaml.cs +++ b/v2rayN/v2rayN.Desktop/App.axaml.cs @@ -16,9 +16,7 @@ public partial class App : Application AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; - var ViewModel = new StatusBarViewModel(null); - Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel)); - DataContext = ViewModel; + DataContext = StatusBarViewModel.Instance; } public override void OnFrameworkInitializationCompleted() diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 532bda6f..eb884e4b 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -20,7 +20,7 @@ namespace v2rayN.Desktop.Views; public partial class MainWindow : WindowBase { private static Config _config; - private WindowNotificationManager? _manager; + private readonly WindowNotificationManager? _manager; private CheckUpdateView? _checkUpdateView; private BackupAndRestoreView? _backupAndRestoreView; private bool _blCloseByUser = false; diff --git a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs index 3eb08f96..976c156d 100644 --- a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs @@ -6,7 +6,6 @@ using Avalonia.ReactiveUI; using Avalonia.Threading; using DialogHostAvalonia; using ReactiveUI; -using Splat; using v2rayN.Desktop.Common; namespace v2rayN.Desktop.Views; @@ -20,9 +19,8 @@ public partial class StatusBarView : ReactiveUserControl InitializeComponent(); _config = AppManager.Instance.Config; - //ViewModel = new StatusBarViewModel(UpdateViewHandler); - //Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel)); - ViewModel = Locator.Current.GetService(); + + ViewModel = StatusBarViewModel.Instance; ViewModel?.InitUpdateView(UpdateViewHandler); txtRunningServerDisplay.Tapped += TxtRunningServerDisplay_Tapped; diff --git a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs index f9b551c2..1d80a694 100644 --- a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs +++ b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs @@ -15,7 +15,8 @@ public partial class StatusBarView { InitializeComponent(); _config = AppManager.Instance.Config; - ViewModel = new StatusBarViewModel(UpdateViewHandler); + ViewModel = StatusBarViewModel.Instance; + ViewModel?.InitUpdateView(UpdateViewHandler); menuExit.Click += menuExit_Click; txtRunningServerDisplay.PreviewMouseDown += txtRunningInfoDisplay_MouseDoubleClick;