修复 CNC 执行中切换用户权限守卫失效(P1-5/P1-7)
PermissionService.CanSwitchUser 原本读 SystemState.OperationMode,但该字段 从未被写成非 Idle(唯一写入点 RecipeService 仍写 Idle),导致"CNC 执行中 禁止切换用户"从未真正生效。改为直接读 AppStateService.CncExecutionState.IsRunning, 这是 CncExecutionService 在开始/暂停/结束时真实维护的状态。 RibbonStatusAreaViewModel 同步改为订阅 CncExecutionStateChanged。 MainViewportService.IsCncRunning 与 CncExecutionState 仍是两套独立状态, 保持不变:SetCncRunning 内部的互斥检查(与检测池模式双向互斥)需要原子性, 直接改为读 CncExecutionState 会引入竞态窗口,不在本次修复范围内。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -151,14 +151,7 @@ namespace XplorePlane.Services.Security
|
||||
public event EventHandler<RoleChangedEventArgs> RoleChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool CanSwitchUser
|
||||
{
|
||||
get
|
||||
{
|
||||
var systemState = _appStateService.SystemState;
|
||||
return systemState.OperationMode == OperationMode.Idle;
|
||||
}
|
||||
}
|
||||
public bool CanSwitchUser => !_appStateService.CncExecutionState.IsRunning;
|
||||
|
||||
public PermissionService(
|
||||
IEventAggregator eventAggregator,
|
||||
|
||||
@@ -62,8 +62,8 @@ namespace XplorePlane.ViewModels.Main
|
||||
_eventAggregator.GetEvent<RoleChangedEvent>()
|
||||
.Subscribe(OnRoleChanged, ThreadOption.UIThread);
|
||||
|
||||
// Subscribe to SystemState changes to update CanSwitchUser
|
||||
_appStateService.SystemStateChanged += OnSystemStateChanged;
|
||||
// Subscribe to CncExecutionState changes to update CanSwitchUser
|
||||
_appStateService.CncExecutionStateChanged += OnCncExecutionStateChanged;
|
||||
|
||||
// Initialize from current state
|
||||
InitializeFromCurrentState();
|
||||
@@ -84,7 +84,7 @@ namespace XplorePlane.ViewModels.Main
|
||||
CurrentRoleDisplayName = MapRoleToDisplayName(payload.NewRole);
|
||||
}
|
||||
|
||||
private void OnSystemStateChanged(object sender, StateChangedEventArgs<SystemState> e)
|
||||
private void OnCncExecutionStateChanged(object sender, StateChangedEventArgs<XplorePlane.Models.Main.CncExecutionState> e)
|
||||
{
|
||||
CanSwitchUser = _permissionService.CanSwitchUser;
|
||||
SwitchUserCommand.RaiseCanExecuteChanged();
|
||||
|
||||
Reference in New Issue
Block a user