mac, linux: Show a notification after trying to reopen the app twice

This commit is contained in:
Hylke Bons 2013-12-01 13:29:35 +00:00
parent 99ddc31652
commit 0ae1c77472
4 changed files with 35 additions and 2 deletions

View file

@ -54,11 +54,18 @@ namespace SparkleShare {
private void ApplicationActivatedDelegate (object sender, EventArgs args) private void ApplicationActivatedDelegate (object sender, EventArgs args)
{ {
if (this.application.Windows.Length > 0) { if (this.application.Windows.Length > 0) {
bool has_visible_windows = false;
foreach (Window window in this.application.Windows) { foreach (Window window in this.application.Windows) {
if (window.Visible) if (window.Visible) {
window.Present (); window.Present ();
has_visible_windows = true;
}
} }
if (!has_visible_windows)
Program.Controller.HandleReopen ();
} else { } else {
Setup = new SparkleSetup (); Setup = new SparkleSetup ();
EventLog = new SparkleEventLog (); EventLog = new SparkleEventLog ();

View file

@ -58,7 +58,7 @@ namespace SparkleShare {
public void Run () public void Run ()
{ {
NSApplication.Main (new string [0]); NSApplication.Main (Program.Arguments);
} }
@ -76,5 +76,14 @@ namespace SparkleShare {
{ {
Program.Controller.Quit (); Program.Controller.Quit ();
} }
public override bool ApplicationShouldHandleReopen (NSApplication sender, bool has_visible_windows)
{
if (!has_visible_windows)
Program.Controller.HandleReopen ();
return true;
}
} }
} }

View file

@ -27,6 +27,7 @@ namespace SparkleShare {
public static SparkleController Controller; public static SparkleController Controller;
public static SparkleUI UI; public static SparkleUI UI;
public static string [] Arguments;
private static Mutex program_mutex = new Mutex (false, "SparkleShare"); private static Mutex program_mutex = new Mutex (false, "SparkleShare");
@ -36,6 +37,8 @@ namespace SparkleShare {
#endif #endif
public static void Main (string [] args) public static void Main (string [] args)
{ {
Arguments = args;
if (args.Length != 0 && !args [0].Equals ("help") && if (args.Length != 0 && !args [0].Equals ("help") &&
SparkleBackend.Platform != PlatformID.MacOSX && SparkleBackend.Platform != PlatformID.MacOSX &&
SparkleBackend.Platform != PlatformID.Win32NT) { SparkleBackend.Platform != PlatformID.Win32NT) {

View file

@ -232,6 +232,20 @@ namespace SparkleShare {
} }
private int reopen_attempt_counts = 0;
public void HandleReopen ()
{
reopen_attempt_counts++;
if (reopen_attempt_counts > 1) {
AlertNotificationRaised ("Hello!", "SparkleShare sits right here, as a status icon.");
reopen_attempt_counts = 0;
}
}
public void UIHasLoaded () public void UIHasLoaded ()
{ {
if (this.lost_folders_path) { if (this.lost_folders_path) {