AI-optimized code

This commit is contained in:
2dust 2025-03-06 14:53:25 +08:00
parent 51e5885e76
commit 7e348c196e
5 changed files with 20 additions and 10 deletions

View file

@ -23,7 +23,7 @@ public partial class App : Application
var ViewModel = new StatusBarViewModel(null);
Locator.CurrentMutable.RegisterLazySingleton(() => ViewModel, typeof(StatusBarViewModel));
this.DataContext = ViewModel;
DataContext = ViewModel;
}
public override void OnFrameworkInitializationCompleted()
@ -65,16 +65,20 @@ public partial class App : Application
var clipboardData = await AvaUtils.GetClipboardData(desktop.MainWindow);
var service = Locator.Current.GetService<MainWindowViewModel>();
if (service != null)
{
_ = service.AddServerViaClipboardAsync(clipboardData);
}
}
}
}
private async void MenuExit_Click(object? sender, EventArgs e)
{
var service = Locator.Current.GetService<MainWindowViewModel>();
if (service != null)
{
await service.MyAppExitAsync(true);
}
service?.Shutdown(true);
}
}

View file

@ -19,7 +19,9 @@ namespace v2rayN.Desktop.Common
{
var sp = GetStorageProvider(owner);
if (sp is null)
{
return null;
}
// Start async operation to open the dialog.
var files = await sp.OpenFilePickerAsync(new FilePickerOpenOptions
@ -35,7 +37,9 @@ namespace v2rayN.Desktop.Common
{
var sp = GetStorageProvider(owner);
if (sp is null)
{
return null;
}
// Start async operation to open the dialog.
var files = await sp.SaveFilePickerAsync(new FilePickerSaveOptions

View file

@ -27,7 +27,9 @@ public class AutoCompleteBox : Avalonia.Controls.AutoCompleteBox
{
base.OnGotFocus(e);
if (IsDropDownOpen)
{
return;
}
SetCurrentValue(IsDropDownOpenProperty, true);
}

View file

@ -8,14 +8,14 @@ namespace v2rayN.Desktop.Converters
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
int.TryParse(value?.ToString(), out var delay);
_ = int.TryParse(value?.ToString(), out var delay);
if (delay <= 0)
return new SolidColorBrush(Colors.Red);
if (delay <= 500)
return new SolidColorBrush(Colors.Green);
else
return new SolidColorBrush(Colors.IndianRed);
return delay switch
{
<= 0 => new SolidColorBrush(Colors.Red),
<= 500 => new SolidColorBrush(Colors.Green),
_ => new SolidColorBrush(Colors.IndianRed)
};
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)

View file

@ -25,8 +25,8 @@ internal class Program
if (Utils.IsWindows())
{
var exePathKey = Utils.GetMd5(Utils.GetExePath());
var rebootas = (Args ?? Array.Empty<string>()).Any(t => t == Global.RebootAs);
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out bool bCreatedNew);
var rebootas = (Args ?? []).Any(t => t == Global.RebootAs);
ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out var bCreatedNew);
if (!rebootas && !bCreatedNew)
{
ProgramStarted.Set();