Skip to content

Commit

Permalink
Wrap telemetry in try/catch and move message to strings class
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenkuhn committed Apr 13, 2024
1 parent dfe5db1 commit 4cf6e6f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
24 changes: 12 additions & 12 deletions Source/v2/Meadow.Cli/Commands/Current/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ public async ValueTask ExecuteAsync(IConsole console)
_console = console;
CancellationToken = _console.RegisterCancellationHandler();

if (MeadowTelemetry.Current.ShouldAskForConsent)
try
{
AnsiConsole.MarkupLine(@$"
Let's improve the Meadow experience together
--------------------------------------------
To help improve the Meadow CLI, we'd like to collect anonymous usage data. This data helps us understand how the CLI is used, so we can make it better for everyone. This usage data not tied to individuals and no personally identifiable information is collected.
if (MeadowTelemetry.Current.ShouldAskForConsent)
{
AnsiConsole.MarkupLine(Strings.Telemetry.ConsentMessage);

Our privacy policy is available at https://www.wildernesslabs.co/privacy-policy.
var result = AnsiConsole.Confirm(Strings.Telemetry.AskToParticipate, defaultValue: true);
MeadowTelemetry.Current.SetTelemetryEnabled(result);
}

You can change your mind at any time by running the ""[bold]meadow analytics [[enable|disable]][/]"" command or by setting the [bold]{MeadowTelemetry.AnalyticsEnabledEnvironmentVariable}[/] environment variable to '1' or '0' ('true' or 'false', respectively).
");

var result = AnsiConsole.Confirm("Would you like to participate?", defaultValue: true);
MeadowTelemetry.Current.SetTelemetryEnabled(result);
MeadowTelemetry.Current.TrackCommand(GetCommandName());
}
catch
{
// Swallow any telemetry-related exceptions
}

MeadowTelemetry.Current.TrackCommand(GetCommandName());
await ExecuteCommand();
}
catch (Exception ex) when (ex is not CommandException && ex is not CliFx.Exceptions.CommandException)
Expand Down
19 changes: 18 additions & 1 deletion Source/v2/Meadow.Cli/Strings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Meadow.CLI;
using Meadow.Telemetry;

namespace Meadow.CLI;

public static class Strings
{
Expand Down Expand Up @@ -62,4 +64,19 @@ public static class Strings
public const string IsDfuUtilInstalled = "Is dfu-util installed?";
public const string RunMeadowDfuInstall = "Run 'meadow dfu install' to install";
public const string NewMeadowDeviceNotFound = "New Meadow device not found";

public static class Telemetry
{
public const string ConsentMessage = @$"
Let's improve the Meadow experience together
--------------------------------------------
To help improve the Meadow CLI, we'd like to collect anonymous usage data. This data helps us understand how the CLI is used, so we can make it better for everyone. This usage data not tied to individuals and no personally identifiable information is collected.
Our privacy policy is available at https://www.wildernesslabs.co/privacy-policy.
You can change your mind at any time by running the ""[bold]meadow analytics [[enable|disable]][/]"" command or by setting the [bold]{MeadowTelemetry.AnalyticsEnabledEnvironmentVariable}[/] environment variable to '1' or '0' ('true' or 'false', respectively).
";

public const string AskToParticipate = "Would you like to participate?";
}
}

0 comments on commit 4cf6e6f

Please sign in to comment.