feat(ui): PowerUse-Einstellungen nach Settings -> Ausfuehrung verschieben
Schalter, Zeitfenster und Handoff-Prozent lagen im Usage-Monitor und mussten in SettingsModalViewModel nur load->save durchgeschleift werden, damit ein Settings-Speichern sie nicht zurueckwirft. Jetzt gehoeren sie dem General-Tab, der Monitor ist wieder nur Anzeige + Threshold-Drag, und "Jetzt aktualisieren" sitzt als Icon in der Titelleiste (neuer ModalShell.HeaderActions-Slot).
This commit is contained in:
@@ -49,8 +49,8 @@ public sealed partial class ListSettingsModalViewModel : ViewModelBase
|
||||
// lands; a non-zero exit keeps the task out of Done instead of silently reporting merged.
|
||||
[ObservableProperty] private string _verifyCommand = "";
|
||||
// Per-list opt-in for PowerUse. A handler run on this list only goes unattended (no questions,
|
||||
// harvests new work, longer handoff chain) when this AND the global switch in the usage monitor
|
||||
// are both on. Off by default — the global switch alone must never change a list's behaviour.
|
||||
// harvests new work, longer handoff chain) when this AND the global switch in Settings →
|
||||
// Execution are both on. Off by default — the global switch alone must never change a list's behaviour.
|
||||
[ObservableProperty] private bool _powerUseAllowed;
|
||||
// Dropdown hidden entirely when no ticket-system base URL is configured (Settings → Files tab).
|
||||
// Icon key into the UI icon library (IconKeyConverter -> "Icon.<key>" StreamGeometry).
|
||||
|
||||
@@ -30,6 +30,15 @@ public sealed partial class GeneralSettingsTabViewModel : ViewModelBase
|
||||
// Cap on a list-handler run's wait<->merge handoff chain. 4 = two merge rounds (the long-standing
|
||||
// default); raise it for runs meant to keep going for hours. Bounds a runaway chain, so never 0.
|
||||
[ObservableProperty] private int _listHandlerMaxHandoffs = 4;
|
||||
// PowerUse master switch: a handler run spends the rest of the window unattended. On its own it
|
||||
// changes nothing — the run's LIST must also opt in (list settings → PowerUse).
|
||||
[ObservableProperty] private bool _powerUseEnabled;
|
||||
// Optional local-time window (HH:mm) narrowing when PowerUse applies; both blank = round the
|
||||
// clock. Unparseable input is normalized to null on save, same as the worker does.
|
||||
[ObservableProperty] private string? _powerUseWindowStart;
|
||||
[ObservableProperty] private string? _powerUseWindowEnd;
|
||||
// 5h-usage percentage at which a PowerUse handler session hands off. Clamped 50..99.
|
||||
[ObservableProperty] private int _powerUseHandoffPct = 95;
|
||||
// Newline-separated path prefixes excluded from the weekly report.
|
||||
[ObservableProperty] private string _reportExcludedPaths = @"C:\Private";
|
||||
// 0=Sunday..6=Saturday (System.DayOfWeek); default Wednesday.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Localization;
|
||||
using ClaudeDo.Ui.Localization;
|
||||
using ClaudeDo.Ui.Services;
|
||||
@@ -130,14 +131,6 @@ public sealed partial class SettingsModalViewModel : ViewModelBase
|
||||
// carried through load→save verbatim so saving Settings can never reset a dragged value.
|
||||
private (int FiveSoft, int FiveHard, int SevenSoft, int SevenHard) _throttleStages = (50, 65, 50, 65);
|
||||
|
||||
// Same deal: the PowerUse master switch is toggled on the usage monitor. Carried load→save so
|
||||
// opening and saving Settings can't switch it off behind the user's back.
|
||||
private bool _powerUseEnabled;
|
||||
|
||||
// Ditto for the PowerUse time window and handoff threshold — usage-monitor-owned, invisible
|
||||
// here, but they must survive a Settings save.
|
||||
private (string? Start, string? End, int HandoffPct) _powerUseWindow = (null, null, 95);
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
IsBusy = true;
|
||||
@@ -156,11 +149,10 @@ public sealed partial class SettingsModalViewModel : ViewModelBase
|
||||
General.UsageGateSevenDayPct = dto.UsageGateSevenDayPct;
|
||||
General.AutoContinueOnUsageLimit = dto.AutoContinueOnUsageLimit;
|
||||
General.ListHandlerMaxHandoffs = dto.ListHandlerMaxHandoffs;
|
||||
// Owned by the usage monitor, not editable here — but it MUST be round-tripped,
|
||||
// because SaveAsync rebuilds the whole DTO positionally and would otherwise write
|
||||
// the record default (false) back and silently switch PowerUse off.
|
||||
_powerUseEnabled = dto.PowerUseEnabled;
|
||||
_powerUseWindow = (dto.PowerUseWindowStart, dto.PowerUseWindowEnd, dto.PowerUseHandoffPct);
|
||||
General.PowerUseEnabled = dto.PowerUseEnabled;
|
||||
General.PowerUseWindowStart = dto.PowerUseWindowStart;
|
||||
General.PowerUseWindowEnd = dto.PowerUseWindowEnd;
|
||||
General.PowerUseHandoffPct = dto.PowerUseHandoffPct;
|
||||
_throttleStages = (
|
||||
dto.UsageThrottleFiveHourSoftPct, dto.UsageThrottleFiveHourHardPct,
|
||||
dto.UsageThrottleSevenDaySoftPct, dto.UsageThrottleSevenDayHardPct);
|
||||
@@ -228,11 +220,13 @@ public sealed partial class SettingsModalViewModel : ViewModelBase
|
||||
_throttleStages.SevenSoft,
|
||||
_throttleStages.SevenHard,
|
||||
General.AutoContinueOnUsageLimit,
|
||||
_powerUseEnabled,
|
||||
General.PowerUseEnabled,
|
||||
General.ListHandlerMaxHandoffs,
|
||||
_powerUseWindow.Start,
|
||||
_powerUseWindow.End,
|
||||
_powerUseWindow.HandoffPct);
|
||||
// The worker stores an unparseable time as null; normalize here too so the box
|
||||
// shows what was actually saved instead of a typo that looks like a live window.
|
||||
PowerUseWindow.Normalize(General.PowerUseWindowStart),
|
||||
PowerUseWindow.Normalize(General.PowerUseWindowEnd),
|
||||
Math.Clamp(General.PowerUseHandoffPct, 50, 99));
|
||||
await _worker.UpdateAppSettingsAsync(dto);
|
||||
await Prime.SaveAsync();
|
||||
await OnlineInbox.SaveAsync();
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Ui.Localization;
|
||||
using ClaudeDo.Ui.Services;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -101,77 +100,6 @@ public sealed partial class UsageMonitorModalViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private IReadOnlyList<UsageGaugeRowViewModel> _gaugeRows = Array.Empty<UsageGaugeRowViewModel>();
|
||||
|
||||
/// <summary>
|
||||
/// PowerUse master switch. It lives here rather than in Settings because turning it on is a
|
||||
/// "spend the rest of the window" decision, made while looking at how much window is left.
|
||||
/// On its own it changes nothing — a list-handler run only goes unattended when its LIST also
|
||||
/// opted in (list settings → PowerUse), so this can stay on without affecting other lists.
|
||||
/// </summary>
|
||||
[ObservableProperty] private bool _powerUseEnabled;
|
||||
|
||||
/// <summary>Optional local-time window (<c>HH:mm</c>) narrowing when PowerUse applies. Both
|
||||
/// blank = round the clock. Committed on focus loss / Enter, not per keystroke.</summary>
|
||||
[ObservableProperty] private string? _powerUseWindowStart;
|
||||
[ObservableProperty] private string? _powerUseWindowEnd;
|
||||
|
||||
/// <summary>5h-usage percentage at which a PowerUse handler session should hand off.</summary>
|
||||
[ObservableProperty] private int _powerUseHandoffPct = 95;
|
||||
|
||||
// Set while LoadAsync writes the stored value in, so seeding the property doesn't immediately
|
||||
// write it straight back to the worker.
|
||||
private bool _loadingPowerUse;
|
||||
|
||||
partial void OnPowerUseEnabledChanged(bool value)
|
||||
{
|
||||
if (_loadingPowerUse) return;
|
||||
_ = SavePowerUse();
|
||||
}
|
||||
|
||||
/// Read-modify-write, same discipline as SaveStagesAsync: never clobber a field this modal
|
||||
/// doesn't own. All four PowerUse fields go in one write, so committing one box can't drop a
|
||||
/// value the user just typed into a sibling box.
|
||||
[RelayCommand]
|
||||
private async Task SavePowerUse()
|
||||
{
|
||||
if (_loadingPowerUse) return;
|
||||
try
|
||||
{
|
||||
var settings = await _worker.GetAppSettingsAsync();
|
||||
if (settings is null)
|
||||
{
|
||||
ErrorReported?.Invoke(Loc.T("vm.usageMonitor.powerUseSaveFailed", Loc.T("vm.settingsModal.workerOffline")));
|
||||
return;
|
||||
}
|
||||
|
||||
// The worker stores an unparseable time as null; normalize here too so the box shows
|
||||
// what was actually saved instead of a typo that looks like a live window.
|
||||
var start = PowerUseWindow.Normalize(PowerUseWindowStart);
|
||||
var end = PowerUseWindow.Normalize(PowerUseWindowEnd);
|
||||
var pct = Math.Clamp(PowerUseHandoffPct, 50, 99);
|
||||
|
||||
await _worker.UpdateAppSettingsAsync(settings with
|
||||
{
|
||||
PowerUseEnabled = PowerUseEnabled,
|
||||
PowerUseWindowStart = start,
|
||||
PowerUseWindowEnd = end,
|
||||
PowerUseHandoffPct = pct,
|
||||
});
|
||||
|
||||
_loadingPowerUse = true;
|
||||
try
|
||||
{
|
||||
PowerUseWindowStart = start;
|
||||
PowerUseWindowEnd = end;
|
||||
PowerUseHandoffPct = pct;
|
||||
}
|
||||
finally { _loadingPowerUse = false; }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorReported?.Invoke(Loc.T("vm.usageMonitor.powerUseSaveFailed", ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsStale => Snapshot?.IsStale == true;
|
||||
public string? LastError => Snapshot?.LastError;
|
||||
public bool IsGateBlocked => Snapshot?.IsGateBlocked == true;
|
||||
@@ -221,20 +149,6 @@ public sealed partial class UsageMonitorModalViewModel : ViewModelBase
|
||||
_worker.UsageUpdatedEvent -= OnUsageUpdated;
|
||||
_worker.UsageUpdatedEvent += OnUsageUpdated;
|
||||
|
||||
var settings = await _worker.GetAppSettingsAsync();
|
||||
if (settings is not null)
|
||||
{
|
||||
_loadingPowerUse = true;
|
||||
try
|
||||
{
|
||||
PowerUseEnabled = settings.PowerUseEnabled;
|
||||
PowerUseWindowStart = settings.PowerUseWindowStart;
|
||||
PowerUseWindowEnd = settings.PowerUseWindowEnd;
|
||||
PowerUseHandoffPct = settings.PowerUseHandoffPct;
|
||||
}
|
||||
finally { _loadingPowerUse = false; }
|
||||
}
|
||||
|
||||
ApplyPresetRange(SelectedPresetDays);
|
||||
await LoadUsageDataAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user