Skip to content

Commit e3a63db

Browse files
committed
Using RxApp replace ViewAction
1 parent ef4a190 commit e3a63db

8 files changed

Lines changed: 16 additions & 35 deletions

File tree

v2rayN/ServiceLib/Enums/EViewAction.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ public enum EViewAction
66
ShowYesNo,
77
SaveFileDialog,
88
AddBatchRoutingRulesYesNo,
9-
AdjustMainLvColWidth,
109
SetClipboardData,
1110
AddServerViaClipboard,
1211
ImportRulesFromClipboard,

v2rayN/ServiceLib/Handler/AppEvents.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ public static class AppEvents
1313

1414
public static readonly Subject<Unit> AppExitRequested = new();
1515

16+
public static readonly Subject<Unit> AdjustMainLvColWidthRequested = new();
17+
1618
public static readonly Subject<ServerSpeedItem> DispatcherStatisticsRequested = new();
1719
}

v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private async Task UpdateTaskHandler(bool success, string msg)
268268
}
269269
if (_config.UiItem.EnableAutoAdjustMainLvColWidth)
270270
{
271-
_updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null);
271+
AppEvents.AdjustMainLvColWidthRequested.OnNext(Unit.Default);
272272
}
273273
}
274274
}

v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,6 @@ public async Task UpdateStatistics(ServerSpeedItem update)
348348
}
349349
}
350350

351-
public async Task AutofitColumnWidthAsync()
352-
{
353-
await _updateView?.Invoke(EViewAction.AdjustMainLvColWidth, null);
354-
}
355-
356351
#endregion Actions
357352

358353
#region Servers && Groups

v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,6 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
250250
await ViewModel.AddServerViaClipboardAsync(clipboardData);
251251
}
252252
break;
253-
254-
case EViewAction.AdjustMainLvColWidth:
255-
Dispatcher.UIThread.Post(() =>
256-
Locator.Current.GetService<ProfilesViewModel>()?.AutofitColumnWidthAsync(),
257-
DispatcherPriority.Default);
258-
break;
259253
}
260254

261255
return await Task.FromResult(true);

v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public ProfilesView(Window window)
103103
.ObserveOn(RxApp.MainThreadScheduler)
104104
.Subscribe(_ => StorageUI())
105105
.DisposeWith(disposables);
106+
107+
AppEvents.AdjustMainLvColWidthRequested
108+
.AsObservable()
109+
.ObserveOn(RxApp.MainThreadScheduler)
110+
.Subscribe(_ => AutofitColumnWidth())
111+
.DisposeWith(disposables);
106112
});
107113

108114
RestoreUI();
@@ -133,13 +139,6 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
133139
await AvaUtils.SetClipboardData(this, (string)obj);
134140
break;
135141

136-
case EViewAction.AdjustMainLvColWidth:
137-
Dispatcher.UIThread.Post(() =>
138-
AutofitColumnWidth(),
139-
DispatcherPriority.Default);
140-
141-
break;
142-
143142
case EViewAction.ProfilesFocus:
144143
lstProfiles.Focus();
145144
break;

v2rayN/v2rayN/Views/MainWindow.xaml.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,6 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
234234
ViewModel?.AddServerViaClipboardAsync(clipboardData);
235235
}
236236
break;
237-
238-
case EViewAction.AdjustMainLvColWidth:
239-
Application.Current?.Dispatcher.Invoke((() =>
240-
{
241-
Locator.Current.GetService<ProfilesViewModel>()?.AutofitColumnWidthAsync();
242-
}), DispatcherPriority.Normal);
243-
break;
244237
}
245238

246239
return await Task.FromResult(true);

v2rayN/v2rayN/Views/ProfilesView.xaml.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public ProfilesView()
9797
.ObserveOn(RxApp.MainThreadScheduler)
9898
.Subscribe(_ => StorageUI())
9999
.DisposeWith(disposables);
100+
101+
AppEvents.AdjustMainLvColWidthRequested
102+
.AsObservable()
103+
.ObserveOn(RxApp.MainThreadScheduler)
104+
.Subscribe(_ => AutofitColumnWidth())
105+
.DisposeWith(disposables);
100106
});
101107

102108
RestoreUI();
@@ -113,14 +119,7 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
113119
if (obj is null)
114120
return false;
115121
WindowsUtils.SetClipboardData((string)obj);
116-
break;
117-
118-
case EViewAction.AdjustMainLvColWidth:
119-
Application.Current?.Dispatcher.Invoke((() =>
120-
{
121-
AutofitColumnWidth();
122-
}), DispatcherPriority.Normal);
123-
break;
122+
break;
124123

125124
case EViewAction.ProfilesFocus:
126125
lstProfiles.Focus();

0 commit comments

Comments
 (0)