Gate Lenovo-only features off on unsupported laptops and cut background CPU#3
Merged
lenuswalker merged 1 commit intoJun 13, 2026
Conversation
…nd CPU On unsupported (non-Lenovo) machines, several Lenovo-specific components started unconditionally and consumed resources: - Seven Lenovo WMI/driver event listeners were auto-activated during IoC container build regardless of hardware. - Hybrid mode init, AIController, the HWiNFO sensor integration, and the battery discharge-rate monitor ran outside the compatibility gate. Changes: - Add Compatibility.IsBasicCompatible (synchronous view of the cached basic-compat result) and an AutoActivateLenovoListener() registration extension that skips auto-activation on unsupported hardware. App now resolves compatibility before building the container so the gate is set at module-load time. The 7 Lenovo listeners use the gated extension; the 6 generic listeners keep normal auto-activation. - Move hybrid mode, AIController, battery monitor, HWiNFO, and macro init inside the compatible block. Cross-platform features (power-mode Windows fallback, processor TDP automation, CLI/IPC, GPU keep-off) stay available on any laptop. Performance: - MacroController installs the system-wide WH_KEYBOARD_LL hook only when macros are enabled (default off), eliminating per-keystroke managed callbacks on every machine. Hook install/uninstall is confined to the UI thread (startup + MacroPage toggle); SetEnabled only flips the setting because automation steps run off-thread. Added Stop() and shutdown cleanup. - Remove dead-code guards in BatteryDischargeRateMonitorService. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On unsupported (non-Lenovo) machines, several Lenovo-specific components started unconditionally at launch and consumed resources (and quietly failed). This change gates them behind the existing basic-compatibility check and trims always-on background work.
Lenovo-only feature gating
Compatibility.IsBasicCompatible— a synchronous view of the cached basic-compat result — and a newAutoActivateLenovoListener()registration extension that skips auto-activation on unsupported hardware.Appnow resolves basic compatibility before building the IoC container, so the gate is known at module-load time.DriverKey,LightingChange,PowerMode,RGBKeyboardBacklight,SpecialKey,ThermalMode,WinKey) now use the gated extension and never start on unsupported machines. The 6 generic listeners (DisplayBrightness,DisplayConfiguration,NativeWindowsMessage,PowerState,SessionLockUnlock,SystemTheme) keep normal auto-activation.AIController, the battery discharge-rate monitor, HWiNFO integration, and macro init inside theif (_isCompatible)block.Performance
MacroControllerinstalls the system-wideWH_KEYBOARD_LLhook only when macros are enabled (default off), eliminating a per-keystroke managed callback on every machine. Install/uninstall is confined to the UI thread (startup + MacroPage toggle);SetEnabledonly flips the setting because automation steps run off-thread. AddedStop()and shutdown cleanup.BatteryDischargeRateMonitorService.Security
No new attack surface — the change reduces it: fewer WMI subscriptions and no global keyboard hook unless the user explicitly enables macros. No new I/O, P/Invoke, or external calls.
Testing
dotnet build LenovoLegionToolkit.sln).Note
If macros are disabled at startup and an automation pipeline enables them mid-session, the hook won't install until the UI toggle is used or the app restarts (the setting persists). This is the deliberate trade-off for not installing a global keyboard hook from a background thread.
🤖 Generated with Claude Code