mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-10-06 17:08:55 +02:00
misc: Tweak NullReferenceException fixes
This commit is contained in:
@@ -88,7 +88,8 @@ namespace Ryujinx.Ava.UI.Models
|
||||
private void UpdateBackground()
|
||||
{
|
||||
var currentApplication = Avalonia.Application.Current;
|
||||
currentApplication!.Styles.TryGetResource("ControlFillColorSecondary", currentApplication.ActualThemeVariant, out object color);
|
||||
object color = null;
|
||||
currentApplication?.Styles.TryGetResource("ControlFillColorSecondary", currentApplication.ActualThemeVariant, out color);
|
||||
|
||||
if (color is not null)
|
||||
{
|
||||
|
||||
@@ -525,16 +525,16 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
{
|
||||
ProfilesList.Clear();
|
||||
|
||||
string basePath = GetProfileBasePath() ?? string.Empty;
|
||||
string basePath = GetProfileBasePath();
|
||||
|
||||
if (!Directory.Exists(basePath))
|
||||
{
|
||||
Directory.CreateDirectory(basePath);
|
||||
Directory.CreateDirectory(basePath ?? string.Empty);
|
||||
}
|
||||
|
||||
ProfilesList.Add((LocaleManager.Instance[LocaleKeys.ControllerSettingsProfileDefault]));
|
||||
|
||||
foreach (string profile in Directory.GetFiles(basePath, "*.json", SearchOption.AllDirectories))
|
||||
foreach (string profile in Directory.GetFiles(basePath ?? string.Empty, "*.json", SearchOption.AllDirectories))
|
||||
{
|
||||
ProfilesList.Add(Path.GetFileNameWithoutExtension(profile));
|
||||
}
|
||||
|
||||
@@ -1555,11 +1555,11 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||
|
||||
private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
|
||||
{
|
||||
if (ShowMenuAndStatusBar && !ShowLoadProgress)
|
||||
if (ShowMenuAndStatusBar && !ShowLoadProgress && Application.Current != null)
|
||||
{
|
||||
Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
Application.Current!.Styles.TryGetResource(args.VSyncMode,
|
||||
Application.Current.Styles.TryGetResource(args.VSyncMode,
|
||||
Application.Current.ActualThemeVariant,
|
||||
out object color);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ using Ryujinx.Ava.UI.ViewModels.Input;
|
||||
using Ryujinx.Common.Configuration.Hid.Controller;
|
||||
using Ryujinx.Input;
|
||||
using Ryujinx.Input.Assigner;
|
||||
using System;
|
||||
using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
|
||||
|
||||
namespace Ryujinx.Ava.UI.Views.Input
|
||||
@@ -68,14 +69,12 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
|
||||
if (_changeSlider != -1.0f && _changeSlider != (float)check.Value)
|
||||
{
|
||||
if (DataContext is ControllerInputViewModel viewModel)
|
||||
{
|
||||
viewModel.ParentModel.IsModified = true;
|
||||
}
|
||||
|
||||
var viewModel = (DataContext as ControllerInputViewModel);
|
||||
if (viewModel != null)
|
||||
{
|
||||
viewModel.ParentModel.IsModified = true;
|
||||
}
|
||||
|
||||
_changeSlider = (float)check.Value;
|
||||
_changeSlider = (float)check.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +118,10 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
|
||||
PointerPressed += MouseClick;
|
||||
|
||||
var viewModel = (DataContext as ControllerInputViewModel);
|
||||
if (DataContext is not ControllerInputViewModel viewModel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IKeyboard keyboard = (IKeyboard)viewModel.ParentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
|
||||
IButtonAssigner assigner = CreateButtonAssigner(isStick);
|
||||
@@ -234,13 +236,14 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
|
||||
private IButtonAssigner CreateButtonAssigner(bool forStick)
|
||||
{
|
||||
IButtonAssigner assigner;
|
||||
if (DataContext is not ControllerInputViewModel controllerInputViewModel)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var controllerInputViewModel = DataContext as ControllerInputViewModel;
|
||||
|
||||
assigner = new GamepadButtonAssigner(
|
||||
controllerInputViewModel?.ParentModel.SelectedGamepad,
|
||||
(controllerInputViewModel.ParentModel.Config as StandardControllerInputConfig).TriggerThreshold,
|
||||
IButtonAssigner assigner = new GamepadButtonAssigner(
|
||||
controllerInputViewModel.ParentModel.SelectedGamepad,
|
||||
((StandardControllerInputConfig)controllerInputViewModel.ParentModel.Config).TriggerThreshold,
|
||||
forStick);
|
||||
|
||||
return assigner;
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Ryujinx.Ava.UI.Views.Settings
|
||||
{
|
||||
base.OnPointerReleased(e);
|
||||
|
||||
if (!_currentAssigner?.ToggledButton?.IsPointerOver ?? false)
|
||||
if (!_currentAssigner?.ToggledButton.IsPointerOver ?? false)
|
||||
{
|
||||
_currentAssigner.Cancel();
|
||||
}
|
||||
|
||||
@@ -63,25 +63,27 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||
|
||||
private async void Import_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var window = this.GetVisualRoot() as Window;
|
||||
var result = await window?.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
if (this.GetVisualRoot() is Window window)
|
||||
{
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = new List<FilePickerFileType>
|
||||
var result = await window.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
new(LocaleManager.Instance[LocaleKeys.AllSupportedFormats])
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = new List<FilePickerFileType>
|
||||
{
|
||||
Patterns = ["*.jpg", "*.jpeg", "*.png", "*.bmp"],
|
||||
AppleUniformTypeIdentifiers = ["public.jpeg", "public.png", "com.microsoft.bmp"],
|
||||
MimeTypes = ["image/jpeg", "image/png", "image/bmp"],
|
||||
new(LocaleManager.Instance[LocaleKeys.AllSupportedFormats])
|
||||
{
|
||||
Patterns = ["*.jpg", "*.jpeg", "*.png", "*.bmp"],
|
||||
AppleUniformTypeIdentifiers = ["public.jpeg", "public.png", "com.microsoft.bmp"],
|
||||
MimeTypes = ["image/jpeg", "image/png", "image/bmp"],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
if (result.Count > 0)
|
||||
{
|
||||
_profile.Image = ProcessProfileImage(File.ReadAllBytes(result[0].Path.LocalPath));
|
||||
_parent.GoBack();
|
||||
if (result.Count > 0)
|
||||
{
|
||||
_profile.Image = ProcessProfileImage(File.ReadAllBytes(result[0].Path.LocalPath));
|
||||
_parent.GoBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,10 @@ namespace Ryujinx.Ava.UI.Views.User
|
||||
|
||||
if (arg.NavigationMode == NavigationMode.Back)
|
||||
{
|
||||
((ContentDialog)_parent.Parent).Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle];
|
||||
if (_parent.Parent != null)
|
||||
{
|
||||
((ContentDialog)_parent.Parent).Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle];
|
||||
}
|
||||
}
|
||||
|
||||
DataContext = ViewModel;
|
||||
|
||||
@@ -516,12 +516,16 @@ namespace Ryujinx.Ava.UI.Windows
|
||||
|
||||
ApplicationLibrary.ApplicationCountUpdated += ApplicationLibrary_ApplicationCountUpdated;
|
||||
_appLibraryAppsSubscription?.Dispose();
|
||||
_appLibraryAppsSubscription = ApplicationLibrary.Applications
|
||||
if (SynchronizationContext.Current != null)
|
||||
{
|
||||
_appLibraryAppsSubscription = ApplicationLibrary.Applications
|
||||
.Connect()
|
||||
.ObserveOn(SynchronizationContext.Current)
|
||||
.Bind(ViewModel.Applications)
|
||||
.OnItemAdded(UpdateApplicationWithLdnData)
|
||||
.Subscribe();
|
||||
}
|
||||
|
||||
ApplicationLibrary.LdnGameDataReceived += ApplicationLibrary_LdnGameDataReceived;
|
||||
|
||||
ConfigurationState.Instance.Multiplayer.Mode.Event += (sender, evt) =>
|
||||
@@ -581,7 +585,7 @@ namespace Ryujinx.Ava.UI.Windows
|
||||
var volumeSplitButton = sender as ToggleSplitButton;
|
||||
if (ViewModel.IsGameRunning)
|
||||
{
|
||||
if (volumeSplitButton is not { IsChecked: true })
|
||||
if (volumeSplitButton is { IsChecked: false })
|
||||
{
|
||||
ViewModel.AppHost.Device.SetVolume(ViewModel.VolumeBeforeMute);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user