Skip to content

Commit

Permalink
Detect new donor and offer splash screen hide.
Browse files Browse the repository at this point in the history
Treat previous subscribers as donors.
  • Loading branch information
phw198 committed Nov 7, 2021
1 parent f2dfa41 commit 8542794
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ private void updateGUIsettings() {
cbStartOnStartup.Checked = Settings.Instance.StartOnStartup;
tbStartupDelay.Value = Settings.Instance.StartupDelay;
tbStartupDelay.Enabled = cbStartOnStartup.Checked;
cbHideSplash.Checked = Settings.Instance.HideSplashScreen;
cbHideSplash.Checked = Settings.Instance.HideSplashScreen ?? false;
cbSuppressSocialPopup.Checked = Settings.Instance.SuppressSocialPopup;
cbStartInTray.Checked = Settings.Instance.StartInTray;
cbMinimiseToTray.Checked = Settings.Instance.MinimiseToTray;
Expand Down Expand Up @@ -453,7 +453,7 @@ private void updateGUIsettings() {
dgAbout.Rows[r].Cells[1].Value = Settings.ConfigFile;
dgAbout.Rows.Add(); r++;
dgAbout.Rows[r].Cells[0].Value = "Subscription";
dgAbout.Rows[r].Cells[1].Value = (Settings.Instance.Subscribed == DateTime.Parse("01-Jan-2000")) ? "N/A" : Settings.Instance.Subscribed.ToShortDateString();
dgAbout.Rows[r].Cells[1].Value = (Settings.Instance.Subscribed <= GoogleOgcs.Authenticator.SubscribedBefore) ? "N/A" : Settings.Instance.Subscribed.ToShortDateString();
dgAbout.Rows.Add(); r++;
dgAbout.Rows[r].Cells[0].Value = "Timezone DB";
dgAbout.Rows[r].Cells[1].Value = TimezoneDB.Instance.Version;
Expand Down
9 changes: 5 additions & 4 deletions src/OutlookGoogleCalendarSync/Forms/Splash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ private static void doShowSplash() {
donor = (XMLManager.ImportElement("Donor", Settings.ConfigFile) ?? "false") == "true";

String subscribedDate = XMLManager.ImportElement("Subscribed", Settings.ConfigFile);
if (string.IsNullOrEmpty(subscribedDate)) subscribedDate = "01-Jan-2000";
subscribed = DateTime.Parse(subscribedDate);
if (!string.IsNullOrEmpty(subscribedDate)) subscribed = DateTime.Parse(subscribedDate);
else subscribed = GoogleOgcs.Authenticator.SubscribedNever;

Boolean hideSplash = (XMLManager.ImportElement("HideSplashScreen", Settings.ConfigFile) ?? "false") == "true";
initialised = true;

splash.cbHideSplash.Checked = hideSplash;
if (subscribed == DateTime.Parse("01-Jan-2000") && !donor) {
if (subscribed == GoogleOgcs.Authenticator.SubscribedNever && !donor) {
ToolTips = new ToolTip {
AutoPopDelay = 10000,
InitialDelay = 500,
Expand Down Expand Up @@ -114,7 +115,7 @@ private void Splash_Shown(object sender, EventArgs e) {
private void cbHideSplash_CheckedChanged(object sender, EventArgs e) {
if (!this.Visible) return;

if (subscribed == DateTime.Parse("01-Jan-2000") && !donor) {
if (subscribed == GoogleOgcs.Authenticator.SubscribedNever && !donor) {
this.cbHideSplash.CheckedChanged -= cbHideSplash_CheckedChanged;
cbHideSplash.Checked = false;
this.cbHideSplash.CheckedChanged += cbHideSplash_CheckedChanged;
Expand Down
23 changes: 18 additions & 5 deletions src/OutlookGoogleCalendarSync/GoogleOgcs/Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static ClientSecrets getCalendarClientSecrets() {
} else {
ApiKeyring apiKeyring = new ApiKeyring();

if (Settings.Instance.Subscribed != null && Settings.Instance.Subscribed != DateTime.Parse("01-Jan-2000"))
if (Settings.Instance.Subscribed != null && Settings.Instance.Subscribed != SubscribedNever && Settings.Instance.Subscribed != SubscribedBefore)
apiKeyring.PickKey(ApiKeyring.KeyType.Subscriber);
else
apiKeyring.PickKey(ApiKeyring.KeyType.Standard);
Expand Down Expand Up @@ -298,11 +298,21 @@ public static String GetMd5(String input, Boolean isEmailAddress = false) {
}

#region OGCS user status
public static readonly DateTime SubscribedNever = new DateTime(2000, 1, 1);
public static readonly DateTime SubscribedBefore = new DateTime(2001, 1, 1);

public void OgcsUserStatus() {
if (!checkedOgcsUserStatus) {
UserSubscriptionCheck();
userDonationCheck();
checkedOgcsUserStatus = true;

if (Settings.Instance.UserIsBenefactor() && Settings.Instance.HideSplashScreen == null) {
DialogResult dr = OgcsMessageBox.Show("Thank you for your support of OGCS!\r\nWould you like the splash screen to be hidden from now on?", "Hide Splash Screen?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);

Settings.Instance.HideSplashScreen = (dr == DialogResult.Yes);
}
}
}

Expand Down Expand Up @@ -359,7 +369,7 @@ public Boolean UserSubscriptionCheck() {
List<Event> subscriptions = result.Where(x => x.Summary == HashedGmailAccount).ToList();
if (subscriptions.Count == 0) {
log.Fine("This user has never subscribed.");
Settings.Instance.Subscribed = DateTime.Parse("01-Jan-2000");
Settings.Instance.Subscribed = SubscribedNever;
return false;
} else {
Boolean subscribed;
Expand All @@ -385,7 +395,7 @@ public Boolean UserSubscriptionCheck() {
Settings.Instance.Subscribed = subscriptionStart;
} else {
log.Info("User has no active subscription.");
Settings.Instance.Subscribed = DateTime.Parse("01-Jan-2000");
Settings.Instance.Subscribed = SubscribedBefore;
}

//Check for any unmigrated entries
Expand All @@ -394,8 +404,11 @@ public Boolean UserSubscriptionCheck() {
Forms.Main.Instance.Console.CallGappScript("subscriber");

if (prevSubscriptionStart != Settings.Instance.Subscribed) {
if (prevSubscriptionStart == DateTime.Parse("01-Jan-2000") //No longer a subscriber
|| Settings.Instance.Subscribed == DateTime.Parse("01-Jan-2000")) //New subscriber
if (((Settings.Instance.Subscribed != SubscribedNever && Settings.Instance.Subscribed != SubscribedBefore) &&
(prevSubscriptionStart == SubscribedNever || prevSubscriptionStart == SubscribedBefore)) //Newly subscribed
||
((Settings.Instance.Subscribed == SubscribedNever || Settings.Instance.Subscribed == SubscribedBefore) &&
(prevSubscriptionStart != SubscribedNever && prevSubscriptionStart != SubscribedBefore))) //No longer subscribed
{
ApiKeyring.ChangeKeys();
}
Expand Down
12 changes: 6 additions & 6 deletions src/OutlookGoogleCalendarSync/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void InitialiseConfigFile(String filename, String directory = null
private String version;
private Boolean donor;
private DateTime subscribed;
private Boolean hideSplashScreen;
private bool? hideSplashScreen;
private Boolean suppressSocialPopup;
private bool? cloudLogging;

Expand Down Expand Up @@ -151,9 +151,9 @@ private void setDefaults() {

alphaReleases = !System.Windows.Forms.Application.ProductVersion.EndsWith("0.0");
SkipVersion = null;
subscribed = DateTime.Parse("01-Jan-2000");
subscribed = GoogleOgcs.Authenticator.SubscribedNever;
donor = false;
hideSplashScreen = false;
hideSplashScreen = null;
suppressSocialPopup = false;

ExtirpateOgcsMetadata = false;
Expand Down Expand Up @@ -314,12 +314,12 @@ public class ColourMappingDictionary : Dictionary<String, String> { }

#endregion
#region App behaviour
[DataMember] public bool HideSplashScreen {
[DataMember] public bool? HideSplashScreen {
get { return hideSplashScreen; }
set {
if (!loading() && hideSplashScreen != value) {
XMLManager.ExportElement("HideSplashScreen", value, ConfigFile);
if (Forms.Main.Instance != null) Forms.Main.Instance.cbHideSplash.Checked = value;
if (Forms.Main.Instance != null) Forms.Main.Instance.cbHideSplash.Checked = value ?? false;
}
hideSplashScreen = value;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ [DataMember] public bool AlphaReleases {
}
}
public Boolean UserIsBenefactor() {
return Subscribed != DateTime.Parse("01-Jan-2000") || donor;
return Subscribed != GoogleOgcs.Authenticator.SubscribedNever || donor;
}
[DataMember] public DateTime Subscribed {
get { return subscribed; }
Expand Down

0 comments on commit 8542794

Please sign in to comment.