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

fix: remove ReadLine from console app when not polling #677

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
6 changes: 4 additions & 2 deletions mkdocs/docs/configuration/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ The App Settings provide global settings for the P2G application.
"App": {
"EnablePolling": true,
"PollingIntervalSeconds": 86400,
"CheckForUpdates": true
"CheckForUpdates": true,
"WantFinalReadLineInConsole": true
}
```

Expand All @@ -27,4 +28,5 @@ The App Settings provide global settings for the P2G application.
|:-----------|:---------|:--------|:------------|
| EnablePolling | no | `true` | `true` if you wish P2G to run continuously and poll Peloton for new workouts. |
| PollingIntervalSeconds | no | 86400 | The polling interval in seconds determines how frequently P2G should check for new workouts. Be warned, that setting this to a frequency of hourly or less may get you flagged by Peloton as a bad actor and they may reset your password. The default is set to Daily. |
| CheckForUpdates | no | `true` | `true` if P2G should check for updates and write a log message if a new release is available. If using the UI this message will display there as well. |
| CheckForUpdates | no | `true` | `true` if P2G should check for updates and write a log message if a new release is available. If using the UI this message will display there as well. |
| WantFinalReadLineInConsole | no | `true` | `true` if the P2G console app should invoke Console.ReadLine() before exiting. This allows users to view any diagnostics or error messages. You may want to set this to `false` if running in a headless container environment. This affects only the console app.|
186 changes: 94 additions & 92 deletions src/Common/Dto/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,140 +12,142 @@ namespace Common.Dto;
/// </summary>
public class Settings
{
public Settings()
{
App = new ();
Format = new ();
Peloton = new ();
Garmin = new ();
}

public App App { get; set; }
public Format Format { get; set; }
public PelotonSettings Peloton { get; set; }
public GarminSettings Garmin { get; set; }
public Settings()
{
App = new ();
Format = new ();
Peloton = new ();
Garmin = new ();
}

public App App { get; set; }
public Format Format { get; set; }
public PelotonSettings Peloton { get; set; }
public GarminSettings Garmin { get; set; }
}

public class App
{
public App()
{
CheckForUpdates = true;
EnablePolling = false;
PollingIntervalSeconds = 86400; // 1 day
}
public App()
{
CheckForUpdates = true;
EnablePolling = false;
WantFinalReadLineInConsole = true;
PollingIntervalSeconds = 86400; // 1 day
}

public bool EnablePolling { get; set; }
public int PollingIntervalSeconds { get; set; }
public bool CheckForUpdates { get; set; }
public bool EnablePolling { get; set; }
public bool WantFinalReadLineInConsole { get; set; }
public int PollingIntervalSeconds { get; set; }
public bool CheckForUpdates { get; set; }

public static string DataDirectory => Path.GetFullPath(Path.Join(Statics.DefaultDataDirectory, "data"));
public static string DataDirectory => Path.GetFullPath(Path.Join(Statics.DefaultDataDirectory, "data"));

public string WorkingDirectory => Statics.DefaultTempDirectory;
public string OutputDirectory => Statics.DefaultOutputDirectory;
public string FailedDirectory => Path.GetFullPath(Path.Join(OutputDirectory, "failed"));
public string DownloadDirectory => Path.GetFullPath(Path.Join(WorkingDirectory, "downloaded"));
public string UploadDirectory => Path.GetFullPath(Path.Join(WorkingDirectory, "upload"));
public string WorkingDirectory => Statics.DefaultTempDirectory;
public string OutputDirectory => Statics.DefaultOutputDirectory;
public string FailedDirectory => Path.GetFullPath(Path.Join(OutputDirectory, "failed"));
public string DownloadDirectory => Path.GetFullPath(Path.Join(WorkingDirectory, "downloaded"));
public string UploadDirectory => Path.GetFullPath(Path.Join(WorkingDirectory, "upload"));


}

public class Format
{
public Format()
{
Cycling = new Cycling();
Running = new Running();
Rowing = new Rowing();
Strength = new Strength();
}

[JsonIgnore]
public static readonly Dictionary<WorkoutType, GarminDeviceInfo> DefaultDeviceInfoSettings = new Dictionary<WorkoutType, GarminDeviceInfo>()
{
{ WorkoutType.None, GarminDevices.Forerunner945 },
{ WorkoutType.Cycling, GarminDevices.TACXDevice },
{ WorkoutType.Rowing, GarminDevices.EpixDevice },
};

public bool Fit { get; set; }
public bool Json { get; set; }
public bool Tcx { get; set; }
public bool SaveLocalCopy { get; set; }
public bool IncludeTimeInHRZones { get; set; }
public bool IncludeTimeInPowerZones { get; set; }
[Obsolete("Use DeviceInfoSettings instead. Will be removed in P2G v5.")]
public string DeviceInfoPath { get; set; }
public Dictionary<WorkoutType, GarminDeviceInfo> DeviceInfoSettings { get; set; }
public string WorkoutTitleTemplate { get; set; } = "{{PelotonWorkoutTitle}}{{#if PelotonInstructorName}} with {{PelotonInstructorName}}{{/if}}";
public Cycling Cycling { get; set; }
public Running Running { get; set; }
public Rowing Rowing { get; init; }
public Strength Strength { get; init; }
public Format()
{
Cycling = new Cycling();
Running = new Running();
Rowing = new Rowing();
Strength = new Strength();
}

[JsonIgnore]
public static readonly Dictionary<WorkoutType, GarminDeviceInfo> DefaultDeviceInfoSettings = new Dictionary<WorkoutType, GarminDeviceInfo>()
{
{ WorkoutType.None, GarminDevices.Forerunner945 },
{ WorkoutType.Cycling, GarminDevices.TACXDevice },
{ WorkoutType.Rowing, GarminDevices.EpixDevice },
};

public bool Fit { get; set; }
public bool Json { get; set; }
public bool Tcx { get; set; }
public bool SaveLocalCopy { get; set; }
public bool IncludeTimeInHRZones { get; set; }
public bool IncludeTimeInPowerZones { get; set; }
[Obsolete("Use DeviceInfoSettings instead. Will be removed in P2G v5.")]
public string DeviceInfoPath { get; set; }
public Dictionary<WorkoutType, GarminDeviceInfo> DeviceInfoSettings { get; set; }
public string WorkoutTitleTemplate { get; set; } = "{{PelotonWorkoutTitle}}{{#if PelotonInstructorName}} with {{PelotonInstructorName}}{{/if}}";
public Cycling Cycling { get; set; }
public Running Running { get; set; }
public Rowing Rowing { get; init; }
public Strength Strength { get; init; }
}

public record Cycling
{
public PreferredLapType PreferredLapType { get; set; }
public PreferredLapType PreferredLapType { get; set; }
}

public record Running
{
public PreferredLapType PreferredLapType { get; set; }
public PreferredLapType PreferredLapType { get; set; }
}

public record Rowing
{
public PreferredLapType PreferredLapType { get; set; }
public PreferredLapType PreferredLapType { get; set; }
}

public record Strength
{
/// <summary>
/// When no Rep information is provided by Peloton, P2G will calculate number
/// of reps based on this default value. Example, if your DefaultNumSecondsPerRep is 3,
/// and the Exercise duration was 15 seconds, then P2G would credit you with 5 reps for that
/// exercise.
/// </summary>
public int DefaultSecondsPerRep { get; set; } = 3;
/// <summary>
/// When no Rep information is provided by Peloton, P2G will calculate number
/// of reps based on this default value. Example, if your DefaultNumSecondsPerRep is 3,
/// and the Exercise duration was 15 seconds, then P2G would credit you with 5 reps for that
/// exercise.
/// </summary>
public int DefaultSecondsPerRep { get; set; } = 3;
}

public enum PreferredLapType
{
Default = 0,
Distance = 1,
Class_Segments = 2,
Class_Targets = 3
Default = 0,
Distance = 1,
Class_Segments = 2,
Class_Targets = 3
}

public class PelotonSettings : ICredentials
{
public PelotonSettings()
{
ExcludeWorkoutTypes = new List<WorkoutType>();
NumWorkoutsToDownload = 5;
}

public EncryptionVersion EncryptionVersion { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public int NumWorkoutsToDownload { get; set; }
public ICollection<WorkoutType> ExcludeWorkoutTypes { get; set; }
public PelotonSettings()
{
ExcludeWorkoutTypes = new List<WorkoutType>();
NumWorkoutsToDownload = 5;
}

public EncryptionVersion EncryptionVersion { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public int NumWorkoutsToDownload { get; set; }
public ICollection<WorkoutType> ExcludeWorkoutTypes { get; set; }
}

public class GarminSettings : ICredentials
{
public EncryptionVersion EncryptionVersion { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool TwoStepVerificationEnabled { get; set; }
public bool Upload { get; set; }
public FileFormat FormatToUpload { get; set; }
public EncryptionVersion EncryptionVersion { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool TwoStepVerificationEnabled { get; set; }
public bool Upload { get; set; }
public FileFormat FormatToUpload { get; set; }
}

public enum FileFormat : byte
{
Fit = 0,
Tcx = 1,
Json = 2
}
Fit = 0,
Tcx = 1,
Json = 2
}
Loading