From abc3290e41efda2fed154fdba390fc95ab0a9876 Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Tue, 10 Nov 2026 17:49:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=BC=80=E5=A7=8B=E5=BD=95=E5=83=8F?= =?UTF-8?q?=E5=92=8C=E5=81=9C=E6=AD=A2=E5=BD=95=E5=83=8F=E6=8B=86=E5=88=86?= =?UTF-8?q?=E4=B8=BA=E7=8B=AC=E7=AB=8B=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Training/CameraViewModel.cs | 15 +++---- .../Training/CameraWindow.axaml | 3 +- .../VVMs/RecipeEditor/RecipeEditor.axaml | 12 ++++-- tests/RecordingLimit.Smoke/Program.cs | 42 ++++++++++++++----- 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/SopHelper.Avalonia/Training/CameraViewModel.cs b/src/SopHelper.Avalonia/Training/CameraViewModel.cs index 89d6016..b74b979 100644 --- a/src/SopHelper.Avalonia/Training/CameraViewModel.cs +++ b/src/SopHelper.Avalonia/Training/CameraViewModel.cs @@ -59,13 +59,13 @@ public sealed class CameraViewModel : BindableBase public Func>? ConfirmRestartAsync { get; set; } public bool CanChangeDirectory => _recipeRecordingDirectory is null && !IsBusy && !IsRecording && !_closing; public string PreviewButtonText => IsPreviewing ? "关闭相机" : "开启相机预览"; - public string RecordButtonText => IsRecording ? "停止录像" : "开始录像"; public string RecordingInfo { get => _recordingInfo; private set => SetProperty(ref _recordingInfo, value); } public string SaveDirectory { get => _directory; set => SetProperty(ref _directory, _recipeRecordingDirectory ?? value); } public string LastRecording { get => _lastRecording; private set { SetProperty(ref _lastRecording, value); UpdateCommands(); } } public double RecordingFps { get; set; } = 30; public DelegateCommand PreviewCommand { get; } - public DelegateCommand RecordCommand { get; } + public DelegateCommand StartRecordingCommand { get; } + public DelegateCommand StopRecordingCommand { get; } public DelegateCommand BrowseCommand { get; } public DelegateCommand RevealCommand { get; } public DelegateCommand PauseCommand { get; } @@ -91,7 +91,8 @@ public sealed class CameraViewModel : BindableBase } catch (Exception e) { Status = "录像目录配置读取失败:" + e.Message; } PreviewCommand = Command(TogglePreviewAsync, () => !IsBusy && !_closing && (IsPreviewing || SelectedCamera != null)); - RecordCommand = Command(ToggleRecordingAsync, () => !IsBusy && !_closing && (IsRecording || (!HasStandardVideo && IsPreviewing && Preview != null && HasRecentFrame))); + StartRecordingCommand = Command(StartRecordingAsync, () => !IsBusy && !_closing && !IsRecording && !HasStandardVideo && IsPreviewing && Preview != null && HasRecentFrame); + StopRecordingCommand = Command(() => { StopRecording(); return Task.CompletedTask; }, () => !IsBusy && !_closing && IsRecording); PauseCommand = Command(() => { TogglePause(); return Task.CompletedTask; }, () => !IsBusy && !_closing && IsRecording); RestartCommand = Command(RestartRecordingAsync, () => _sopStandard && !IsBusy && !_closing && HasStandardVideo && IsPreviewing && Preview != null && HasRecentFrame); PlayVideoCommand = Command(ToggleVideoPlaybackAsync, () => _sopStandard && !IsBusy && !_closing && !IsRecording && HasStandardVideo); @@ -150,7 +151,7 @@ public sealed class CameraViewModel : BindableBase private void StateChanged() { RaisePropertyChanged(nameof(CanChangeDirectory)); RaisePropertyChanged(nameof(SelectedCameraName)); - RaisePropertyChanged(nameof(PreviewButtonText)); RaisePropertyChanged(nameof(RecordButtonText)); UpdateCommands(); + RaisePropertyChanged(nameof(PreviewButtonText)); UpdateCommands(); RaisePropertyChanged(nameof(PauseButtonText)); RaisePropertyChanged(nameof(HasStandardVideo)); } private async Task TogglePreviewAsync() @@ -187,9 +188,9 @@ public sealed class CameraViewModel : BindableBase await Playback.PlayAsync(StandardVideoPath); if (Playback.IsPlaying) Status = "正在播放已录制的SOP流程视频"; } - private Task ToggleRecordingAsync() + private Task StartRecordingAsync() { - if (IsRecording) { StopRecording(); return Task.CompletedTask; } + if (IsRecording) return Task.CompletedTask; if (HasStandardVideo) throw new InvalidOperationException("已有SOP流程视频,请使用“重新录制”并确认删除旧视频"); if (string.IsNullOrWhiteSpace(SaveDirectory)) throw new ArgumentException("请选择录像保存目录"); var directory = Path.GetFullPath(SaveDirectory.Trim()); @@ -234,7 +235,7 @@ public sealed class CameraViewModel : BindableBase File.Delete(StandardVideoPath); LastRecording = ""; StateChanged(); - await ToggleRecordingAsync(); + await StartRecordingAsync(); } private void StopRecording() { diff --git a/src/SopHelper.Avalonia/Training/CameraWindow.axaml b/src/SopHelper.Avalonia/Training/CameraWindow.axaml index 46fbe84..b88247f 100644 --- a/src/SopHelper.Avalonia/Training/CameraWindow.axaml +++ b/src/SopHelper.Avalonia/Training/CameraWindow.axaml @@ -46,8 +46,9 @@