Skip to content

Commit

Permalink
Finished up first rating UI and logic
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
madskristensen committed Jan 23, 2022
1 parent 20b34f1 commit 5790131
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/BaseClasses/DefaultConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BaseClasses
public class DefaultConfig : IRatingConfig
{
private const string _propertyName = "RatingIncrement";
public int RatingIncrements { get; set; }
public int RatingRequests { get; set; }

public async Task SaveAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion src/BaseClasses/IRatingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface IRatingConfig
{
int RatingIncrements { get; set; }
int RatingRequests { get; set; }

Task SaveAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace BaseClasses
{
public class RateMyExtension
public class RatingPrompt
{
private const string _urlFormat = "https://marketplace.visualstudio.com/items?itemName={0}#review-details";
private const int _minutesVisible = 2;
private bool _hasChecked;

public RateMyExtension(string marketplaceId, string extensionName, IRatingConfig config = null, int requestsBeforePrompt = 10)
public RatingPrompt(string marketplaceId, string extensionName, IRatingConfig config = null, int requestsBeforePrompt = 10)
{
MarketplaceId = marketplaceId ?? throw new ArgumentNullException(nameof(marketplaceId));
ExtensionName = extensionName ?? throw new ArgumentNullException(nameof(extensionName));
Expand All @@ -36,7 +36,7 @@ public RateMyExtension(string marketplaceId, string extensionName, IRatingConfig

public void RegisterSuccessfullUsage()
{
if (!_hasChecked)
if (!_hasChecked && Config.RatingRequests < RequestsBeforePrompt)
{
_hasChecked = true;
IncrementAsync().FireAndForget();
Expand All @@ -45,21 +45,23 @@ public void RegisterSuccessfullUsage()

public async Task ResetAsync()
{
Config.RatingIncrements = 0;
Config.RatingRequests = 0;
await Config.SaveAsync();
}

private async Task IncrementAsync()
{
if (Config.RatingIncrements > RequestsBeforePrompt)
await Task.Yield(); // Yield to allow any shutdown procedure to continue

if (VsShellUtilities.ShellIsShuttingDown)
{
return;
}

Config.RatingIncrements += 1;
Config.RatingRequests += 1;
await Config.SaveAsync();

if (Config.RatingIncrements == RequestsBeforePrompt)
if (Config.RatingRequests == RequestsBeforePrompt)
{
PromptAsync().FireAndForget();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Editor/EditorFeatures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class HideMargings : WpfTextViewCreationListener
private TableDataSource _dataSource;
private DocumentView _docView;
private Document _document;
private RateMyExtension _rating;
private RatingPrompt _rating;
private readonly DateTime _openedDate = DateTime.Now;

[Import] internal IBufferTagAggregatorFactoryService _bufferTagAggregator = null;
Expand Down
2 changes: 1 addition & 1 deletion src/MarkdownEditor2022.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Commands\EnablePreviewSyncCommand.cs" />
<Compile Include="MarkdownEditor2022Package.cs" />
<Compile Include="BaseClasses\RateMyExtension.cs" />
<Compile Include="BaseClasses\RatingPrompt.cs" />
<Compile Include="source.extension.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
2 changes: 1 addition & 1 deletion src/Options/AdvancedOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public class AdvancedOptions : BaseOptionModel<AdvancedOptions>, IRatingConfig
public bool ValidateHeaderIncrements { get; set; } = true;

[Browsable(false)]
public int RatingIncrements { get; set; }
public int RatingRequests { get; set; }
}
}

0 comments on commit 5790131

Please sign in to comment.