-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
boost(Update::Postpone): The more the user postpone, the longer it wa…
…its before asking to update. Start with 3 days, then 7 days, then 12 days, then 19 days then 28 days. 28 days is the maximum. Fixes #528
- Loading branch information
Showing
6 changed files
with
73 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using Serilog; | ||
using SoundSwitch.Framework.Configuration; | ||
|
||
namespace SoundSwitch.Framework.Updater.Remind | ||
{ | ||
public class PostponeService | ||
{ | ||
/// <summary> | ||
/// Set the release as postponed | ||
/// </summary> | ||
/// <param name="release"></param> | ||
public void PostponeRelease(Release release) | ||
{ | ||
var postponed = AppConfigs.Configuration.Postponed; | ||
try | ||
{ | ||
if (postponed == null || postponed.Version < release.ReleaseVersion) | ||
{ | ||
AppConfigs.Configuration.Postponed = new ReleasePostponed(release.ReleaseVersion, DateTime.UtcNow + 3 * TimeSpan.FromSeconds(AppConfigs.Configuration.UpdateCheckInterval), 1); | ||
return; | ||
} | ||
|
||
if (postponed.Version == release.ReleaseVersion) | ||
{ | ||
var postponedCount = postponed.Count + 1; | ||
if (postponedCount > 5) | ||
{ | ||
postponedCount = 5; | ||
} | ||
AppConfigs.Configuration.Postponed = postponed with | ||
{ | ||
Count = postponedCount, Until = DateTime.UtcNow + (3 + (postponedCount ^ 2)) * TimeSpan.FromSeconds(AppConfigs.Configuration.UpdateCheckInterval) | ||
}; | ||
} | ||
} | ||
finally | ||
{ | ||
Log.Information($"Release {release} set as {AppConfigs.Configuration.Postponed}"); | ||
AppConfigs.Configuration.Save(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Return true if the release should be postponed, false if it can be done now. | ||
/// </summary> | ||
/// <param name="release"></param> | ||
/// <returns></returns> | ||
public bool ShouldPostpone(Release release) | ||
{ | ||
var postponed = AppConfigs.Configuration.Postponed; | ||
if (postponed == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (release.ReleaseVersion > postponed.Version) | ||
{ | ||
return false; | ||
} | ||
|
||
return postponed.Until > DateTime.UtcNow; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters