axe-windows icon indicating copy to clipboard operation
axe-windows copied to clipboard

feat: Allow callers to override default DPI awareness handling

Open DaveTryon opened this issue 3 years ago • 2 comments
trafficstars

Details

We need to be DPI-aware when running an Axe.Windows scan. We current call SetProcessDPIAware then never reset the state, partially because there's no way to obtain the original state. #733 asks for a way to scope this and/or reset the original state. We want to enable this, but since different scenarios could require different handling, we are moving the DPI awareness into an interface and allowing the caller to provide their own implementation. The new interface is defined as follows:

    public interface IDPIAwareness
    {
        /// <summary>
        /// Enable DPI awareness for the scan
        /// </summary>
        /// <returns>An object that will be passed as a parameter <see cref="IDPIAwareness.Restore"/></returns>
        object Enable();

        /// <summary>
        /// Restore DPI awareness to its original state
        /// </summary>
        /// <param name="dataFromEnable">The object returned from the call to <see cref="IDPIAwareness.Enable"/></param>
        void Restore(object dataFromEnable);
    }

Calls to Enable and Restore will always be paired within a call to IScanner.Scan or IScanner.ScanAll. A user's implementation of IDPIAwareness is injected by calling Config.Builder.WithDPIAwareness when setting up the scanner. Apps that don't call ConfigBuilder.WithDPIAwareness will continue to use the existing behavior, so backward compatibility is preserved.

Motivation

Address #733

Context

We could have just set the DPI awareness on the thread, then reset it as suggested in a comment on #733. That would potentially break backward compatibility, and it opens the door of possibly trying to provide one-off solutions as customer needs change. The simpler long-term option is to allow customers to implement what works for their scenario. This may become even more important as we think about adding async versions of the scanning methods. Making assumptions about the calling code is a great way to create a bug pump.

Pull request checklist

  • [ ] Addresses an existing issue: #0000

DaveTryon avatar Sep 09 '22 22:09 DaveTryon

@chabiss and @spadapet, please let us know if this approach will unblock the scenarios that you have in mind. Thanks!

DaveTryon avatar Sep 09 '22 22:09 DaveTryon

Codecov Report

Merging #751 (fa0369e) into main (4fc19c3) will increase coverage by 1.28%. The diff coverage is 82.63%.

@@            Coverage Diff             @@
##             main     #751      +/-   ##
==========================================
+ Coverage   73.70%   74.98%   +1.28%     
==========================================
  Files         398      418      +20     
  Lines       12046    12880     +834     
==========================================
+ Hits         8878     9658     +780     
- Misses       3168     3222      +54     
Impacted Files Coverage Δ
src/Actions/Actions/ControlPatternAction.cs 0.00% <ø> (ø)
src/Actions/Actions/CustomUIAAction.cs 0.00% <0.00%> (ø)
src/Actions/Actions/GetDataAction.cs 25.00% <ø> (ø)
src/Actions/Actions/ListenAction.cs 0.00% <0.00%> (ø)
src/Actions/Actions/LoadActionParts.cs 90.90% <ø> (ø)
src/Actions/Actions/SetDataAction.cs 0.00% <ø> (ø)
...rc/Actions/Attributes/InteractionLevelAttribute.cs 0.00% <ø> (ø)
src/Actions/Contexts/ElementDataContext.cs 86.36% <ø> (ø)
src/Actions/Misc/ExtensionMethods.cs 37.31% <0.00%> (-1.75%) :arrow_down:
src/Actions/Resources/ErrorMessages.Designer.cs 55.55% <ø> (ø)
... and 227 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Sep 09 '22 22:09 codecov-commenter