|
| 1 | +using GamerGuardian.Models; |
| 2 | +using Microsoft.Win32; |
| 3 | + |
| 4 | +namespace GamerGuardian.Monitors; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// The "Let's finish setting up your device" / SCOOBE full-screen and |
| 8 | +/// notification nags that prompt to set up OneDrive, a Microsoft account, or a |
| 9 | +/// Microsoft 365 subscription -- and resurface after feature updates. Driven by |
| 10 | +/// the per-user UserProfileEngagement flag plus the device-setup notification |
| 11 | +/// under ContentDeliveryManager. Intuitive Enabled/Disabled: <c>DesiredOn</c> = |
| 12 | +/// the nag enabled; recommended OFF. |
| 13 | +/// </summary> |
| 14 | +public sealed class FinishSetupNagMonitor : IMonitoredSetting |
| 15 | +{ |
| 16 | + public string Id => "debloat.finishsetup"; |
| 17 | + private const string EngagementKey = @"Software\Microsoft\Windows\CurrentVersion\UserProfileEngagement"; |
| 18 | + private const string EngagementVal = "ScoobeSystemSettingEnabled"; |
| 19 | + private const string CdmKey = @"Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; |
| 20 | + private const string CdmVal = "SubscribedContent-310093Enabled"; // device-setup "finish setup" notifications |
| 21 | + |
| 22 | + public IEnumerable<DriftItem> CheckDrift(AppConfig config) |
| 23 | + { |
| 24 | + var pref = config.Global.FinishSetupNag; |
| 25 | + var current = ReadCurrent(); |
| 26 | + if (current is null) yield break; |
| 27 | + if (current.Value == pref.DesiredOn) yield break; |
| 28 | + |
| 29 | + bool desired = pref.DesiredOn; |
| 30 | + yield return new DriftItem( |
| 31 | + SettingId: Id, |
| 32 | + DisplayKey: "debloat", |
| 33 | + DisplayLabel: "Debloat", |
| 34 | + Description: "\"Finish setting up your device\" nag", |
| 35 | + CurrentValue: current.Value ? "Enabled" : "Disabled", |
| 36 | + DesiredValue: desired ? "Enabled" : "Disabled", |
| 37 | + AutoApply: pref.AutoApply, |
| 38 | + Apply: () => Task.Run(() => Apply(desired)), |
| 39 | + IsMonitored: pref.Monitor, |
| 40 | + RawBefore: current.Value ? "(default / nag on)" : "ScoobeSystemSettingEnabled=0, SubscribedContent-310093Enabled=0", |
| 41 | + RawDesired: desired ? "(deleted / Windows default)" : "ScoobeSystemSettingEnabled=0, SubscribedContent-310093Enabled=0"); |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary>True (on) unless both nag flags are explicitly 0. Absent values |
| 45 | + /// count as on (the SCOOBE default), so the toggle applies on a fresh machine.</summary> |
| 46 | + public static bool? ReadCurrent() |
| 47 | + { |
| 48 | + try |
| 49 | + { |
| 50 | + using var e = Registry.CurrentUser.OpenSubKey(EngagementKey, writable: false); |
| 51 | + if ((e?.GetValue(EngagementVal) as int?) != 0) return true; |
| 52 | + using var c = Registry.CurrentUser.OpenSubKey(CdmKey, writable: false); |
| 53 | + if ((c?.GetValue(CdmVal) as int?) != 0) return true; |
| 54 | + return false; |
| 55 | + } |
| 56 | + catch { return null; } |
| 57 | + } |
| 58 | + |
| 59 | + public static void Apply(bool on) |
| 60 | + { |
| 61 | + try |
| 62 | + { |
| 63 | + if (on) |
| 64 | + { |
| 65 | + using (var e = Registry.CurrentUser.OpenSubKey(EngagementKey, writable: true)) |
| 66 | + e?.DeleteValue(EngagementVal, throwOnMissingValue: false); |
| 67 | + using (var c = Registry.CurrentUser.OpenSubKey(CdmKey, writable: true)) |
| 68 | + c?.DeleteValue(CdmVal, throwOnMissingValue: false); |
| 69 | + } |
| 70 | + else |
| 71 | + { |
| 72 | + using (var e = Registry.CurrentUser.CreateSubKey(EngagementKey, writable: true)!) |
| 73 | + e.SetValue(EngagementVal, 0, RegistryValueKind.DWord); |
| 74 | + using (var c = Registry.CurrentUser.CreateSubKey(CdmKey, writable: true)!) |
| 75 | + c.SetValue(CdmVal, 0, RegistryValueKind.DWord); |
| 76 | + } |
| 77 | + } |
| 78 | + catch { } |
| 79 | + } |
| 80 | +} |
0 commit comments