1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Linux - Fix crash in keyframes

This commit is contained in:
Robert 2024-03-25 20:41:15 +01:00
parent 257fa8ae0d
commit 107b604c86
2 changed files with 15 additions and 16 deletions

View File

@ -34,7 +34,7 @@ public abstract partial class TreeItemViewModel : ActivatableViewModelBase
private RenderProfileElement? _currentProfileElement; private RenderProfileElement? _currentProfileElement;
private ObservableAsPropertyHelper<bool>? _isFocused; private ObservableAsPropertyHelper<bool>? _isFocused;
private TimeSpan _time; private TimeSpan _time;
[Notify] private bool _canPaste; [Notify] private bool _canPaste;
[Notify] private bool _isExpanded; [Notify] private bool _isExpanded;
[Notify] private bool _isFlyoutOpen; [Notify] private bool _isFlyoutOpen;
@ -100,7 +100,7 @@ public abstract partial class TreeItemViewModel : ActivatableViewModelBase
public ReactiveCommand<Unit, Unit> Paste { get; } public ReactiveCommand<Unit, Unit> Paste { get; }
public ReactiveCommand<Unit, Unit> Delete { get; } public ReactiveCommand<Unit, Unit> Delete { get; }
public abstract bool SupportsChildren { get; } public abstract bool SupportsChildren { get; }
public async Task ShowBrokenStateExceptions() public async Task ShowBrokenStateExceptions()
{ {
if (ProfileElement == null) if (ProfileElement == null)
@ -117,7 +117,7 @@ public abstract partial class TreeItemViewModel : ActivatableViewModelBase
return; return;
} }
} }
public void InsertElement(TreeItemViewModel elementViewModel, int targetIndex) public void InsertElement(TreeItemViewModel elementViewModel, int targetIndex)
{ {
if (elementViewModel.Parent == this && Children.IndexOf(elementViewModel) == targetIndex) if (elementViewModel.Parent == this && Children.IndexOf(elementViewModel) == targetIndex)
@ -239,26 +239,22 @@ public abstract partial class TreeItemViewModel : ActivatableViewModelBase
await _windowService.ShowDialogAsync<LayerHintsDialogViewModel, bool>(layer); await _windowService.ShowDialogAsync<LayerHintsDialogViewModel, bool>(layer);
await ProfileEditorService.SaveProfileAsync(); await ProfileEditorService.SaveProfileAsync();
} }
private void ExecuteApplyAdaptionHints() private void ExecuteApplyAdaptionHints()
{ {
if (ProfileElement is not Layer layer) if (ProfileElement is not Layer layer)
return; return;
ProfileEditorService.ExecuteCommand(new ApplyAdaptionHints(layer, _deviceService.EnabledDevices.ToList())); ProfileEditorService.ExecuteCommand(new ApplyAdaptionHints(layer, _deviceService.EnabledDevices.ToList()));
} }
private async void UpdateCanPaste(bool isFlyoutOpen) private async void UpdateCanPaste(bool isFlyoutOpen)
{ {
string[] formats = await Shared.UI.Clipboard.GetFormatsAsync(); string[]? formats = await Shared.UI.Clipboard.GetFormatsAsync();
//diogotr7: This can be null on Linux sometimes. I'm not sure why.
if (formats == null!) // Can be null on some platforms
{ // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
CanPaste = false; CanPaste = formats != null && formats.Contains(ProfileElementExtensions.ClipboardDataFormat);
return;
}
CanPaste = formats.Contains(ProfileElementExtensions.ClipboardDataFormat);
} }
private bool GetIsFocused(ProfileEditorFocusMode focusMode, RenderProfileElement? currentProfileElement) private bool GetIsFocused(ProfileEditorFocusMode focusMode, RenderProfileElement? currentProfileElement)

View File

@ -174,8 +174,11 @@ public partial class TimelineKeyframeViewModel<T> : ActivatableViewModelBase, IT
private async void UpdateCanPaste(bool isFlyoutOpen) private async void UpdateCanPaste(bool isFlyoutOpen)
{ {
string[] formats = await Shared.UI.Clipboard.GetFormatsAsync(); string[]? formats = await Shared.UI.Clipboard.GetFormatsAsync();
CanPaste = formats.Contains("Artemis.Keyframes");
// Can be null on some platforms
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
CanPaste = formats != null && formats.Contains("Artemis.Keyframes");
} }
#endregion #endregion