From c57430ed5cac3076f54de1a9cef5d657f78a3e13 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 8 Sep 2010 23:30:24 +0100 Subject: [PATCH] [statusicon] do the statusicon syncing/idle switching smarter, less bugs --- SparkleLib/SparkleRepo.cs | 18 ++++++++++++ SparkleShare/SparkleBubble.cs | 2 +- SparkleShare/SparkleIntro.cs | 6 ++-- SparkleShare/SparkleStatusIcon.cs | 29 +++++++------------ SparkleShare/SparkleUI.cs | 46 +++++++++++++------------------ 5 files changed, 51 insertions(+), 50 deletions(-) diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index f5dffc8e..cbd95993 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -43,6 +43,8 @@ namespace SparkleLib { public string CurrentHash; public string UserEmail; public string UserName; + public bool IsSyncing; + public bool IsBuffering; public delegate void AddedEventHandler (object o, SparkleEventArgs args); public delegate void CommitedEventHandler (object o, SparkleEventArgs args); @@ -94,6 +96,8 @@ namespace SparkleLib { Domain = GetDomain (RemoteOriginUrl); Description = GetDescription (); HasUnsyncedChanges = false; + IsSyncing = false; + IsBuffering = false; if (CurrentHash == null) CreateInitialCommit (); @@ -202,6 +206,8 @@ namespace SparkleLib { SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes have settled, adding files..."); + IsBuffering = false; + HasChanged = false; AddCommitAndPush (); @@ -222,6 +228,8 @@ namespace SparkleLib { if (!ShouldIgnore (fse_args.FullPath)) { + IsBuffering = true; + // Only fire the event if the timer has been stopped. // This prevents multiple events from being raised whilst "buffering". if (!HasChanged) { @@ -338,6 +346,8 @@ namespace SparkleLib { public void Fetch () { + IsSyncing = true; + RemoteTimer.Stop (); Process process = new Process () { @@ -360,6 +370,7 @@ namespace SparkleLib { process.StartInfo.Arguments = "fetch -v origin master"; process.Start (); + process.WaitForExit (); process.Exited += delegate { @@ -376,6 +387,8 @@ namespace SparkleLib { CurrentHash = GetCurrentHash (); + IsSyncing = false; + }; } @@ -482,6 +495,8 @@ namespace SparkleLib { public void Push () { + IsSyncing = true; + SparkleEventArgs args = new SparkleEventArgs ("PushingStarted"); if (PushingStarted != null) @@ -490,6 +505,7 @@ namespace SparkleLib { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes..."); Process.StartInfo.Arguments = "push origin master"; + Process.Start (); Process.WaitForExit (); @@ -519,6 +535,8 @@ namespace SparkleLib { } + IsSyncing = false; + }; } diff --git a/SparkleShare/SparkleBubble.cs b/SparkleShare/SparkleBubble.cs index 4eb0909b..ea37b681 100644 --- a/SparkleShare/SparkleBubble.cs +++ b/SparkleShare/SparkleBubble.cs @@ -29,7 +29,7 @@ namespace SparkleShare { Timeout = 4500; Urgency = Urgency.Low; - AttachToStatusIcon (SparkleUI.NotificationIcon); + AttachToStatusIcon (SparkleUI.StatusIcon); } diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index 3ba702a7..69027537 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -567,10 +567,10 @@ namespace SparkleShare { finish_button.Clicked += delegate (object o, EventArgs args) { - if (SparkleUI.NotificationIcon == null) - SparkleUI.NotificationIcon = new SparkleStatusIcon (); + if (SparkleUI.StatusIcon == null) + SparkleUI.StatusIcon = new SparkleStatusIcon (); else - SparkleUI.NotificationIcon.CreateMenu (); + SparkleUI.StatusIcon.CreateMenu (); Destroy (); diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs index e5f02eea..dfb76c30 100644 --- a/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/SparkleStatusIcon.cs @@ -30,8 +30,6 @@ namespace SparkleShare { private List OpenLogs; - public int SyncingReposCount; - private Menu Menu; private MenuItem StatusMenuItem; private string StateText; @@ -60,8 +58,6 @@ namespace SparkleShare { AnimationFrames = CreateAnimationFrames (); Animation = CreateAnimation (); - SyncingReposCount = 0; - StateText = ""; StatusMenuItem = new MenuItem (); @@ -372,36 +368,31 @@ namespace SparkleShare { UpdateFolderSize (); - // Make sure the number of syncing repositories doesn't - // go below zero. This can happen in some circumstances. - if (SyncingReposCount < 0) - SyncingReposCount = 0; - - // Make sure the number of syncing repositories doesn't - // go above the number of existing repositories. This can - // happen in some circumstances. - if (SyncingReposCount > SparkleUI.Repositories.Count) - SyncingReposCount = SparkleUI.Repositories.Count; - if (error) { SetErrorState (); } else { - if (SyncingReposCount > 0) + foreach (SparkleRepo repo in SparkleUI.Repositories) + + if (repo.IsSyncing || repo.IsBuffering) { + SetSyncingState (); - else + break; + + } else { + SetIdleState (); + } + } // Use the new status text (StatusMenuItem.Children [0] as Label).Text = StateText; Menu.ShowAll (); - SparkleHelpers.DebugInfo ("Status", "Number of repos syncing: " + SyncingReposCount); - } diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index 1e4d9806..4146bb82 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -31,7 +31,7 @@ namespace SparkleShare { public class SparkleUI { public static List Repositories; - public static SparkleStatusIcon NotificationIcon; + public static SparkleStatusIcon StatusIcon; // Short alias for the translations @@ -126,7 +126,7 @@ namespace SparkleShare { } // Create the statusicon - NotificationIcon = new SparkleStatusIcon (); + StatusIcon = new SparkleStatusIcon (); } @@ -344,12 +344,11 @@ namespace SparkleShare { } - // Updates the statusicon to the syncing state - public void UpdateStatusIconToSyncing (object o, EventArgs args) + // Tells the statusicon to update its state + public void UpdateStatusIcon (object o, EventArgs args) { - NotificationIcon.SyncingReposCount++; - NotificationIcon.ShowState (); + StatusIcon.ShowState (); } @@ -358,18 +357,7 @@ namespace SparkleShare { public void UpdateStatusIconToError (object o, EventArgs args) { - NotificationIcon.SyncingReposCount--; - NotificationIcon.ShowState (true); - - } - - - // Updates the syncing icon to the idle state - public void UpdateStatusIconToIdle (object o, EventArgs args) - { - - NotificationIcon.SyncingReposCount--; - NotificationIcon.ShowState (); + StatusIcon.ShowState (true); } @@ -395,23 +383,27 @@ namespace SparkleShare { }; repo.FetchingStarted += delegate { - Application.Invoke (UpdateStatusIconToSyncing); + Application.Invoke (UpdateStatusIcon); }; repo.FetchingFinished += delegate { - Application.Invoke (UpdateStatusIconToIdle); + Application.Invoke (UpdateStatusIcon); }; repo.ChangesDetected += delegate { - Application.Invoke (UpdateStatusIconToSyncing); + Application.Invoke (UpdateStatusIcon); + }; + + repo.PushingStarted += delegate { + Application.Invoke (UpdateStatusIcon); }; repo.PushingFinished += delegate { - Application.Invoke (UpdateStatusIconToIdle); + Application.Invoke (UpdateStatusIcon); }; repo.CommitEndedUpEmpty += delegate { - Application.Invoke (UpdateStatusIconToIdle); + Application.Invoke (UpdateStatusIcon); }; repo.PushingFailed += delegate { @@ -424,8 +416,8 @@ namespace SparkleShare { Repositories.Add (repo); - if (NotificationIcon != null) - Application.Invoke (delegate { NotificationIcon.CreateMenu (); }); + if (StatusIcon != null) + Application.Invoke (delegate { StatusIcon.CreateMenu (); }); } @@ -449,8 +441,8 @@ namespace SparkleShare { } - if (NotificationIcon != null) - Application.Invoke (delegate { NotificationIcon.CreateMenu (); }); + if (StatusIcon != null) + Application.Invoke (delegate { StatusIcon.CreateMenu (); }); }