mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
refactor(imageresizer): disable AI feature and cache functionality (#44759)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **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 <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Co-authored-by: Yu Leng <yuleng@microsoft.com>
This commit is contained in:
@@ -188,31 +188,8 @@ namespace ImageResizer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static AiAvailabilityState CheckAiAvailability()
|
private static AiAvailabilityState CheckAiAvailability()
|
||||||
{
|
{
|
||||||
try
|
// AI feature disabled - always return NotSupported
|
||||||
{
|
return AiAvailabilityState.NotSupported;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -39,29 +39,8 @@ namespace ImageResizer.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static AiAvailabilityState? LoadCache()
|
public static AiAvailabilityState? LoadCache()
|
||||||
{
|
{
|
||||||
try
|
// Cache disabled - always return null to use default value
|
||||||
{
|
return null;
|
||||||
if (!File.Exists(CachePath))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var json = File.ReadAllText(CachePath);
|
|
||||||
var cache = JsonSerializer.Deserialize<AiCapabilityCache>(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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -70,32 +49,8 @@ namespace ImageResizer.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SaveCache(AiAvailabilityState state)
|
public static void SaveCache(AiAvailabilityState state)
|
||||||
{
|
{
|
||||||
try
|
// Cache disabled - do not save anything
|
||||||
{
|
return;
|
||||||
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}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user