[statusicon] do the statusicon syncing/idle switching smarter, less bugs
This commit is contained in:
parent
9d0b7f4451
commit
c57430ed5c
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace SparkleShare {
|
|||
Timeout = 4500;
|
||||
Urgency = Urgency.Low;
|
||||
|
||||
AttachToStatusIcon (SparkleUI.NotificationIcon);
|
||||
AttachToStatusIcon (SparkleUI.StatusIcon);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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 ();
|
||||
|
||||
|
|
|
@ -30,8 +30,6 @@ namespace SparkleShare {
|
|||
|
||||
private List <SparkleLog> 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace SparkleShare {
|
|||
public class SparkleUI {
|
||||
|
||||
public static List <SparkleRepo> 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 (); });
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue