[New PowerToy] OCR PowerToy (#19172)

* Init commit

* Fix unintended GUID change of Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests

* Region and click word working

* Code style

* Close even when there is no result from the OCR

* Fix spelling concerns, and make overlay black to match snipping tool

* increase opacity of overlay to match snipping tool

* Code Style and cleanup

* Code style

* Create Logos and hook them into the project file

* Make the PowerOCR VCXProj more like Awake VCXProj

* Rename MainWindow to OCROverlay

* Add WindowUtilities and WindowForms

* Remove fsg to fix spelling error

* launch OCR Overlay on every screen

* Add PowerOCR to Runner Main.cpp

* Add PowerOCR Settings and Properties

* Add PowerOcrViewModel

* Fix wrong setting reference in PowerOcrSettingsVM

* Try to clean up the Cpp project for PowerOCR

* Went to ARM64 was x64 thanks @snickler

* Clean up PowerOCR C++ Proj with file refs

* Rewrite C++ dllmain comparing to awake

* Changes for spelling issues. The rest will stay

* Create PowerOcr Settings Page and add to settings shell

* Fix PowerOcr Settings

* Fix multi-monitor scaling issue

* Add close all overlays when escaping

* Update src/runner/main.cpp to call correct Power OCR dll

Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com>

* Update expect.txt

* Add many files from Color Picker for hotkey activation

* Organize project into helper folder

* Use new hotkey activation and keep process alive

* Fix bug where scalebmp wasn't working

* Add The file headers and dispose app.xaml.cs

* Code style changes

* Fix bug where PowerOCR was toggling Awake

* Unsubscribe from keyboard events making they don't fire twice

* Add SndPowerOcrSetting and add to SettingsVM

* Trying to make the runner close PowerOCR when runner closes

* Fix app_name

* Update spellcheck expect

* use mutex on PowerOCR app to keep to single instance

* Rebuild the module interface using ColorPicker as a template.

Process still stays alive.

* Fix project names of the module interface

* Put app startup args back to 0 like color picker

* Runner now finds and enables/disables PowerOCR

* remove unneeded item groups from settings proj, per stefansjfw

* Add PowerOCR Screenshots

* Revert changed project GUID

* Add OOBE content for PowerOCR

* Keep cursor on one screen since the OCR window does not span screens.

* reload settings when activation key is pressed

* New screenshots and OOBE text

* Add PowerOCR as a case in the settings App.xaml.cs OnLaunched

* Settings and OOBE Text Changes

* Using using on bitmaps and change OCR overlay to stay open if no result

* Keyboard activation is handled is true

* Remove unused start PowerOCR OOBE Method

* [PowerOCR]Add some telemetry

* Add some logging

* Don't recreate the OCR overlay Windows more times

* Add to BugReportTool to get event viewer errors

* Fix wrong comment

* Fix another comment

* Add files to installer

* Add to signing

* Don't take Esc away from other apps

* Default to Win Shift R

* Use low level keyboard hook from runner

* Remove esc from local low level keyboard hook

* Fix some nits

* Default to Win Shift T
This commit is contained in:
Joseph Finney
2022-08-25 05:25:52 -05:00
committed by GitHub
parent 768603eb61
commit eedea3159c
64 changed files with 3040 additions and 16 deletions

View File

@@ -122,6 +122,7 @@ namespace Microsoft.PowerToys.Settings.UI
case "ImageResizer": StartupPage = typeof(Views.ImageResizerPage); break;
case "KBM": StartupPage = typeof(Views.KeyboardManagerPage); break;
case "MouseUtils": StartupPage = typeof(Views.MouseUtilsPage); break;
case "PowerOCR": StartupPage = typeof(Views.PowerOcrPage); break;
case "PowerRename": StartupPage = typeof(Views.PowerRenamePage); break;
case "FileExplorer": StartupPage = typeof(Views.PowerPreviewPage); break;
case "ShortcutGuide": StartupPage = typeof(Views.ShortcutGuidePage); break;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

View File

@@ -15,6 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Enums
ImageResizer,
KBM,
MouseUtils,
PowerOCR,
PowerRename,
Run,
ShortcutGuide,

View File

@@ -0,0 +1,39 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.OOBE.Views.OobePowerOCR"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.PowerToys.Settings.UI.OOBE.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:toolkitcontrols="using:CommunityToolkit.WinUI.UI.Controls">
<controls:OOBEPageControl x:Uid="Oobe_PowerOCR"
HeroImage="ms-appx:///Assets/Modules/OOBE/PowerOCR.gif">
<controls:OOBEPageControl.PageContent>
<StackPanel Orientation="Vertical">
<TextBlock x:Uid="Oobe_HowToUse"
Style="{ThemeResource OobeSubtitleStyle}" />
<controls:ShortcutWithTextLabelControl x:Name="HotkeyControl" x:Uid="Oobe_PowerOCR_HowToUse" />
<TextBlock x:Uid="Oobe_TipsAndTricks"
Style="{ThemeResource OobeSubtitleStyle}"/>
<toolkitcontrols:MarkdownTextBlock Background="Transparent" x:Uid="Oobe_PowerOCR_TipsAndTricks" />
<StackPanel Orientation="Horizontal" Spacing="12" Margin="0,24,0,0">
<Button x:Uid="OOBE_Settings"
Click="SettingsLaunchButton_Click"/>
<HyperlinkButton NavigateUri="https://aka.ms/PowerToysOverview_PowerOCR" Style="{StaticResource TextButtonStyle}">
<TextBlock x:Uid="LearnMore_PowerOCR"
TextWrapping="Wrap" />
</HyperlinkButton>
</StackPanel>
</StackPanel>
</controls:OOBEPageControl.PageContent>
</controls:OOBEPageControl>
</Page>

View File

@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Threading;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
{
public sealed partial class OobePowerOCR : Page
{
public OobePowerToysModule ViewModel { get; set; }
public OobePowerOCR()
{
this.InitializeComponent();
ViewModel = new OobePowerToysModule(OobeShellPage.OobeShellHandler.Modules[(int)PowerToysModules.PowerOCR]);
DataContext = ViewModel;
}
private void SettingsLaunchButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (OobeShellPage.OpenMainWindowCallback != null)
{
OobeShellPage.OpenMainWindowCallback(typeof(PowerOcrPage));
}
ViewModel.LogOpeningSettingsEvent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ViewModel.LogOpeningModuleEvent();
HotkeyControl.Keys = SettingsRepository<PowerOcrSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.ActivationShortcut.GetKeysList();
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
ViewModel.LogClosingModuleEvent();
}
}
}

View File

@@ -116,6 +116,14 @@
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
<muxc:NavigationViewItem x:Uid="Shell_PowerOCR"
Tag="PowerOCR">
<muxc:NavigationViewItem.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/FluentIcons/FluentIconsPowerOCR.png"
ShowAsMonochrome="False" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
<muxc:NavigationViewItem x:Uid="Shell_PowerRename"
Tag="PowerRename">
<muxc:NavigationViewItem.Icon>

View File

@@ -102,6 +102,11 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
ModuleName = "MouseUtils",
IsNew = true,
});
Modules.Insert((int)PowerToysModules.PowerOCR, new OobePowerToysModule()
{
ModuleName = "PowerOCR",
IsNew = true,
});
Modules.Insert((int)PowerToysModules.PowerRename, new OobePowerToysModule()
{
ModuleName = "PowerRename",
@@ -170,6 +175,7 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
case "ImageResizer": NavigationFrame.Navigate(typeof(OobeImageResizer)); break;
case "KBM": NavigationFrame.Navigate(typeof(OobeKBM)); break;
case "PowerRename": NavigationFrame.Navigate(typeof(OobePowerRename)); break;
case "PowerOCR": NavigationFrame.Navigate(typeof(OobePowerOCR)); break;
case "FileExplorer": NavigationFrame.Navigate(typeof(OobeFileExplorer)); break;
case "ShortcutGuide": NavigationFrame.Navigate(typeof(OobeShortcutGuide)); break;
case "VideoConference": NavigationFrame.Navigate(typeof(OobeVideoConference)); break;

View File

@@ -35,10 +35,6 @@
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<None Remove="OobeWindow.xaml" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
@@ -68,14 +64,14 @@
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\Settings.UI.Library\Settings.UI.Library.csproj" />
</ItemGroup>
<ItemGroup>
<Page Update="OobeWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<None Update="icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Page Update="OOBE\Views\OobePowerOCR.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
</ItemGroup>
</Project>

View File

@@ -2164,6 +2164,39 @@ From there, simply click on one of the supported files in the File Explorer and
<data name="AlwaysOnTop_RoundCorners.Content" xml:space="preserve">
<value>Enable round corners</value>
</data>
<data name="LearnMore_PowerOcr.Text" xml:space="preserve">
<value>Learn more about PowerOCR</value>
</data>
<data name="PowerOCR.ModuleDescription" xml:space="preserve">
<value>PowerOCR is a convenient way to copy text from anywhere on screen</value>
</data>
<data name="PowerOCR.ModuleTitle" xml:space="preserve">
<value>PowerOCR</value>
</data>
<data name="PowerOCR_EnableToggleControl_HeaderText.Header" xml:space="preserve">
<value>Enable PowerOCR</value>
</data>
<data name="Shell_PowerOcr.Content" xml:space="preserve">
<value>PowerOCR</value>
</data>
<data name="Launch_PowerOCR.Content" xml:space="preserve">
<value>Launch PowerOCR</value>
</data>
<data name="Oobe_PowerOCR.Title" xml:space="preserve">
<value>PowerOCR</value>
</data>
<data name="Oobe_PowerOCR_HowToUse.Text" xml:space="preserve">
<value>to open PowerOCR and then selecting a region to copy the text from.</value>
</data>
<data name="Oobe_PowerOCR_TipsAndTricks.Text" xml:space="preserve">
<value>Hold the shift key to move the selection region around.</value>
</data>
<data name="PowerOCR.SecondaryLinksHeader" xml:space="preserve">
<value>Attribution</value>
</data>
<data name="Oobe_PowerOCR.Description" xml:space="preserve">
<value>PowerOCR works like Snipping Tool, but copies the text out of the selected region using OCR and puts it on the clipboard.</value>
</data>
<data name="FileExplorerPreview_ToggleSwitch_Monaco_Try_Format.Description" xml:space="preserve">
<value>Applies to json and xml. Files remain unchanged.</value>
</data>

View File

@@ -0,0 +1,44 @@
<Page
x:Class="Microsoft.PowerToys.Settings.UI.Views.PowerOcrPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
AutomationProperties.LandmarkType="Main"
mc:Ignorable="d">
<controls:SettingsPageControl x:Uid="PowerOCR" ModuleImageSource="ms-appx:///Assets/Modules/PowerOCR.png">
<controls:SettingsPageControl.ModuleContent>
<StackPanel Orientation="Vertical">
<controls:Setting x:Uid="PowerOCR_EnableToggleControl_HeaderText">
<controls:Setting.Icon>
<BitmapIcon ShowAsMonochrome="False" UriSource="ms-appx:///Assets/FluentIcons/FluentIconsPowerOcr.png" />
</controls:Setting.Icon>
<controls:Setting.ActionContent>
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" />
</controls:Setting.ActionContent>
</controls:Setting>
<controls:SettingsGroup x:Uid="Shortcut" IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
<controls:Setting x:Uid="Activation_Shortcut" Icon="&#xEDA7;">
<controls:Setting.ActionContent>
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind Path=ViewModel.ActivationShortcut, Mode=TwoWay}" />
</controls:Setting.ActionContent>
</controls:Setting>
</controls:SettingsGroup>
</StackPanel>
</controls:SettingsPageControl.ModuleContent>
<controls:SettingsPageControl.PrimaryLinks>
<controls:PageLink x:Uid="LearnMore_PowerOcr" Link="https://aka.ms/PowerToysOverview_PowerOCR" />
</controls:SettingsPageControl.PrimaryLinks>
<controls:SettingsPageControl.SecondaryLinks>
<controls:PageLink Text="Based upon Joseph Finney's Text Grab" Link="https://github.com/TheJoeFin/Text-Grab"/>
</controls:SettingsPageControl.SecondaryLinks>
</controls:SettingsPageControl>
</Page>

View File

@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.UI.Xaml.Controls;
namespace Microsoft.PowerToys.Settings.UI.Views
{
public sealed partial class PowerOcrPage : Page
{
private PowerOcrViewModel ViewModel { get; set; }
public PowerOcrPage()
{
var settingsUtils = new SettingsUtils();
ViewModel = new PowerOcrViewModel(
settingsUtils,
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
ShellPage.SendDefaultIPCMessage);
DataContext = ViewModel;
InitializeComponent();
}
}
}

View File

@@ -120,6 +120,14 @@
ShowAsMonochrome="False" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
<muxc:NavigationViewItem x:Uid="Shell_PowerOcr"
helpers:NavHelper.NavigateTo="views:PowerOcrPage">
<muxc:NavigationViewItem.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/FluentIcons/FluentIconsPowerOcr.png"
ShowAsMonochrome="False" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
<muxc:NavigationViewItem x:Uid="Shell_PowerLauncher"
helpers:NavHelper.NavigateTo="views:PowerLauncherPage">