Skip to content

Commit

Permalink
[#352] Create Windows GUI (#426)
Browse files Browse the repository at this point in the history
* [352] client gui's

* decoupled UI error handling from HTTP

* create client UI project and wire up first shared page

* filesystem basics working

* some cleanup

* reorganize solution to optimize for code re-use

* try fix gh build

* try again

* layout and navmenu now shared

* rebase

* try to add bootstrap and css dependencies

* fix ioc wireup

* not really working yet

* webui working again, now using shared css/js resources

* clientUI now working with shared css/js

* app settings working

* peloton settings working

* move app settings to own component

* format settings page updated

* garmin settings page

* cleanup

* rebase

* progress on sync page and mfa

* sync page working

* fix some build warnings

* index page working

* attempt to fix gha pr check

* rename PelotonToGarminConsole to ConsoleClient

* update app name

* [352] basic publishing working

* logging is working

* attempt update prcheck to publish

* fix typo

* try publish ready to run

* comment out for now
  • Loading branch information
philosowaffle committed Nov 11, 2023
1 parent adb180b commit 2c7559e
Show file tree
Hide file tree
Showing 146 changed files with 3,801 additions and 1,784 deletions.
56 changes: 51 additions & 5 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
dotnet: [ '7.0']
os: [ubuntu-latest, windows-latest, macos-latest]
dotnet: ['7.0']
os: [windows-latest]

steps:
- uses: actions/checkout@v3
Expand All @@ -22,6 +22,9 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet }}

- name: Install MAUI Workloads
run: dotnet workload install maui --ignore-failed-sources

- name: Clean
run: dotnet clean --configuration Debug && dotnet nuget locals all --clear
Expand Down Expand Up @@ -55,18 +58,18 @@ jobs:
dotnet-version: ${{ matrix.dotnet }}

- name: Clean
run: dotnet clean ${{ github.workspace }}/src/PelotonToGarminConsole/PelotonToGarminConsole.csproj --configuration Release && dotnet nuget locals all --clear
run: dotnet clean ${{ github.workspace }}/src/ConsoleClient/ConsoleClient.csproj --configuration Release && dotnet nuget locals all --clear

- name: Restore
run: dotnet restore ${{ github.workspace }}/src/PelotonToGarminConsole/PelotonToGarminConsole.csproj
run: dotnet restore ${{ github.workspace }}/src/ConsoleClient/ConsoleClient.csproj

- name: Prepare env
run: |
echo "BUILD_VERSION=$Env:GITHUB_RUN_NUMBER-$Env:GITHUB_RUN_ID" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
echo "RUNNER_TOOL_CACHE=$Env:RUNNER_TOOL_CACHE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Publish ${{matrix.os}}
run: dotnet publish ${{ github.workspace }}/src/PelotonToGarminConsole/PelotonToGarminConsole.csproj --no-restore -c Release -r ${{ matrix.os }} -o ${{ github.workspace }}/dist/${{ matrix.os }} --version-suffix ${{ env.BUILD_VERSION }} --self-contained true
run: dotnet publish ${{ github.workspace }}/src/ConsoleClient/ConsoleClient.csproj --no-restore -c Release -r ${{ matrix.os }} -o ${{ github.workspace }}/dist/${{ matrix.os }} --version-suffix ${{ env.BUILD_VERSION }} --self-contained true

- name: Copy Config to Distro
run: cp ${{ github.workspace }}/configuration.example.json ${{ github.workspace }}/dist/${{ matrix.os }}/configuration.local.json
Expand Down Expand Up @@ -95,6 +98,49 @@ jobs:
with:
name: ${{ matrix.os }}_${{ env.BUILD_VERSION }}
path: ${{ github.workspace }}/dist/${{ matrix.os }}

#compile-distro-ui:
# name: Compile Distro UI
# runs-on: 'windows-latest'
# needs: build-and-test
# strategy:
# max-parallel: 1
# matrix:
# dotnet: [ '7.0' ]
# framework: ['net7.0-windows10.0.19041.0']
# os: [ 'win10-x64' ]

# steps:

# - uses: actions/checkout@v3
# - name: Setup .NET Core SDK ${{ matrix.dotnet }}
# uses: actions/setup-dotnet@v3
# with:
# dotnet-version: ${{ matrix.dotnet }}

# - name: Install MAUI Workloads
# run: dotnet workload install maui --ignore-failed-sources

# - name: Clean
# run: dotnet clean ${{ github.workspace }}/src/ClientUI/ClientUI.csproj --configuration Release && dotnet nuget locals all --clear

# - name: Restore
# run: dotnet restore ${{ github.workspace }}/src/ClientUI/ClientUI.csproj

# - name: Prepare env
# run: |
# echo "BUILD_VERSION=$Env:GITHUB_RUN_NUMBER-$Env:GITHUB_RUN_ID" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
# echo "RUNNER_TOOL_CACHE=$Env:RUNNER_TOOL_CACHE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append

# - name: Publish ${{matrix.os}}
# run: dotnet publish ${{ github.workspace }}/src/ClientUI/ClientUI.csproj --no-restore -c Release -f ${{ matrix.framework }} -p:RuntimeIdentifierOverride=${{ matrix.os }} -o ${{ github.workspace }}/dist/${{ matrix.os }}-ui

# # Create Build Artifact
# - name: Upload Artifact ${{ matrix.os }}_${{ env.BUILD_VERSION }}
# uses: actions/upload-artifact@v3
# with:
# name: ${{ matrix.os }}_${{ env.BUILD_VERSION }}
# path: ${{ github.workspace }}/dist/${{ matrix.os }}-ui/AppPackages

create_docker_images:
name: Publish Docker Images - PR
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_distros_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
echo "RUNNER_TOOL_CACHE=$Env:RUNNER_TOOL_CACHE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Publish ${{matrix.os}}
run: dotnet publish ${{ github.workspace }}/src/PelotonToGarminConsole/PelotonToGarminConsole.csproj --no-restore -c Release -r ${{ matrix.os }} -o ${{ github.workspace }}/dist/${{ matrix.os }} --version-suffix ${{ env.BUILD_VERSION }} --self-contained true
run: dotnet publish ${{ github.workspace }}/src/ConsoleClient/ConsoleClient.csproj --no-restore -c Release -r ${{ matrix.os }} -o ${{ github.workspace }}/dist/${{ matrix.os }} --version-suffix ${{ env.BUILD_VERSION }} --self-contained true

- name: Copy Config to Distro
run: cp ${{ github.workspace }}/configuration.example.json ${{ github.workspace }}/dist/${{ matrix.os }}/configuration.local.json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
echo "RUNNER_TOOL_CACHE=$Env:RUNNER_TOOL_CACHE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Publish ${{matrix.os}}
run: dotnet publish ${{ github.workspace }}/src/PelotonToGarminConsole/PelotonToGarminConsole.csproj --no-restore -c Release -r ${{ matrix.os }} -o ${{ github.workspace }}/dist/${{ matrix.os }} --self-contained true
run: dotnet publish ${{ github.workspace }}/src/ConsoleClient/ConsoleClient.csproj --no-restore -c Release -r ${{ matrix.os }} -o ${{ github.workspace }}/dist/${{ matrix.os }} --self-contained true

- name: Copy Config to Distro
run: cp ${{ github.workspace }}/configuration.example.json ${{ github.workspace }}/dist/${{ matrix.os }}/configuration.local.json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_peloton_to_garmin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
}
}
EOT
- run: /app/PelotonToGarminConsole
- run: /app/ConsoleClient
if: ${{ env.P2G_PELOTON__EMAIL && env.P2G_PELOTON__PASSWORD && env.P2G_GARMIN__EMAIL && env.P2G_GARMIN__PASSWORD }}
working-directory: /app
env:
Expand Down
30 changes: 16 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,19 @@ python/build/
*/**/bin/*
*/**/obj/*

# Dev Files
*.log
syncHistory.json
configuration.local.json
/.vs/PelotonToGarmin
/src/Api/data
/src/PelotonToGarminConsole/data
/src/PelotonToGarminConsole/python/**
/src/WebUI/wwwroot/lib
*/**/output/**
/Output
/.vs/ProjectSettings.json
.vs/
/.vscode/settings.json
# Dev Files
*.log
syncHistory.json
configuration.local.json
/.vs/PelotonToGarmin
/src/Api/data
/src/ConsoleClient/data
/src/ConsoleClient/python/**
/src/WebUI/wwwroot/lib
*/**/output/**
/Output
/.vs/ProjectSettings.json
.vs/
/.vscode/settings.json
/src/SharedUI/wwwroot/lib
/src/ClientUI/ClientUI.csproj.user
28 changes: 27 additions & 1 deletion PelotonToGarmin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PelotonToGarminConsole", "src\PelotonToGarminConsole\PelotonToGarminConsole.csproj", "{808B1164-D94D-456F-B0AF-E5DDE4B82B4A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleClient", "src\ConsoleClient\ConsoleClient.csproj", "{808B1164-D94D-456F-B0AF-E5DDE4B82B4A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Garmin", "src\Garmin\Garmin.csproj", "{3E0E0007-E67A-44BA-B819-40C6E2C2EC8C}"
EndProject
Expand Down Expand Up @@ -46,6 +46,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebUI", "src\WebUI\WebUI.cs
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api", "src\Api\Api.csproj", "{63A354CC-C2D3-4860-995E-C3072EC76C46}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedUI", "src\SharedUI\SharedUI.csproj", "{5A2D34BF-6301-489C-A53C-46A2105EC923}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientUI", "src\ClientUI\ClientUI.csproj", "{E3C986C7-56B2-409B-A17F-566955804D73}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api.Service", "src\Api.Service\Api.Service.csproj", "{AE7ED46D-B1F6-402F-AA9F-EE952984B3BA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api.Contract", "src\Api.Contract\Api.Contract.csproj", "{629769E4-3048-41B6-8818-141DED7AD8D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -88,6 +96,24 @@ Global
{63A354CC-C2D3-4860-995E-C3072EC76C46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63A354CC-C2D3-4860-995E-C3072EC76C46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63A354CC-C2D3-4860-995E-C3072EC76C46}.Release|Any CPU.Build.0 = Release|Any CPU
{5A2D34BF-6301-489C-A53C-46A2105EC923}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A2D34BF-6301-489C-A53C-46A2105EC923}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A2D34BF-6301-489C-A53C-46A2105EC923}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A2D34BF-6301-489C-A53C-46A2105EC923}.Release|Any CPU.Build.0 = Release|Any CPU
{E3C986C7-56B2-409B-A17F-566955804D73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3C986C7-56B2-409B-A17F-566955804D73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3C986C7-56B2-409B-A17F-566955804D73}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{E3C986C7-56B2-409B-A17F-566955804D73}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3C986C7-56B2-409B-A17F-566955804D73}.Release|Any CPU.Build.0 = Release|Any CPU
{E3C986C7-56B2-409B-A17F-566955804D73}.Release|Any CPU.Deploy.0 = Release|Any CPU
{AE7ED46D-B1F6-402F-AA9F-EE952984B3BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE7ED46D-B1F6-402F-AA9F-EE952984B3BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE7ED46D-B1F6-402F-AA9F-EE952984B3BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE7ED46D-B1F6-402F-AA9F-EE952984B3BA}.Release|Any CPU.Build.0 = Release|Any CPU
{629769E4-3048-41B6-8818-141DED7AD8D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{629769E4-3048-41B6-8818-141DED7AD8D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{629769E4-3048-41B6-8818-141DED7AD8D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{629769E4-3048-41B6-8818-141DED7AD8D7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.console
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then \
RID=linux-arm ; \
fi \
&& dotnet publish /build/src/PelotonToGarminConsole/PelotonToGarminConsole.csproj -c Release -r $RID -o /build/published --version-suffix $VERSION --self-contained ;
&& dotnet publish /build/src/ConsoleClient/ConsoleClient.csproj -c Release -r $RID -o /build/published --version-suffix $VERSION --self-contained ;

###################
# FINAL
Expand Down
2 changes: 1 addition & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ if [[ "$1" == "api" ]]; then
elif [[ "$1" == "webui" ]]; then
exec runuser -u p2g ./WebUI
else
exec runuser -u p2g ./PelotonToGarminConsole
exec runuser -u p2g ./ConsoleClient
fi
4 changes: 2 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Ensure that your code:
```
> dotnet restore
> dotnet build
> dotnet run ./src/PelotonToGarminConsole/PelotonToGarminConsole.csproj
> dotnet run ./src/ConsoleClient/ConsoleClient.csproj
```

## Package Windows exe
```
> dotnet publish ./src/PelotonToGarminConsole/PelotonToGarminConsole.csproj --no-restore -c Release -r win10-x64 -o ./dist --version-suffix local
> dotnet publish ./src/ConsoleClient/ConsoleClient.csproj --no-restore -c Release -r win10-x64 -o ./dist --version-suffix local
```

## Developing against garmin-upload python library
Expand Down
8 changes: 4 additions & 4 deletions docs/install/source.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To compile and run P2G on your machine, follow the below steps.
## To run P2G

```bash
> dotnet run --project ./src/PelotonToGarminConsole/PelotonToGarminConsole.csproj
> dotnet run --project ./src/ConsoleClient/ConsoleClient.csproj
```

## Updating
Expand All @@ -36,7 +36,7 @@ To compile and run P2G on your machine, follow the below steps.
> git fetch
> git pull
> cd peloton-to-garmin
> dotnet restore ./src/PelotonToGarminConsole/PelotonToGarminConsole.csproj
> dotnet build ./src/PelotonToGarminConsole/PelotonToGarminConsole.csproj
> dotnet run --project ./src/PelotonToGarminConsole/PelotonToGarminConsole.csproj
> dotnet restore ./src/ConsoleClient/ConsoleClient.csproj
> dotnet build ./src/ConsoleClient/ConsoleClient.csproj
> dotnet run --project ./src/ConsoleClient/ConsoleClient.csproj
```
6 changes: 3 additions & 3 deletions docs/install/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For convenience a compiled windows executable is provided. This can easily be do
1. In the unzipped directory find the `configuration.local.json` and open it in a text editor of your choice
1. Be sure to set your usernames and passwords in Garmin and Peloton config sections respectively.
1. Save and close the file
1. Find the `PelotonToGarminConsole.exe`
1. Find the `ConsoleClient.exe`
1. Double click to run it!

You can learn more about customizing your configuration file over in the [Configuration Section]({{ site.baseurl }}{% link configuration/index.md %}).
Expand All @@ -22,15 +22,15 @@ You can learn more about customizing your configuration file over in the [Config

1. Download and unzip the [latest stable release](https://github.com/philosowaffle/peloton-to-garmin/releases)
1. In the unzipped directory replace the `configuration.local.json` with your previous `configuration.local.json` file
1. Find the `PelotonToGarminConsole.exe`
1. Find the `ConsoleClient.exe`
1. Double click to run it!

## Rolling back to a previous version

1. Find the release you want from the [releases page](https://github.com/philosowaffle/peloton-to-garmin/releases)
1. Download and unzip the Windows exe from that relase (found in the `Assets` section)
1. In the unzipped directory replace the `configuration.local.json` with your previous `configuration.local.json` file
1. Find the `PelotonToGarminConsole.exe`
1. Find the `ConsoleClient.exe`
1. Double click to run it!

## Available Versions
Expand Down
17 changes: 17 additions & 0 deletions src/Api.Contract/Api.Contract.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Common.Dto.Api;
namespace Api.Contract;

public record GarminAuthenticationMfaTokenPostRequest
{
public string MfaToken { get; set; }
public string? MfaToken { get; set; }
}

public record GarminAuthenticationGetResponse
Expand Down
34 changes: 34 additions & 0 deletions src/Api.Contract/IError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Api.Contract;

public interface IErrorResponse
{
public string Message { get; set; }
public ErrorCode Code { get; set; }
}

public class ErrorResponse : IErrorResponse
{
public string Message { get; set; }
public ErrorCode Code { get; set; }
public Exception? Exception { get; set; }

public ErrorResponse(string message, Exception? ex = null)
{
Message = message;
}

public ErrorResponse(string message, ErrorCode code, Exception? ex = null)
{
Message = message;
Code = code;
}
}

public enum ErrorCode : ushort
{
None = 0,

NeedToInitGarminMFAAuth = 100,
UnexpectedGarminMFA = 101,
InvalidGarminCredentials = 102,
}
20 changes: 2 additions & 18 deletions src/Common/Dto/Api/IPaging.cs → src/Api.Contract/IPaging.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Common.Helpers;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace Common.Dto.Api;
namespace Api.Contract;

public interface IPagingRequest
{
Expand Down Expand Up @@ -38,19 +37,4 @@ public abstract class PagingResponseBase<T> : IPagingResponse<T>

public abstract ICollection<T> Items { get; set; }

}

public static class PagingExtensions
{
public static bool IsValid(this IPagingRequest request, out ActionResult result)
{
if (request.PageSize.CheckIsLessThanOrEqualTo(0, nameof(request.PageSize), out result))
return false;

if (request.PageIndex.CheckIsLessThan(0, nameof(request.PageIndex), out result))
return false;

return true;
}
}

}
Loading

0 comments on commit 2c7559e

Please sign in to comment.