Skip to content

Commit

Permalink
Merge branch 'release' into feature-wip/release-code-refactor-google
Browse files Browse the repository at this point in the history
  • Loading branch information
phw198 committed May 19, 2024
2 parents 1bfb06e + 79f5925 commit 80e84d6
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 19 deletions.
11 changes: 9 additions & 2 deletions src/OutlookGoogleCalendarSync/Extensions/MenuButton.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

Expand All @@ -10,8 +11,12 @@ public partial class MenuButton : Button {
[DefaultValue(20), Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int SplitWidth { get; set; }

[DefaultValue(true)]
public Boolean MenuEnabled { get; set; }

public MenuButton() {
SplitWidth = 20;
MenuEnabled = true;
}

protected override void OnMouseDown(MouseEventArgs mevent) {
Expand All @@ -20,6 +25,8 @@ protected override void OnMouseDown(MouseEventArgs mevent) {

// Figure out if the button click was on the button itself or the menu split
if (Menu != null && mevent.Button == MouseButtons.Left && splitRect.Contains(mevent.Location)) {
if (!this.MenuEnabled) return;

if (this.Menu.Visible) {
this.Tag = "CloseRequested";
this.Menu.Hide();
Expand All @@ -40,7 +47,7 @@ protected override void OnPaint(PaintEventArgs pEvent) {
int arrowX = ClientRectangle.Width - (int)(SplitWidth - ((SplitWidth - 7)/2));
int arrowY = ClientRectangle.Height / 2 - 1;

var arrowBrush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow;
var arrowBrush = (Enabled && MenuEnabled) ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow;
var arrows = new[] { new Point(arrowX, arrowY), new Point(arrowX + 7, arrowY), new Point(arrowX + 3, arrowY + 4) };
pEvent.Graphics.FillPolygon(arrowBrush, arrows);

Expand Down
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/OutlookGoogleCalendarSync/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Main(string startingTab = null) {
gbAppBehaviour_Proxy.MinimumSize =
gbAppBehaviour_Logging.MinimumSize = new System.Drawing.Size(0, 0);

Program.Updater.CheckForUpdate(btCheckForUpdate);
Program.Updater.CheckForUpdate();

if (startingTab != null && startingTab == "Help") this.tabApp.SelectedTab = this.tabPage_Help;

Expand Down Expand Up @@ -1011,11 +1011,12 @@ public void MainFormShow(Boolean forceToTop = false) {
if (this.WindowState == FormWindowState.Minimized || !this.Visible || !this.TopMost || !this.ShowInTaskbar) {
this.tbSyncNote.ScrollBars = RichTextBoxScrollBars.None; //Reset scrollbar
this.Show(); //Show minimised back in taskbar
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
if (forceToTop) this.TopMost = true;
this.tbSyncNote.ScrollBars = RichTextBoxScrollBars.Vertical; //Show scrollbar if necessary
this.Show(); //Now restore
if (this.Location.X < 0 || this.Location.Y < 0) this.CenterToScreen();
this.TopMost = false;
this.Refresh();
System.Windows.Forms.Application.DoEvents();
Expand Down
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/NotificationTray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void RemoveProfileItem(String itemText) {
/// </summary>
public void UpdateAutoSyncItems() {
Boolean autoSyncing = Settings.Instance.Calendars.Any(c =>
(c.OgcsTimer != null && c.OgcsTimer.Running()) ||
(c.OgcsTimer != null && c.OgcsTimer.IsRunning) ||
(c.OgcsTimer == null && (c.SyncInterval != 0 || c.OutlookPush)));

UpdateItem("autoSyncToggle", autoSyncing ? "Disable" : "Enable");
Expand Down
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/SettingsStore/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ public void RegisterForPushSync() {
log.Info("Start monitoring for Outlook appointments changes on profile: " + this._ProfileName);
if (this.OgcsPushTimer == null)
this.OgcsPushTimer = new Sync.PushSyncTimer(this);
if (!this.OgcsPushTimer.Running())
if (!this.OgcsPushTimer.IsRunning)
this.OgcsPushTimer.Activate(true);
}

public void DeregisterForPushSync() {
log.Info("Stop monitoring for Outlook appointment changes on profile: " + this._ProfileName);
if (this.OgcsPushTimer != null && this.OgcsPushTimer.Running())
if (this.OgcsPushTimer != null && this.OgcsPushTimer.IsRunning)
this.OgcsPushTimer.Activate(false);
}
#endregion
Expand Down
2 changes: 2 additions & 0 deletions src/OutlookGoogleCalendarSync/Sync/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public Calendar() {
public void StartSync(Boolean manualIgnition, Boolean updateSyncSchedule = true) {
Forms.Main mainFrm = Forms.Main.Instance;
mainFrm.bSyncNow.Text = "Stop Sync";
mainFrm.bSyncNow.MenuEnabled = false;
mainFrm.NotificationTray.UpdateItem("sync", "&Stop Sync");

this.Profile.LogSettings();
Expand Down Expand Up @@ -219,6 +220,7 @@ public void StartSync(Boolean manualIgnition, Boolean updateSyncSchedule = true)
Sync.Engine.Instance.bwSync?.Dispose();
Sync.Engine.Instance.bwSync = null;
Sync.Engine.Instance.ActiveProfile = null;
mainFrm.bSyncNow.MenuEnabled = true;
mainFrm.bSyncNow.Text = "Start Sync";
mainFrm.NotificationTray.UpdateItem("sync", "&Sync Now");
if (Settings.Instance.MuteClickSounds) Console.MuteClicks(false);
Expand Down
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/Sync/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void Sync_Requested(object sender = null, EventArgs e = null) {
Ogcs.Extensions.MessageBox.Show("A sync is already running. Please wait for it to complete and then try again.", "Sync already running", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return;
}
if (Control.ModifierKeys == Keys.Shift) {
if (Control.ModifierKeys == Keys.Shift || Forms.Main.Instance.bSyncNow.Text == "Start Full Sync") {
if (Forms.Main.Instance.ActiveCalendarProfile.SyncDirection == Direction.Bidirectional) {
Ogcs.Extensions.MessageBox.Show("Forcing a full sync is not allowed whilst in 2-way sync mode.\r\nPlease temporarily chose a direction to sync in first.",
"2-way full sync not allowed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Expand Down
28 changes: 18 additions & 10 deletions src/OutlookGoogleCalendarSync/Sync/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ private void ogcsTimer_Tick(object sender, EventArgs e) {

log.Debug("Scheduled sync triggered for profile: "+ Settings.Profile.Name(this.owningProfile));

if ((DateTime.Now - TimezoneDB.LastSystemResume).TotalSeconds < 60) {
log.Debug("Too soon after system resume; delaying for 60 seconds...");
System.Threading.Thread.Sleep(60 * 1000);
}

if (!Sync.Engine.Instance.SyncingNow) {
Forms.Main.Instance.Sync_Click(sender, null);
} else {
Expand All @@ -59,6 +64,8 @@ private void ogcsTimer_Tick(object sender, EventArgs e) {
}
}

/// <summary>Get the sync interval as configured in Settings.</summary>
/// <returns>Minutes between syncs</returns>
private int getResyncInterval() {
var profile = (this.owningProfile as SettingsStore.Calendar);
int min = profile.SyncInterval;
Expand Down Expand Up @@ -114,7 +121,7 @@ public void CalculateInterval() {
}
Activate(true);
}

public void Activate(Boolean activate) {
if (Forms.Main.Instance.InvokeRequired) {
log.Error("Attempted to " + (activate ? "" : "de") + "activate " + this.Tag + " from non-GUI thread will not work.");
Expand All @@ -125,14 +132,14 @@ public void Activate(Boolean activate) {
else if (!activate && this.Enabled) this.Stop();
}

public Boolean Running() {
return this.Enabled;
public Boolean IsRunning {
get { return this.Enabled; }
}

public String Status() {
var profile = (owningProfile as SettingsStore.Calendar);
if (this.Running()) return NextSyncDateText;
else if (profile.OgcsPushTimer != null && profile.OgcsPushTimer.Running()) return "Push Sync Active";
if (this.IsRunning) return NextSyncDateText;
else if (profile.OgcsPushTimer != null && profile.OgcsPushTimer.IsRunning) return "Push Sync Active";
else return "Inactive";
}
}
Expand Down Expand Up @@ -168,8 +175,9 @@ public void ResetLastRun() {

private void ogcsPushTimer_Tick(object sender, EventArgs e) {
if (Forms.ErrorReporting.Instance.Visible) return;
log.UltraFine("Push sync triggered.");
if ((DateTime.Now - TimezoneDB.LastSystemResume).TotalSeconds < 60) return;

log.UltraFine("Push sync triggered.");
try {
SettingsStore.Calendar profile = this.owningProfile as SettingsStore.Calendar;

Expand All @@ -184,8 +192,8 @@ private void ogcsPushTimer_Tick(object sender, EventArgs e) {

if (items.Count < this.lastRunItemCount || items.FindAll(x => x.LastModificationTime > this.lastRunTime).Count > 0) {
log.Debug("Changes found for Push sync.");
Forms.Main.Instance.Sync_Click(sender, null);
} else {
Forms.Main.Instance.Sync_Click(sender, null);
} else {
log.Fine("No changes found.");
}
failures = 0;
Expand Down Expand Up @@ -222,8 +230,8 @@ public void Activate(Boolean activate) {
profile.OgcsTimer.SetNextSync();
}
}
public Boolean Running() {
return this.Enabled;
public Boolean IsRunning {
get { return this.Enabled; }
}
}
}
3 changes: 3 additions & 0 deletions src/OutlookGoogleCalendarSync/TimezoneDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public TzdbDateTimeZoneSource Source {
public String Version {
get { return source.TzdbVersion; }
}

public static DateTime LastSystemResume = DateTime.Now.AddDays(-1);

private TimezoneDB() {
try {
Expand All @@ -47,6 +49,7 @@ private TimezoneDB() {
private static void SystemEvents_TimeChanged(object sender, EventArgs e) {
log.Info("Detected system timezone change.");
System.Globalization.CultureInfo.CurrentCulture.ClearCachedData();
LastSystemResume = DateTime.Now;
}

public void CheckForUpdate() {
Expand Down
2 changes: 2 additions & 0 deletions src/OutlookGoogleCalendarSync/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ private async Task<Boolean> githubCheck() {
log.Info("User chose not to upgrade right now.");
Telemetry.Send(Analytics.Category.squirrel, Analytics.Action.upgrade, squirrelAnalyticsLabel + ";later");
squirrelGaEv.AddParameter(GA4.Squirrel.action_taken, "Deferred");
squirrelGaEv.Send();

} else if (dr == DialogResult.Ignore) {
Telemetry.Send(Analytics.Category.squirrel, Analytics.Action.upgrade, squirrelAnalyticsLabel + ";skipped");
squirrelGaEv.AddParameter(GA4.Squirrel.action_taken, "Skipped");
squirrelGaEv.Send();

} else if (dr == DialogResult.Yes) {
try {
Expand Down

0 comments on commit 80e84d6

Please sign in to comment.