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

Add to SystemInformation class #1533

Merged

Conversation

mrlacey
Copy link
Contributor

@mrlacey mrlacey commented Oct 2, 2017

For #1505
Porting of some logic from WTS + extra useful app usage and analytical information
Adds Properties: IsFirstRun; IsAppUpdated; FirstVersionInstalled; FirstUseTime; LastLaunchTime; LaunchTime; LaunchCount; AppUptime
Adds Methods: TrackAppUse(); LaunchStoreForReviewAsync()

@mrlacey mrlacey changed the title Is first run or updated helper Add to SystemInformation class Oct 2, 2017
}
}

private static DateTime _sessionStart;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to move it to the top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will move

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This one is necessary

}
else
{
return TimeSpan.MinValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just use TimeSpan.Zero though MinValue works too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zero has the possibility that it might be valid if checked as soon as the app starts. MinValue will never be valid and so can always be used as a comparison and indicates the value has not been set without the overhead of considering nullability.

/// <param name="args">Details about the launch request and process.</param>
public static void TrackAppUse(LaunchActivatedEventArgs args)
{
if (new[] { ApplicationExecutionState.ClosedByUser, ApplicationExecutionState.NotRunning }.Contains(args.PreviousExecutionState))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be simpler to just use a standard if statement rather than creating an array to only do contains ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this as it's shorter than if (args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser || args.PreviousExecutionState == ApplicationExecutionState.NotRunning) as everything is only mentioned once. I also use it as a general approach as it makes it easier to add additional comparisons against the same value in the future. Shouldn't be relevant here, but just trying to explain my reasoning.
Simpler is subjective. Must this be changed to be accepted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I felt sufficiently strong about these then I would have requested changes. Thoughts just based on a quick glance. I will let others go through this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Hermit is right, creating new array will consume some memory that we don't need :) I know an array of 2 doesn't add much to memory but it is just a practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to better meet expectations of how it would normally be done.

Copy link
Contributor

@nmetulev nmetulev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just have few minor requests.

Also, could you pull in master in here to make sure it's tested with the latest

public static string FirstVersionInstalled { get; }

/// <summary>
/// Gets the DateTime (in UTC) that the app as first used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording feels confusing. How about

Gets the DateTime (in UTC) when the app was launched for the first time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// To get if the app is being used for the first time since it was installed.
public string IsFirstUse => SystemInformation.IsFirstRun.ToString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the ToString on all the properties in the bind file. It hides the return type of the property/function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/// Gets the first version of the app that was installed.
/// This will be the current version if a previous verison of the app was installed before accessing this property.
/// </summary>
public static string FirstVersionInstalled { get; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this match the ApplicationVersion return type of PackageVersion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed but had to add a PackageVersionHelper as PackageVersion isn't serializable.
Should the methods in this new helper class have extra specific error handling? or happy to just let any formatting errors bubble up from usage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the error bubbling up as you already have the format in the param description

public static DateTime FirstUseTime { get; }

/// <summary>
/// Gets the DateTime (in UTC) that this was previously launched.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd reword this to

Gets the DateTime (in UTC) when the app was previously launched, not including this instance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@IbraheemOsama IbraheemOsama merged commit 384b9dc into CommunityToolkit:master Oct 12, 2017
@mrlacey mrlacey deleted the IsFirstRunOrUpdatedHelper branch October 17, 2017 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants