Code clean

This commit is contained in:
2dust
2025-11-02 15:25:41 +08:00
parent b218f0b501
commit ab6a6b879e
45 changed files with 326 additions and 52 deletions
+3
View File
@@ -28,7 +28,10 @@ internal class AvaUtils
{
var clipboard = TopLevel.GetTopLevel(visual)?.Clipboard;
if (clipboard == null)
{
return;
}
await clipboard.SetTextAsync(strData);
}
catch
@@ -6,7 +6,7 @@ public class DelayColorConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
_ = int.TryParse(value?.ToString(), out var delay);
var delay = value.ToString().ToInt();
return delay switch
{
@@ -95,7 +95,9 @@ public class ThemeSettingViewModel : MyReactiveObject
{
double size = CurrentFontSize;
if (size < Global.MinFontSize)
{
return;
}
Style style = new(x => Selectors.Or(
x.OfType<Button>(),
@@ -95,7 +95,9 @@ public partial class AddGroupServerWindow : WindowBase<AddGroupServerViewModel>
private void AddGroupServerWindow_KeyDown(object? sender, KeyEventArgs e)
{
if (!lstChild.IsKeyboardFocusWithin)
{
return;
}
if ((e.KeyModifiers & (KeyModifiers.Control | KeyModifiers.Meta)) != 0)
{
@@ -22,8 +22,8 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
_manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.TopRight };
KeyDown += MainWindow_KeyDown;
menuSettingsSetUWP.Click += menuSettingsSetUWP_Click;
menuPromotion.Click += menuPromotion_Click;
menuSettingsSetUWP.Click += MenuSettingsSetUWP_Click;
menuPromotion.Click += MenuPromotion_Click;
menuCheckUpdate.Click += MenuCheckUpdate_Click;
menuBackupAndRestore.Click += MenuBackupAndRestore_Click;
menuClose.Click += MenuClose_Click;
@@ -188,6 +188,7 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
private async Task DelegateSnackMsg(string content)
{
_manager?.Show(new Notification(null, content, NotificationType.Information));
await Task.CompletedTask;
}
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
@@ -196,17 +197,26 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
{
case EViewAction.AddServerWindow:
if (obj is null)
{
return false;
}
return await new AddServerWindow((ProfileItem)obj).ShowDialog<bool>(this);
case EViewAction.AddServer2Window:
if (obj is null)
{
return false;
}
return await new AddServer2Window((ProfileItem)obj).ShowDialog<bool>(this);
case EViewAction.AddGroupServerWindow:
if (obj is null)
{
return false;
}
return await new AddGroupServerWindow((ProfileItem)obj).ShowDialog<bool>(this);
case EViewAction.DNSSettingWindow:
@@ -308,12 +318,12 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
}
}
private void menuPromotion_Click(object? sender, RoutedEventArgs e)
private void MenuPromotion_Click(object? sender, RoutedEventArgs e)
{
ProcUtils.ProcessStart($"{Utils.Base64Decode(Global.PromotionUrl)}?t={DateTime.Now.Ticks}");
}
private void menuSettingsSetUWP_Click(object? sender, RoutedEventArgs e)
private void MenuSettingsSetUWP_Click(object? sender, RoutedEventArgs e)
{
ProcUtils.ProcessStart(Utils.GetBinPath("EnableLoopback.exe"));
}
@@ -478,8 +488,8 @@ public partial class MainWindow : WindowBase<MainWindowViewModel>
{
var coreInfo = CoreInfoManager.Instance.GetCoreInfo();
foreach (var it in coreInfo
.Where(t => t.CoreType != ECoreType.v2fly
&& t.CoreType != ECoreType.hysteria))
.Where(t => t.CoreType is not ECoreType.v2fly
and not ECoreType.hysteria))
{
var item = new MenuItem()
{
@@ -30,7 +30,9 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
{
case EViewAction.DispatcherShowMsg:
if (obj is null)
{
return false;
}
Dispatcher.UIThread.Post(() => ShowMsg(obj),
DispatcherPriority.ApplicationIdle);
@@ -124,7 +124,10 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
{
case EViewAction.SetClipboardData:
if (obj is null)
{
return false;
}
await AvaUtils.SetClipboardData(this, (string)obj);
break;
@@ -141,7 +144,10 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
case EViewAction.SaveFileDialog:
if (obj is null)
{
return false;
}
var fileName = await UI.SaveFileDialog(_window, "");
if (fileName.IsNullOrEmpty())
{
@@ -152,28 +158,43 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
case EViewAction.AddServerWindow:
if (obj is null)
{
return false;
}
return await new AddServerWindow((ProfileItem)obj).ShowDialog<bool>(_window);
case EViewAction.AddServer2Window:
if (obj is null)
{
return false;
}
return await new AddServer2Window((ProfileItem)obj).ShowDialog<bool>(_window);
case EViewAction.AddGroupServerWindow:
if (obj is null)
{
return false;
}
return await new AddGroupServerWindow((ProfileItem)obj).ShowDialog<bool>(_window);
case EViewAction.ShareServer:
if (obj is null)
{
return false;
}
await ShareServer((string)obj);
break;
case EViewAction.SubEditWindow:
if (obj is null)
{
return false;
}
return await new SubEditWindow((SubItem)obj).ShowDialog<bool>(_window);
case EViewAction.DispatcherRefreshServersBiz:
@@ -215,14 +236,17 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
{
var source = e.Source as Border;
if (source?.Name == "HeaderBackground")
{
return;
}
if (_config.UiItem.DoubleClick2Activate)
{
ViewModel?.SetDefaultServer();
}
else
{
ViewModel?.EditServerAsync(EConfigType.Custom);
ViewModel?.EditServerAsync();
}
}
@@ -263,7 +287,7 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
break;
case Key.D:
ViewModel?.EditServerAsync(EConfigType.Custom);
ViewModel?.EditServerAsync();
break;
case Key.F:
@@ -83,7 +83,10 @@ public partial class RoutingRuleSettingWindow : WindowBase<RoutingRuleSettingVie
case EViewAction.RoutingRuleDetailsWindow:
if (obj is null)
{
return false;
}
return await new RoutingRuleDetailsWindow((RulesItem)obj).ShowDialog<bool>(this);
case EViewAction.ImportRulesFromFile:
@@ -60,7 +60,10 @@ public partial class RoutingSettingWindow : WindowBase<RoutingSettingViewModel>
case EViewAction.RoutingRuleSettingWindow:
if (obj is null)
{
return false;
}
return await new RoutingRuleSettingWindow((RoutingItem)obj).ShowDialog<bool>(this);
}
return await Task.FromResult(true);
@@ -56,7 +56,10 @@ public partial class StatusBarView : ReactiveUserControl<StatusBarViewModel>
case EViewAction.SetClipboardData:
if (obj is null)
{
return false;
}
await AvaUtils.SetClipboardData(this, (string)obj);
break;
@@ -49,14 +49,20 @@ public partial class SubSettingWindow : WindowBase<SubSettingViewModel>
case EViewAction.SubEditWindow:
if (obj is null)
{
return false;
}
var window = new SubEditWindow((SubItem)obj);
await window.ShowDialog(this);
break;
case EViewAction.ShareSub:
if (obj is null)
{
return false;
}
await ShareSub((string)obj);
break;
}