[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 CurrentHash;
|
||||||
public string UserEmail;
|
public string UserEmail;
|
||||||
public string UserName;
|
public string UserName;
|
||||||
|
public bool IsSyncing;
|
||||||
|
public bool IsBuffering;
|
||||||
|
|
||||||
public delegate void AddedEventHandler (object o, SparkleEventArgs args);
|
public delegate void AddedEventHandler (object o, SparkleEventArgs args);
|
||||||
public delegate void CommitedEventHandler (object o, SparkleEventArgs args);
|
public delegate void CommitedEventHandler (object o, SparkleEventArgs args);
|
||||||
|
@ -94,6 +96,8 @@ namespace SparkleLib {
|
||||||
Domain = GetDomain (RemoteOriginUrl);
|
Domain = GetDomain (RemoteOriginUrl);
|
||||||
Description = GetDescription ();
|
Description = GetDescription ();
|
||||||
HasUnsyncedChanges = false;
|
HasUnsyncedChanges = false;
|
||||||
|
IsSyncing = false;
|
||||||
|
IsBuffering = false;
|
||||||
|
|
||||||
if (CurrentHash == null)
|
if (CurrentHash == null)
|
||||||
CreateInitialCommit ();
|
CreateInitialCommit ();
|
||||||
|
@ -202,6 +206,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes have settled, adding files...");
|
SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes have settled, adding files...");
|
||||||
|
|
||||||
|
IsBuffering = false;
|
||||||
|
|
||||||
HasChanged = false;
|
HasChanged = false;
|
||||||
AddCommitAndPush ();
|
AddCommitAndPush ();
|
||||||
|
|
||||||
|
@ -222,6 +228,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
if (!ShouldIgnore (fse_args.FullPath)) {
|
if (!ShouldIgnore (fse_args.FullPath)) {
|
||||||
|
|
||||||
|
IsBuffering = true;
|
||||||
|
|
||||||
// Only fire the event if the timer has been stopped.
|
// Only fire the event if the timer has been stopped.
|
||||||
// This prevents multiple events from being raised whilst "buffering".
|
// This prevents multiple events from being raised whilst "buffering".
|
||||||
if (!HasChanged) {
|
if (!HasChanged) {
|
||||||
|
@ -338,6 +346,8 @@ namespace SparkleLib {
|
||||||
public void Fetch ()
|
public void Fetch ()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
IsSyncing = true;
|
||||||
|
|
||||||
RemoteTimer.Stop ();
|
RemoteTimer.Stop ();
|
||||||
|
|
||||||
Process process = new Process () {
|
Process process = new Process () {
|
||||||
|
@ -360,6 +370,7 @@ namespace SparkleLib {
|
||||||
process.StartInfo.Arguments = "fetch -v origin master";
|
process.StartInfo.Arguments = "fetch -v origin master";
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
|
process.WaitForExit ();
|
||||||
|
|
||||||
process.Exited += delegate {
|
process.Exited += delegate {
|
||||||
|
|
||||||
|
@ -376,6 +387,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
CurrentHash = GetCurrentHash ();
|
CurrentHash = GetCurrentHash ();
|
||||||
|
|
||||||
|
IsSyncing = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -482,6 +495,8 @@ namespace SparkleLib {
|
||||||
public void Push ()
|
public void Push ()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
IsSyncing = true;
|
||||||
|
|
||||||
SparkleEventArgs args = new SparkleEventArgs ("PushingStarted");
|
SparkleEventArgs args = new SparkleEventArgs ("PushingStarted");
|
||||||
|
|
||||||
if (PushingStarted != null)
|
if (PushingStarted != null)
|
||||||
|
@ -490,6 +505,7 @@ namespace SparkleLib {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "push origin master";
|
Process.StartInfo.Arguments = "push origin master";
|
||||||
|
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
|
|
||||||
|
@ -519,6 +535,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IsSyncing = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace SparkleShare {
|
||||||
Timeout = 4500;
|
Timeout = 4500;
|
||||||
Urgency = Urgency.Low;
|
Urgency = Urgency.Low;
|
||||||
|
|
||||||
AttachToStatusIcon (SparkleUI.NotificationIcon);
|
AttachToStatusIcon (SparkleUI.StatusIcon);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -567,10 +567,10 @@ namespace SparkleShare {
|
||||||
|
|
||||||
finish_button.Clicked += delegate (object o, EventArgs args) {
|
finish_button.Clicked += delegate (object o, EventArgs args) {
|
||||||
|
|
||||||
if (SparkleUI.NotificationIcon == null)
|
if (SparkleUI.StatusIcon == null)
|
||||||
SparkleUI.NotificationIcon = new SparkleStatusIcon ();
|
SparkleUI.StatusIcon = new SparkleStatusIcon ();
|
||||||
else
|
else
|
||||||
SparkleUI.NotificationIcon.CreateMenu ();
|
SparkleUI.StatusIcon.CreateMenu ();
|
||||||
|
|
||||||
Destroy ();
|
Destroy ();
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,6 @@ namespace SparkleShare {
|
||||||
|
|
||||||
private List <SparkleLog> OpenLogs;
|
private List <SparkleLog> OpenLogs;
|
||||||
|
|
||||||
public int SyncingReposCount;
|
|
||||||
|
|
||||||
private Menu Menu;
|
private Menu Menu;
|
||||||
private MenuItem StatusMenuItem;
|
private MenuItem StatusMenuItem;
|
||||||
private string StateText;
|
private string StateText;
|
||||||
|
@ -60,8 +58,6 @@ namespace SparkleShare {
|
||||||
AnimationFrames = CreateAnimationFrames ();
|
AnimationFrames = CreateAnimationFrames ();
|
||||||
Animation = CreateAnimation ();
|
Animation = CreateAnimation ();
|
||||||
|
|
||||||
SyncingReposCount = 0;
|
|
||||||
|
|
||||||
StateText = "";
|
StateText = "";
|
||||||
StatusMenuItem = new MenuItem ();
|
StatusMenuItem = new MenuItem ();
|
||||||
|
|
||||||
|
@ -372,36 +368,31 @@ namespace SparkleShare {
|
||||||
|
|
||||||
UpdateFolderSize ();
|
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) {
|
if (error) {
|
||||||
|
|
||||||
SetErrorState ();
|
SetErrorState ();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (SyncingReposCount > 0)
|
foreach (SparkleRepo repo in SparkleUI.Repositories)
|
||||||
|
|
||||||
|
if (repo.IsSyncing || repo.IsBuffering) {
|
||||||
|
|
||||||
SetSyncingState ();
|
SetSyncingState ();
|
||||||
else
|
break;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
SetIdleState ();
|
SetIdleState ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the new status text
|
// Use the new status text
|
||||||
(StatusMenuItem.Children [0] as Label).Text = StateText;
|
(StatusMenuItem.Children [0] as Label).Text = StateText;
|
||||||
Menu.ShowAll ();
|
Menu.ShowAll ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Status", "Number of repos syncing: " + SyncingReposCount);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace SparkleShare {
|
||||||
public class SparkleUI {
|
public class SparkleUI {
|
||||||
|
|
||||||
public static List <SparkleRepo> Repositories;
|
public static List <SparkleRepo> Repositories;
|
||||||
public static SparkleStatusIcon NotificationIcon;
|
public static SparkleStatusIcon StatusIcon;
|
||||||
|
|
||||||
|
|
||||||
// Short alias for the translations
|
// Short alias for the translations
|
||||||
|
@ -126,7 +126,7 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the statusicon
|
// Create the statusicon
|
||||||
NotificationIcon = new SparkleStatusIcon ();
|
StatusIcon = new SparkleStatusIcon ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,12 +344,11 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Updates the statusicon to the syncing state
|
// Tells the statusicon to update its state
|
||||||
public void UpdateStatusIconToSyncing (object o, EventArgs args)
|
public void UpdateStatusIcon (object o, EventArgs args)
|
||||||
{
|
{
|
||||||
|
|
||||||
NotificationIcon.SyncingReposCount++;
|
StatusIcon.ShowState ();
|
||||||
NotificationIcon.ShowState ();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,18 +357,7 @@ namespace SparkleShare {
|
||||||
public void UpdateStatusIconToError (object o, EventArgs args)
|
public void UpdateStatusIconToError (object o, EventArgs args)
|
||||||
{
|
{
|
||||||
|
|
||||||
NotificationIcon.SyncingReposCount--;
|
StatusIcon.ShowState (true);
|
||||||
NotificationIcon.ShowState (true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Updates the syncing icon to the idle state
|
|
||||||
public void UpdateStatusIconToIdle (object o, EventArgs args)
|
|
||||||
{
|
|
||||||
|
|
||||||
NotificationIcon.SyncingReposCount--;
|
|
||||||
NotificationIcon.ShowState ();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,23 +383,27 @@ namespace SparkleShare {
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.FetchingStarted += delegate {
|
repo.FetchingStarted += delegate {
|
||||||
Application.Invoke (UpdateStatusIconToSyncing);
|
Application.Invoke (UpdateStatusIcon);
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.FetchingFinished += delegate {
|
repo.FetchingFinished += delegate {
|
||||||
Application.Invoke (UpdateStatusIconToIdle);
|
Application.Invoke (UpdateStatusIcon);
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.ChangesDetected += delegate {
|
repo.ChangesDetected += delegate {
|
||||||
Application.Invoke (UpdateStatusIconToSyncing);
|
Application.Invoke (UpdateStatusIcon);
|
||||||
|
};
|
||||||
|
|
||||||
|
repo.PushingStarted += delegate {
|
||||||
|
Application.Invoke (UpdateStatusIcon);
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.PushingFinished += delegate {
|
repo.PushingFinished += delegate {
|
||||||
Application.Invoke (UpdateStatusIconToIdle);
|
Application.Invoke (UpdateStatusIcon);
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.CommitEndedUpEmpty += delegate {
|
repo.CommitEndedUpEmpty += delegate {
|
||||||
Application.Invoke (UpdateStatusIconToIdle);
|
Application.Invoke (UpdateStatusIcon);
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.PushingFailed += delegate {
|
repo.PushingFailed += delegate {
|
||||||
|
@ -424,8 +416,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
Repositories.Add (repo);
|
Repositories.Add (repo);
|
||||||
|
|
||||||
if (NotificationIcon != null)
|
if (StatusIcon != null)
|
||||||
Application.Invoke (delegate { NotificationIcon.CreateMenu (); });
|
Application.Invoke (delegate { StatusIcon.CreateMenu (); });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,8 +441,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NotificationIcon != null)
|
if (StatusIcon != null)
|
||||||
Application.Invoke (delegate { NotificationIcon.CreateMenu (); });
|
Application.Invoke (delegate { StatusIcon.CreateMenu (); });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue