mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
UI - Use Timer instead of DispatcherTimer where feasible
This commit is contained in:
1 parent
4ffe8d8848
commit
fa710777d7
7 files changed
+42
-52
No files matched your search
@@ -2,11 +2,11 @@
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Timers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Avalonia.Threading;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Playback;
|
||||
@@ -53,13 +53,17 @@ public class PlaybackViewModel : ActivatableViewModelBase
|
||||
_formattedCurrentTime = _profileEditorService.Time.Select(t => $"{Math.Floor(t.TotalSeconds):00}.{t.Milliseconds:000}").ToProperty(this, vm => vm.FormattedCurrentTime).DisposeWith(d);
|
||||
_playing = _profileEditorService.Playing.ToProperty(this, vm => vm.Playing).DisposeWith(d);
|
||||
_keyBindingsEnabled = Shared.UI.KeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
|
||||
|
||||
|
||||
// Update timer
|
||||
Timer updateTimer = new(TimeSpan.FromMilliseconds(60.0 / 1000));
|
||||
updateTimer.Elapsed += (_, _) => Update();
|
||||
updateTimer.DisposeWith(d);
|
||||
_profileEditorService.Playing.Subscribe(_ => _lastUpdate = DateTime.Now).DisposeWith(d);
|
||||
_profileEditorService.Playing.Subscribe(p => updateTimer.Enabled = p).DisposeWith(d);
|
||||
_lastUpdate = DateTime.MinValue;
|
||||
DispatcherTimer updateTimer = new(TimeSpan.FromMilliseconds(60.0 / 1000), DispatcherPriority.Background, Update);
|
||||
updateTimer.Start();
|
||||
|
||||
Disposable.Create(() =>
|
||||
{
|
||||
updateTimer.Stop();
|
||||
_settingsService.GetSetting("ProfileEditor.RepeatTimeline", true).Value = _repeating && _repeatTimeline;
|
||||
_settingsService.GetSetting("ProfileEditor.RepeatSegment", false).Value = _repeating && _repeatSegment;
|
||||
}).DisposeWith(d);
|
||||
@@ -206,13 +210,10 @@ public class PlaybackViewModel : ActivatableViewModelBase
|
||||
return TimeSpan.Zero;
|
||||
}
|
||||
|
||||
private void Update(object? sender, EventArgs e)
|
||||
private void Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Playing)
|
||||
return;
|
||||
|
||||
if (_lastUpdate == DateTime.MinValue)
|
||||
_lastUpdate = DateTime.Now;
|
||||
|
||||
|
||||
+9
-12
@@ -2,6 +2,7 @@
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.DryIoc.Factories;
|
||||
@@ -50,20 +51,16 @@ public class DataBindingViewModel : ActivatableViewModelBase
|
||||
.DisposeWith(d);
|
||||
_profileEditorService.Playing.CombineLatest(_profileEditorService.SuspendedEditing).Subscribe(tuple => _playing = tuple.First || tuple.Second).DisposeWith(d);
|
||||
|
||||
DispatcherTimer updateTimer = new(TimeSpan.FromMilliseconds(25.0 / 1000), DispatcherPriority.Background, Update);
|
||||
// TODO: Remove in favor of saving each time a node editor command is executed
|
||||
DispatcherTimer saveTimer = new(TimeSpan.FromMinutes(2), DispatcherPriority.Normal, Save);
|
||||
Timer updateTimer = new(TimeSpan.FromMilliseconds(25.0 / 1000));
|
||||
Timer saveTimer = new(TimeSpan.FromMinutes(2));
|
||||
|
||||
updateTimer.Elapsed += (_, _) => Update();
|
||||
saveTimer.Elapsed += (_, _) => Save();
|
||||
updateTimer.Start();
|
||||
saveTimer.Start();
|
||||
|
||||
Disposable.Create(() =>
|
||||
{
|
||||
updateTimer.Stop();
|
||||
saveTimer.Stop();
|
||||
|
||||
_profileEditorService.SaveProfile();
|
||||
}).DisposeWith(d);
|
||||
updateTimer.DisposeWith(d);
|
||||
saveTimer.DisposeWith(d);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,7 +94,7 @@ public class DataBindingViewModel : ActivatableViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
private void Update(object? sender, EventArgs e)
|
||||
private void Update()
|
||||
{
|
||||
// If playing the data binding will already be updated, no need to do it here
|
||||
if (_playing || !_alwaysApplyDataBindings.Value)
|
||||
@@ -106,7 +103,7 @@ public class DataBindingViewModel : ActivatableViewModelBase
|
||||
LayerProperty?.UpdateDataBinding();
|
||||
}
|
||||
|
||||
private void Save(object? sender, EventArgs e)
|
||||
private void Save()
|
||||
{
|
||||
if (!_editorOpen)
|
||||
_profileEditorService.SaveProfile();
|
||||
|
||||
Reference in new issue
Block a user