EnabledModules.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Runtime.CompilerServices; 7 using System.Text.Json; 8 using System.Text.Json.Serialization; 9 10 using Microsoft.PowerToys.Settings.Telemetry; 11 using Microsoft.PowerToys.Telemetry; 12 13 namespace Microsoft.PowerToys.Settings.UI.Library 14 { 15 public class EnabledModules 16 { 17 private Action notifyEnabledChangedAction; 18 19 // Default values for enabled modules should match their expected "enabled by default" values. 20 // Otherwise, a run of DSC on clean settings will not match the expected default result. 21 public EnabledModules() 22 { 23 } 24 25 private bool fancyZones = true; 26 27 [JsonPropertyName("FancyZones")] 28 public bool FancyZones 29 { 30 get => fancyZones; 31 set 32 { 33 if (fancyZones != value) 34 { 35 LogTelemetryEvent(value); 36 fancyZones = value; 37 NotifyChange(); 38 } 39 } 40 } 41 42 private bool imageResizer = true; 43 44 [JsonPropertyName("Image Resizer")] 45 public bool ImageResizer 46 { 47 get => imageResizer; 48 set 49 { 50 if (imageResizer != value) 51 { 52 LogTelemetryEvent(value); 53 imageResizer = value; 54 } 55 } 56 } 57 58 private bool fileExplorerPreview = true; 59 60 [JsonPropertyName("File Explorer Preview")] 61 public bool PowerPreview 62 { 63 get => fileExplorerPreview; 64 set 65 { 66 if (fileExplorerPreview != value) 67 { 68 LogTelemetryEvent(value); 69 fileExplorerPreview = value; 70 } 71 } 72 } 73 74 private bool shortcutGuide = true; 75 76 [JsonPropertyName("Shortcut Guide")] 77 public bool ShortcutGuide 78 { 79 get => shortcutGuide; 80 set 81 { 82 if (shortcutGuide != value) 83 { 84 LogTelemetryEvent(value); 85 shortcutGuide = value; 86 NotifyChange(); 87 } 88 } 89 } 90 91 private bool powerRename = true; 92 93 public bool PowerRename 94 { 95 get => powerRename; 96 set 97 { 98 if (powerRename != value) 99 { 100 LogTelemetryEvent(value); 101 powerRename = value; 102 } 103 } 104 } 105 106 private bool keyboardManager; // defaulting to off 107 108 [JsonPropertyName("Keyboard Manager")] 109 public bool KeyboardManager 110 { 111 get => keyboardManager; 112 set 113 { 114 if (keyboardManager != value) 115 { 116 LogTelemetryEvent(value); 117 keyboardManager = value; 118 } 119 } 120 } 121 122 private bool powerLauncher = true; 123 124 [JsonPropertyName("PowerToys Run")] 125 public bool PowerLauncher 126 { 127 get => powerLauncher; 128 set 129 { 130 if (powerLauncher != value) 131 { 132 LogTelemetryEvent(value); 133 powerLauncher = value; 134 NotifyChange(); 135 } 136 } 137 } 138 139 private bool colorPicker = true; 140 141 [JsonPropertyName("ColorPicker")] 142 public bool ColorPicker 143 { 144 get => colorPicker; 145 set 146 { 147 if (colorPicker != value) 148 { 149 LogTelemetryEvent(value); 150 colorPicker = value; 151 NotifyChange(); 152 } 153 } 154 } 155 156 private bool cropAndLock = true; 157 158 [JsonPropertyName("CropAndLock")] 159 public bool CropAndLock 160 { 161 get => cropAndLock; 162 set 163 { 164 if (cropAndLock != value) 165 { 166 LogTelemetryEvent(value); 167 cropAndLock = value; 168 NotifyChange(); 169 } 170 } 171 } 172 173 private bool awake = true; 174 175 [JsonPropertyName("Awake")] 176 public bool Awake 177 { 178 get => awake; 179 set 180 { 181 if (awake != value) 182 { 183 LogTelemetryEvent(value); 184 awake = value; 185 } 186 } 187 } 188 189 private bool mouseWithoutBorders; // defaulting to off 190 191 [JsonPropertyName("MouseWithoutBorders")] 192 public bool MouseWithoutBorders 193 { 194 get => mouseWithoutBorders; 195 set 196 { 197 if (mouseWithoutBorders != value) 198 { 199 LogTelemetryEvent(value); 200 mouseWithoutBorders = value; 201 } 202 } 203 } 204 205 private bool findMyMouse = true; 206 207 [JsonPropertyName("FindMyMouse")] 208 public bool FindMyMouse 209 { 210 get => findMyMouse; 211 set 212 { 213 if (findMyMouse != value) 214 { 215 LogTelemetryEvent(value); 216 findMyMouse = value; 217 } 218 } 219 } 220 221 private bool mouseHighlighter = true; 222 223 [JsonPropertyName("MouseHighlighter")] 224 public bool MouseHighlighter 225 { 226 get => mouseHighlighter; 227 set 228 { 229 if (mouseHighlighter != value) 230 { 231 LogTelemetryEvent(value); 232 mouseHighlighter = value; 233 } 234 } 235 } 236 237 private bool mouseJump; // defaulting to off 238 239 [JsonPropertyName("MouseJump")] 240 public bool MouseJump 241 { 242 get => mouseJump; 243 set 244 { 245 if (mouseJump != value) 246 { 247 LogTelemetryEvent(value); 248 mouseJump = value; 249 } 250 } 251 } 252 253 private bool alwaysOnTop = true; 254 255 [JsonPropertyName("AlwaysOnTop")] 256 public bool AlwaysOnTop 257 { 258 get => alwaysOnTop; 259 set 260 { 261 if (alwaysOnTop != value) 262 { 263 LogTelemetryEvent(value); 264 alwaysOnTop = value; 265 } 266 } 267 } 268 269 private bool mousePointerCrosshairs; // defaulting to off 270 271 [JsonPropertyName("MousePointerCrosshairs")] 272 public bool MousePointerCrosshairs 273 { 274 get => mousePointerCrosshairs; 275 set 276 { 277 if (mousePointerCrosshairs != value) 278 { 279 LogTelemetryEvent(value); 280 mousePointerCrosshairs = value; 281 } 282 } 283 } 284 285 private bool powerAccent; // defaulting to off 286 287 [JsonPropertyName("QuickAccent")] 288 public bool PowerAccent 289 { 290 get => powerAccent; 291 set 292 { 293 if (powerAccent != value) 294 { 295 LogTelemetryEvent(value); 296 powerAccent = value; 297 } 298 } 299 } 300 301 private bool powerOCR; // defaulting to off 302 303 [JsonPropertyName("TextExtractor")] 304 public bool PowerOcr 305 { 306 get => powerOCR; 307 set 308 { 309 if (powerOCR != value) 310 { 311 LogTelemetryEvent(value); 312 powerOCR = value; 313 NotifyChange(); 314 } 315 } 316 } 317 318 private bool advancedPaste = true; 319 320 [JsonPropertyName("AdvancedPaste")] 321 public bool AdvancedPaste 322 { 323 get => advancedPaste; 324 set 325 { 326 if (advancedPaste != value) 327 { 328 LogTelemetryEvent(value); 329 advancedPaste = value; 330 NotifyChange(); 331 } 332 } 333 } 334 335 private bool measureTool = true; 336 337 [JsonPropertyName("Measure Tool")] 338 public bool MeasureTool 339 { 340 get => measureTool; 341 set 342 { 343 if (measureTool != value) 344 { 345 LogTelemetryEvent(value); 346 measureTool = value; 347 NotifyChange(); 348 } 349 } 350 } 351 352 private bool hosts = true; 353 354 [JsonPropertyName("Hosts")] 355 public bool Hosts 356 { 357 get => hosts; 358 set 359 { 360 if (hosts != value) 361 { 362 LogTelemetryEvent(value); 363 hosts = value; 364 NotifyChange(); 365 } 366 } 367 } 368 369 private bool fileLocksmith = true; 370 371 [JsonPropertyName("File Locksmith")] 372 public bool FileLocksmith 373 { 374 get => fileLocksmith; 375 set 376 { 377 if (fileLocksmith != value) 378 { 379 LogTelemetryEvent(value); 380 fileLocksmith = value; 381 } 382 } 383 } 384 385 private bool peek = true; 386 387 [JsonPropertyName("Peek")] 388 public bool Peek 389 { 390 get => peek; 391 set 392 { 393 if (peek != value) 394 { 395 LogTelemetryEvent(value); 396 peek = value; 397 } 398 } 399 } 400 401 private bool registryPreview = true; 402 403 [JsonPropertyName("RegistryPreview")] 404 public bool RegistryPreview 405 { 406 get => registryPreview; 407 set 408 { 409 if (registryPreview != value) 410 { 411 LogTelemetryEvent(value); 412 registryPreview = value; 413 } 414 } 415 } 416 417 private bool cmdNotFound = true; 418 419 [JsonPropertyName("CmdNotFound")] 420 public bool CmdNotFound 421 { 422 get => cmdNotFound; 423 set 424 { 425 if (cmdNotFound != value) 426 { 427 LogTelemetryEvent(value); 428 cmdNotFound = value; 429 NotifyChange(); 430 } 431 } 432 } 433 434 private bool environmentVariables = true; 435 436 [JsonPropertyName("EnvironmentVariables")] 437 public bool EnvironmentVariables 438 { 439 get => environmentVariables; 440 set 441 { 442 if (environmentVariables != value) 443 { 444 LogTelemetryEvent(value); 445 environmentVariables = value; 446 } 447 } 448 } 449 450 private bool newPlus; 451 452 [JsonPropertyName("NewPlus")] // This key must match newplus::constants::non_localizable 453 public bool NewPlus 454 { 455 get => newPlus; 456 set 457 { 458 if (newPlus != value) 459 { 460 LogTelemetryEvent(value); 461 newPlus = value; 462 } 463 } 464 } 465 466 private bool workspaces = true; 467 468 [JsonPropertyName("Workspaces")] 469 public bool Workspaces 470 { 471 get => workspaces; 472 set 473 { 474 if (workspaces != value) 475 { 476 LogTelemetryEvent(value); 477 workspaces = value; 478 NotifyChange(); 479 } 480 } 481 } 482 483 private bool cmdPal = true; 484 485 [JsonPropertyName("CmdPal")] 486 public bool CmdPal 487 { 488 get => cmdPal; 489 set 490 { 491 if (cmdPal != value) 492 { 493 LogTelemetryEvent(value); 494 cmdPal = value; 495 } 496 } 497 } 498 499 private bool zoomIt; 500 501 [JsonPropertyName("ZoomIt")] 502 public bool ZoomIt 503 { 504 get => zoomIt; 505 set 506 { 507 if (zoomIt != value) 508 { 509 LogTelemetryEvent(value); 510 zoomIt = value; 511 NotifyChange(); 512 } 513 } 514 } 515 516 private bool cursorWrap; // defaulting to off 517 518 [JsonPropertyName("CursorWrap")] 519 public bool CursorWrap 520 { 521 get => cursorWrap; 522 set 523 { 524 if (cursorWrap != value) 525 { 526 LogTelemetryEvent(value); 527 cursorWrap = value; 528 } 529 } 530 } 531 532 private bool lightSwitch; 533 534 [JsonPropertyName("LightSwitch")] 535 public bool LightSwitch 536 { 537 get => lightSwitch; 538 set 539 { 540 if (lightSwitch != value) 541 { 542 LogTelemetryEvent(value); 543 lightSwitch = value; 544 NotifyChange(); 545 } 546 } 547 } 548 549 private bool powerDisplay; 550 551 [JsonPropertyName("PowerDisplay")] 552 public bool PowerDisplay 553 { 554 get => powerDisplay; 555 set 556 { 557 if (powerDisplay != value) 558 { 559 LogTelemetryEvent(value); 560 powerDisplay = value; 561 NotifyChange(); 562 } 563 } 564 } 565 566 private void NotifyChange() 567 { 568 notifyEnabledChangedAction?.Invoke(); 569 } 570 571 public string ToJsonString() 572 { 573 return JsonSerializer.Serialize(this); 574 } 575 576 private static void LogTelemetryEvent(bool value, [CallerMemberName] string moduleName = null) 577 { 578 var dataEvent = new SettingsEnabledEvent() 579 { 580 Value = value, 581 Name = moduleName, 582 }; 583 PowerToysTelemetry.Log.WriteEvent(dataEvent); 584 } 585 586 internal void AddEnabledModuleChangeNotification(Action callBack) 587 { 588 notifyEnabledChangedAction = callBack; 589 } 590 } 591 }