Files
DHR60 9664ee380e ViewModel-First (#9621)
* Interaction

* Remove view action

* ViewModel-first

* MainGirdOrientation Hot Reload

* Fix avalonia preview

* Remove CloseWindowInteraction

* Fix

* Avoid threading issues

* Fix

* ProfilesSelect

* Try fix previewer

* Remove AppEvents.ProfilesRefreshRequested

* Remove AppEvents.SubscriptionsRefreshRequested

* Remove AppEvents.ProxiesReloadRequested

* Remove AppEvents.AdjustMainLvColWidthRequested

* Remove AppEvents.SetDefaultServerRequested

* Remove AppEvents.RoutingsMenuRefreshRequested

* Remove AppEvents.TestServerRequested

* Remove AppEvents.InboundDisplayRequested

* Remove AppEvents.SubscriptionsUpdateRequested

* Remove AppEvents.ShowHideWindowRequested

* Remove AppEvents.ReloadRequested

* Remove AppEvents.AddServerRequested

* Fix
2026-07-14 09:05:05 +08:00

60 lines
1.7 KiB
C#

using Avalonia.Platform.Storage;
using v2rayN.Desktop.Manager;
using v2rayN.Desktop.Views;
namespace v2rayN.Desktop.Common;
internal class UI
{
private static readonly string caption = Global.AppName;
public static async Task<ButtonResult> ShowYesNo(string msg)
{
var owner = WindowDialog.TryGetOwnerWindow();
var box = new MessageBoxDialog(caption, msg);
var result = await box.ShowDialog<ButtonResult>(owner);
return result == ButtonResult.Yes ? ButtonResult.Yes : ButtonResult.No;
}
public static async Task<string?> OpenFileDialog(FilePickerFileType? filter)
{
var sp = GetStorageProvider();
if (sp is null)
{
return null;
}
// Start async operation to open the dialog.
var files = await sp.OpenFilePickerAsync(new FilePickerOpenOptions
{
AllowMultiple = false,
FileTypeFilter = filter is null ? [FilePickerFileTypes.All, FilePickerFileTypes.ImagePng] : [filter]
});
return files.FirstOrDefault()?.TryGetLocalPath();
}
public static async Task<string?> SaveFileDialog(string filter)
{
var sp = GetStorageProvider();
if (sp is null)
{
return null;
}
// Start async operation to open the dialog.
var files = await sp.SaveFilePickerAsync(new FilePickerSaveOptions
{
});
return files?.TryGetLocalPath();
}
private static IStorageProvider? GetStorageProvider()
{
var owner = WindowDialog.TryGetOwnerWindow();
var topLevel = TopLevel.GetTopLevel(owner);
return topLevel?.StorageProvider;
}
}