Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json configuration #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ On startup, you can choose if you want to use UIA2 or UIA3 (see [FAQ](https://gi
###### Choose Version Dialog
![Choose Version](https://raw.githubusercontent.com/wiki/FlauTech/FlaUInspect/images/choose_version.png)

Version could also specified in appsettings.json file. If you do this, the application will start silently, i.e. 'Choose Version Dialog' will not pop up

###### Main Screen
![Main Screen](https://raw.githubusercontent.com/wiki/FlauTech/FlaUInspect/images/main_screen.png)

Expand Down
2 changes: 1 addition & 1 deletion src/FlaUInspect/App.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
Expand Down
28 changes: 26 additions & 2 deletions src/FlaUInspect/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
namespace FlaUInspect
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Windows;

namespace FlaUInspect
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
public partial class App : Application
{
private static Lazy<Settings.FlaUInspect> configuration = new Lazy<Settings.FlaUInspect>(ReadConfiguration);

public static new App Current => (App)Application.Current;

public Settings.FlaUInspect Configuration => configuration.Value;

private static Settings.FlaUInspect ReadConfiguration()
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
.Build();

// Read the configuration settings
var setting = new Settings.FlaUInspect();
configuration.Bind(nameof(Settings.FlaUInspect), setting);

return setting;
}
}
}
38 changes: 16 additions & 22 deletions src/FlaUInspect/FlaUInspect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FlaUInspect</RootNamespace>
<AssemblyName>FlaUInspect</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -64,6 +64,12 @@
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FlaUI.UIA2" Version="3.2.0" />
<PackageReference Include="FlaUI.UIA3" Version="3.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
Expand All @@ -76,6 +82,7 @@
<Compile Include="Core\HoverMode.cs" />
<Compile Include="Core\ObservableObject.cs" />
<Compile Include="Core\RelayCommand.cs" />
<Compile Include="Settings\FlaUInspect.cs" />
<Compile Include="Models\Element.cs" />
<Compile Include="ViewModels\DetailGroupViewModel.cs" />
<Compile Include="ViewModels\DetailViewModel.cs" />
Expand Down Expand Up @@ -126,6 +133,9 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Button.png" />
Expand All @@ -143,7 +153,12 @@
<Resource Include="Resources\Window.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Calendar.png" />
<Resource Include="Resources\Custom.png" />
<Resource Include="Resources\DataGrid.png" />
<Resource Include="Resources\Document.png" />
<Resource Include="Resources\Header.png" />
<Resource Include="Resources\HeaderItem.png" />
<Resource Include="Resources\HyperLink.png" />
<Resource Include="Resources\Item.png" />
<Resource Include="Resources\List.png" />
Expand All @@ -159,30 +174,9 @@
<Resource Include="Resources\ToolBar.png" />
<Resource Include="Resources\ToolTip.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Header.png" />
<Resource Include="Resources\HeaderItem.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Custom.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Document.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Inspect.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Calendar.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FlaUI.UIA2">
<Version>3.2.0</Version>
</PackageReference>
<PackageReference Include="FlaUI.UIA3">
<Version>3.2.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
8 changes: 4 additions & 4 deletions src/FlaUInspect/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Roemer")]
[assembly: AssemblyProduct("FlaUInspect")]
[assembly: AssemblyCopyright("Copyright © 2016-2017")]
[assembly: AssemblyCopyright("Copyright © 2016-2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -22,6 +22,6 @@
// app, or any theme specific resource dictionaries)
)]

[assembly: AssemblyVersion("1.3.0")]
[assembly: AssemblyFileVersion("1.3.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyVersion("1.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: AssemblyInformationalVersion("1.4.0")]
9 changes: 9 additions & 0 deletions src/FlaUInspect/Settings/FlaUInspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using FlaUI.Core;

namespace FlaUInspect.Settings
{
public class FlaUInspect
{
public AutomationType? AutomationType { get; set; }
}
}
8 changes: 7 additions & 1 deletion src/FlaUInspect/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,18 @@ public ElementViewModel SelectedItemInTree
private set { SetProperty(value); }
}

public void Initialize(Func<AutomationType> selectAutomationType)
{
var automationType = App.Current.Configuration.AutomationType ?? selectAutomationType();
Initialize(automationType);
}

public void Initialize(AutomationType selectedAutomationType)
{
SelectedAutomationType = selectedAutomationType;
IsInitialized = true;

_automation = selectedAutomationType == AutomationType.UIA2 ? (AutomationBase)new UIA2Automation() : new UIA3Automation();
_automation = SelectedAutomationType == AutomationType.UIA2 ? (AutomationBase)new UIA2Automation() : new UIA3Automation();
_rootElement = _automation.GetDesktop();
var desktopViewModel = new ElementViewModel(_rootElement);
desktopViewModel.SelectionChanged += DesktopViewModel_SelectionChanged;
Expand Down
19 changes: 13 additions & 6 deletions src/FlaUInspect/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using FlaUI.Core;
using FlaUInspect.ViewModels;

namespace FlaUInspect.Views
Expand Down Expand Up @@ -36,16 +37,22 @@ private void MainWindow_Loaded(object sender, System.EventArgs e)
{
if (!_vm.IsInitialized)
{
var dlg = new ChooseVersionWindow { Owner = this };
if (dlg.ShowDialog() != true)
{
Close();
}
_vm.Initialize(dlg.SelectedAutomationType);
_vm.Initialize(ChoseVersion);
Loaded -= MainWindow_Loaded;
}
}

private AutomationType ChoseVersion()
{
var dlg = new ChooseVersionWindow { Owner = this };
if (dlg.ShowDialog() != true)
{
Close();
}

return dlg.SelectedAutomationType;
}

private void MenuItem_Click(object sender, RoutedEventArgs e)
{
Close();
Expand Down
5 changes: 5 additions & 0 deletions src/FlaUInspect/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"FlaUInspect": {
"AutomationType": "UIA3"
}
}