From 089c5f8b5075febf273aa70ff7f8a1f23c43e490 Mon Sep 17 00:00:00 2001 From: moooyo <42196638+moooyo@users.noreply.github.com> Date: Mon, 19 Jan 2026 10:50:05 +0800 Subject: [PATCH] refactor(imageresizer): disable AI feature and cache functionality (#44759) ## Summary of the Pull Request ## PR Checklist - [ ] Closes: #xxx - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed Co-authored-by: Yu Leng --- src/modules/imageresizer/ui/App.xaml.cs | 27 +--------- .../ui/Services/AiAvailabilityCacheService.cs | 53 ++----------------- 2 files changed, 6 insertions(+), 74 deletions(-) diff --git a/src/modules/imageresizer/ui/App.xaml.cs b/src/modules/imageresizer/ui/App.xaml.cs index 06c8eebad5..9977a8a474 100644 --- a/src/modules/imageresizer/ui/App.xaml.cs +++ b/src/modules/imageresizer/ui/App.xaml.cs @@ -188,31 +188,8 @@ namespace ImageResizer /// private static AiAvailabilityState CheckAiAvailability() { - try - { - // Check Windows AI service model ready state - // it's so slow, why? - var readyState = Services.WinAiSuperResolutionService.GetModelReadyState(); - - // Map AI service state to our availability state - switch (readyState) - { - case Microsoft.Windows.AI.AIFeatureReadyState.Ready: - return AiAvailabilityState.Ready; - - case Microsoft.Windows.AI.AIFeatureReadyState.NotReady: - return AiAvailabilityState.ModelNotReady; - - case Microsoft.Windows.AI.AIFeatureReadyState.DisabledByUser: - case Microsoft.Windows.AI.AIFeatureReadyState.NotSupportedOnCurrentSystem: - default: - return AiAvailabilityState.NotSupported; - } - } - catch (Exception) - { - return AiAvailabilityState.NotSupported; - } + // AI feature disabled - always return NotSupported + return AiAvailabilityState.NotSupported; } /// diff --git a/src/modules/imageresizer/ui/Services/AiAvailabilityCacheService.cs b/src/modules/imageresizer/ui/Services/AiAvailabilityCacheService.cs index d1a235297e..474d1c398e 100644 --- a/src/modules/imageresizer/ui/Services/AiAvailabilityCacheService.cs +++ b/src/modules/imageresizer/ui/Services/AiAvailabilityCacheService.cs @@ -39,29 +39,8 @@ namespace ImageResizer.Services /// public static AiAvailabilityState? LoadCache() { - try - { - if (!File.Exists(CachePath)) - { - return null; - } - - var json = File.ReadAllText(CachePath); - var cache = JsonSerializer.Deserialize(json); - - if (!IsCacheValid(cache)) - { - return null; - } - - return (AiAvailabilityState)cache.State; - } - catch (Exception ex) - { - // Read failure (file locked, corrupted JSON, etc.) - return null and use fallback - Logger.LogError($"Failed to load AI cache: {ex.Message}"); - return null; - } + // Cache disabled - always return null to use default value + return null; } /// @@ -70,32 +49,8 @@ namespace ImageResizer.Services /// public static void SaveCache(AiAvailabilityState state) { - try - { - var cache = new AiCapabilityCache - { - Version = CacheVersion, - State = (int)state, - WindowsBuild = Environment.OSVersion.Version.ToString(), - Architecture = RuntimeInformation.ProcessArchitecture.ToString(), - Timestamp = DateTime.UtcNow.ToString("o"), - }; - - var dir = Path.GetDirectoryName(CachePath); - if (!Directory.Exists(dir)) - { - Directory.CreateDirectory(dir); - } - - var json = JsonSerializer.Serialize(cache, SerializerOptions); - File.WriteAllText(CachePath, json); - - Logger.LogInfo($"AI cache saved: {state}"); - } - catch (Exception ex) - { - Logger.LogError($"Failed to save AI cache: {ex.Message}"); - } + // Cache disabled - do not save anything + return; } ///