Skip to content
This repository was archived by the owner on Nov 25, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
0bfc829
Add the ErgoDox tag model
Invvard May 8, 2019
6a2cd84
Add the geometry and tag list properties
Invvard May 8, 2019
013dd0c
Add ZIP and HEX file URL properties
Invvard May 8, 2019
115218b
Add the GetLayoutInfo method signature
Invvard May 8, 2019
e1b2ce0
Implement GetLayoutInfo method
Invvard May 8, 2019
5a9f815
Update the project
Invvard May 10, 2019
827c9ae
Create the GraphQL for layout info
Invvard May 10, 2019
e8b7095
Move duplicated code to private method
Invvard May 10, 2019
7196e6c
Update the default Layout URL
Invvard May 10, 2019
d8d47e0
Update the default Layout URL
Invvard May 10, 2019
ddaf1b9
Remove unused using
Invvard May 10, 2019
02c8862
Update dictionary
Invvard May 11, 2019
22566f7
Get layout info on URL change
Invvard May 11, 2019
763a1c1
Simplify after change layout URL
Invvard May 13, 2019
45fb5fb
Modify window to add space for Layout info
Invvard May 13, 2019
239eaf9
Add delay on the PropertyChanged event
Invvard May 13, 2019
4d9a755
Add layout info group box
Invvard May 14, 2019
b86cb86
Add layers listview
Invvard May 14, 2019
858a7c7
Remove propertyChanged notification for fix strings
Invvard May 14, 2019
d6d8570
Add layout info label
Invvard May 15, 2019
1a76350
Add layout info label binding
Invvard May 15, 2019
9938504
Change the URIs type to String
Invvard May 15, 2019
ad68741
Add basic info into LayoutService design implementation
Invvard May 15, 2019
bcdbce4
Add the ToString override
Invvard May 15, 2019
b8d86cf
Expose LayoutInfo properties
Invvard May 15, 2019
d447601
Display the LayoutInfo in the Settings window
Invvard May 15, 2019
1e1de30
Edit presentation
Invvard May 15, 2019
f19e79b
Move HyperlinkStyledButton
Invvard May 15, 2019
990f229
Add design time labels
Invvard May 15, 2019
e74032e
Add Tags listview
Invvard May 15, 2019
cbd1c72
Add open tag search command
Invvard May 17, 2019
dc7f7c4
Bind tag button to command
Invvard May 17, 2019
ba2d1a9
Update tag listview
Invvard May 17, 2019
1e61324
Add download button commands
Invvard May 17, 2019
10b5627
Bind download buttons to command
Invvard May 17, 2019
1f244ee
Add logs
Invvard May 17, 2019
b7321ae
Clear listview when layout info are updated
Invvard May 17, 2019
ed882d0
Simplify condition
Invvard May 17, 2019
4af3d0e
Add keyboard description
Invvard May 18, 2019
5dee404
Add Settings resource dictionary
Invvard May 18, 2019
df819fe
Move style to resource dictionary
Invvard May 18, 2019
043d45d
Remove unused using
Invvard May 21, 2019
5e5f6b5
Simplify design time loading
Invvard May 21, 2019
03efede
Change the way layout info are updated
Invvard May 21, 2019
61bd152
Add the process mock
Invvard May 21, 2019
23d88af
Add unit tests for OpenTagSearchCommand
Invvard May 22, 2019
90cd689
Rollback removal
Invvard May 22, 2019
1f76f4d
Update the constructor unit test
Invvard May 24, 2019
a603d99
Create empty collection
Invvard May 24, 2019
34f500b
Unit test the ErgoDoxInfo update when null
Invvard May 24, 2019
003c2d1
Fix creating other keyboard model label
Invvard May 24, 2019
2940d71
Unit test layout info update with actual data
Invvard May 24, 2019
c78dd46
Unit test download url logic
Invvard May 24, 2019
6ff4de6
Fix Revision null argument exception
Invvard May 24, 2019
228f2a6
Unit test layout info update exception
Invvard May 24, 2019
ddaebd8
Unit test download buttons
Invvard May 28, 2019
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: 1 addition & 1 deletion src/InvvardDev.EZLayoutDisplay.Desktop/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<userSettings>
<InvvardDev.EZLayoutDisplay.Desktop.Properties.Settings>
<setting name="ErgodoxLayoutUrl" serializeAs="String">
<value>https://configure.ergodox-ez.com/layouts/default/latest/0</value>
<value>https://configure.ergodox-ez.com/ergodox-ez/layouts/default/latest/0</value>
</setting>
<setting name="HotkeyShowLayout" serializeAs="String">
<value>{"modifiers":[0,1,2,4],"keycode":32}</value>
Expand Down
17 changes: 17 additions & 0 deletions src/InvvardDev.EZLayoutDisplay.Desktop/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="WhiteSmoke" />

<Style TargetType="Button" x:Key="HyperlinkStyledButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<TextBlock Foreground="#FF0066CC"
Text="{TemplateBinding Content}"
TextDecorations="Underline"
FontFamily="Segoe UI"
FontSize="15"
Cursor="Hand" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="5,0,0,0" />
</Style>

<converter:KeyCodeToCharConverter x:Key="KeyCodeConverter" />

<converter:BoolToVisibilityConverter x:Key="BoolToHiddenConverter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<Compile Include="Helper\KeyContentTemplateSelector.cs" />
<Compile Include="Helper\LoggerHelper.cs" />
<Compile Include="Model\Enum\KeyDisplayType.cs" />
<Compile Include="Model\ErgodoxTag.cs" />
<Compile Include="Model\KeyTemplate.cs" />
<Compile Include="Model\Messenger\UpdatedLayoutMessage.cs" />
<Compile Include="Properties\Resources.Designer.cs">
Expand Down Expand Up @@ -174,6 +175,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Skins\SettingsSkin.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="View\AboutWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
5 changes: 5 additions & 0 deletions src/InvvardDev.EZLayoutDisplay.Desktop/Model/ErgodoxLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ public class ErgodoxLayer
/// </summary>
[JsonProperty("color")]
public string Color { get; set; }

public override string ToString()
{
return $"{Title} {Position}";
}
}
}
12 changes: 12 additions & 0 deletions src/InvvardDev.EZLayoutDisplay.Desktop/Model/ErgodoxLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ public class ErgodoxLayout
[JsonProperty("hashId")]
public string HashId { get; set; }

/// <summary>
/// Gets or sets the keyboard geometry.
/// </summary>
[JsonProperty("geometry")]
public string Geometry { get; set; }

/// <summary>
/// Gets or sets the layout title.
/// </summary>
[JsonProperty("title")]
public string Title { get; set; }

/// <summary>
/// Gets or sets the keyboard tags.
/// </summary>
[JsonProperty("tags", NullValueHandling = NullValueHandling.Ignore)]
public List<ErgodoxTag> Tags { get; set; }

/// <summary>
/// Gets or sets the list of <see cref="Revision"/>.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/InvvardDev.EZLayoutDisplay.Desktop/Model/ErgodoxTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace InvvardDev.EZLayoutDisplay.Desktop.Model
{
public class ErgodoxTag
{
/// <summary>
/// Gets or sets the tag name.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
}
}
15 changes: 14 additions & 1 deletion src/InvvardDev.EZLayoutDisplay.Desktop/Model/Revision.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace InvvardDev.EZLayoutDisplay.Desktop.Model
Expand All @@ -11,6 +12,18 @@ public class Revision
[JsonProperty("hashId")]
public string HashId { get; set; }

/// <summary>
/// Gets or sets the keyboard layout HEX file URL.
/// </summary>
[JsonProperty("hexUrl")]
public string HexUrl { get; set; }

/// <summary>
/// Gets or sets the keyboard layout sources zip URL.
/// </summary>
[JsonProperty("zipUrl")]
public string SourcesUrl { get; set; }

/// <summary>
/// Gets or sets the keyboard model.
/// </summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Profiles />
<Settings>
<Setting Name="ErgodoxLayoutUrl" Type="System.String" Scope="User">
<Value Profile="(Default)">https://configure.ergodox-ez.com/layouts/default/latest/0</Value>
<Value Profile="(Default)">https://configure.ergodox-ez.com/ergodox-ez/layouts/default/latest/0</Value>
</Setting>
<Setting Name="HotkeyShowLayout" Type="System.String" Scope="User">
<Value Profile="(Default)">{"modifiers":[0,1,2,4],"keycode":32}</Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ namespace InvvardDev.EZLayoutDisplay.Desktop.Service.Design
{
public class LayoutService : ILayoutService
{
public async Task<ErgodoxLayout> GetLayoutInfo(string layoutHashId)
{
Debug.WriteLine("Layout retrieved.");

var layoutInfo = new ErgodoxLayout();
layoutInfo.Title = "Layout title v1.0";

return await new Task<ErgodoxLayout>(() => layoutInfo);
}

/// <inheritdoc />
public async Task<ErgodoxLayout> GetErgodoxLayout(string layoutHashId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,37 @@ namespace InvvardDev.EZLayoutDisplay.Desktop.Service.Implementation
public class LayoutService : ILayoutService
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

private readonly string GetLayoutBody =
"{{\"operationName\":\"getLayout\",\"variables\":{{\"hashId\":\"{0}\"}},\"query\":\"query getLayout($hashId: String!) {{\\n Layout(hashId: $hashId) {{\\n ...LayoutData\\n }}\\n}}\\n\\nfragment LayoutData on Layout {{\\n hashId\\n title\\n revisions {{\\n hashId\\n model\\n layers {{\\n hashId\\n keys\\n position\\n title\\n color\\n }}\\n}}\\n}}\\n\"}}";

private readonly string GetLayoutInfoRequestBody =
"{{\"operationName\":\"getLayout\",\"variables\":{{\"hashId\":\"{0}\"}},\"query\":\"query getLayout($hashId: String!) {{\\n Layout(hashId: $hashId) {{\\n ...LayoutData\\n __typename\\n }}\\n}}\\n\\nfragment LayoutData on Layout {{\\n geometry\\n hashId\\n title\\n tags {{\\n id\\n hashId\\n name\\n }}\\n revisions {{\\n hexUrl\\n model\\n zipUrl\\n layers {{\\n position\\n title\\n }}\\n }}\\n __typename\\n}}\\n\"}}";

private const string GetLayoutRequestUri = "https://oryx.ergodox-ez.com/graphql";

#region ILayoutService implementation

/// <inheritdoc />
public async Task<ErgodoxLayout> GetErgodoxLayout(string layoutHashId)
public async Task<ErgodoxLayout> GetLayoutInfo(string layoutHashId)
{
Logger.TraceMethod();
Logger.DebugInputParam(nameof(layoutHashId), layoutHashId);

if (string.IsNullOrWhiteSpace(layoutHashId))
{
Logger.Error("Layout {0} was not found", layoutHashId);
// ReSharper disable once LocalizableElement
throw new ArgumentNullException(nameof(layoutHashId), $"Layout hash ID '{layoutHashId}' was not found.");
}

DataRoot layout;

using (HttpClient client = new HttpClient())
{
var body = string.Format(GetLayoutBody, layoutHashId);
Logger.Debug("Request body : {@body}", body);

var response = await client.PostAsync(GetLayoutRequestUri, new StringContent(body, Encoding.UTF8, "application/json"));
Logger.Debug("Response : {@response}", response);

var result = await response.Content.ReadAsStringAsync();
Logger.Debug("Content result : {@result}", result);
var info = await QueryData(layoutHashId, GetLayoutInfoRequestBody);

return info;
}

layout = JsonConvert.DeserializeObject<DataRoot>(result);
Logger.Debug("Deserialized layout : {@layout}", layout);
/// <inheritdoc />
public async Task<ErgodoxLayout> GetErgodoxLayout(string layoutHashId)
{
Logger.TraceMethod();
Logger.DebugInputParam(nameof(layoutHashId), layoutHashId);

if (layout?.LayoutRoot?.Layout == null)
{
Logger.Error("Layout {0} does not exist", layoutHashId);
throw new ArgumentException(layoutHashId, $"Hash ID \"{layoutHashId}\" does not exist");
}
}
var layout = await QueryData(layoutHashId, GetLayoutBody);

return layout.LayoutRoot.Layout;
return layout;
}

/// <inheritdoc />
Expand All @@ -80,11 +67,60 @@ public async Task<IEnumerable<KeyTemplate>> GetLayoutTemplate()
IEnumerable<KeyTemplate> layoutTemplate = await ReadLayoutDefinition();

return layoutTemplate;
}

#endregion

#region Private methods

private async Task<ErgodoxLayout> QueryData(string layoutHashId, string graphQlQuery)
{
ValidateLayoutHashId(layoutHashId);

var requestBody = string.Format(graphQlQuery, layoutHashId);

var layout = await HttpClientCall(requestBody);

if (layout?.LayoutRoot?.Layout == null)
{
Logger.Error("Layout {0} does not exist", layoutHashId);

throw new ArgumentException(layoutHashId, $"Hash ID \"{layoutHashId}\" does not exist");
}

return layout.LayoutRoot.Layout;
}

#endregion
private static void ValidateLayoutHashId(string layoutHashId)
{
if (!string.IsNullOrWhiteSpace(layoutHashId)) return;

#region Private methods
Logger.Error("Layout {0} was not found", layoutHashId);

// ReSharper disable once LocalizableElement
throw new ArgumentNullException(nameof(layoutHashId), $"Layout hash ID '{layoutHashId}' was not found.");
}

private async Task<DataRoot> HttpClientCall(string requestBody)
{
DataRoot layout;

using (HttpClient client = new HttpClient())
{
Logger.Debug("Request body : {@body}", requestBody);

var response = await client.PostAsync(GetLayoutRequestUri, new StringContent(requestBody, Encoding.UTF8, "application/json"));
Logger.Debug("Response : {@response}", response);

var result = await response.Content.ReadAsStringAsync();
Logger.Debug("Content result : {@result}", result);

layout = JsonConvert.DeserializeObject<DataRoot>(result);
Logger.Debug("Deserialized layout : {@layout}", layout);
}

return layout;
}

private async Task<IEnumerable<KeyTemplate>> ReadLayoutDefinition()
{
Expand All @@ -93,16 +129,17 @@ private async Task<IEnumerable<KeyTemplate>> ReadLayoutDefinition()
if (Resources.layoutDefinition.Length <= 0)
{
Logger.Warn("Layout definition is empty");

return new List<KeyTemplate>();
}

var layoutTemplate = await Task.Run(() => {
var json = Encoding.Default.GetString(Resources.layoutDefinition);
var json = Encoding.Default.GetString(Resources.layoutDefinition);

var layoutDefinition = JsonConvert.DeserializeObject<IEnumerable<KeyTemplate>>(json);
var layoutDefinition = JsonConvert.DeserializeObject<IEnumerable<KeyTemplate>>(json);

return layoutDefinition;
});
return layoutDefinition;
});

Logger.DebugOutputParam(nameof(layoutTemplate), layoutTemplate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ namespace InvvardDev.EZLayoutDisplay.Desktop.Service.Interface
{
public interface ILayoutService
{
/// <summary>
/// Gets the <see cref="ErgodoxLayout"/> basic info.
/// </summary>
/// <param name="layoutHashId">The layout hash ID to get.</param>
/// <returns>The <see cref="ErgodoxLayout"/>.</returns>
Task<ErgodoxLayout> GetLayoutInfo(string layoutHashId);

/// <summary>
/// Gets the <see cref="ErgodoxLayout"/>.
/// </summary>
Expand Down
17 changes: 0 additions & 17 deletions src/InvvardDev.EZLayoutDisplay.Desktop/Skins/AboutSkin.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,4 @@
<Setter Property="Margin" Value="5,0,0,0" />
</Style>

<Style TargetType="Button" x:Key="HyperlinkStyledButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<TextBlock Foreground="#FF0066CC"
Text="{TemplateBinding Content}"
TextDecorations="Underline"
FontFamily="Segoe UI"
FontSize="15"
Cursor="Hand" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="5,0,0,0" />
</Style>

</ResourceDictionary>
Loading