From 0ae1c77472376a16723d055ad8bbc6e3b77f5120 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 1 Dec 2013 13:29:35 +0000 Subject: [PATCH] mac, linux: Show a notification after trying to reopen the app twice --- SparkleShare/Linux/SparkleUI.cs | 9 ++++++++- SparkleShare/Mac/SparkleUI.cs | 11 ++++++++++- SparkleShare/Program.cs | 3 +++ SparkleShare/SparkleControllerBase.cs | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/SparkleShare/Linux/SparkleUI.cs b/SparkleShare/Linux/SparkleUI.cs index afa4442f..466364dd 100644 --- a/SparkleShare/Linux/SparkleUI.cs +++ b/SparkleShare/Linux/SparkleUI.cs @@ -54,11 +54,18 @@ namespace SparkleShare { private void ApplicationActivatedDelegate (object sender, EventArgs args) { if (this.application.Windows.Length > 0) { + bool has_visible_windows = false; + foreach (Window window in this.application.Windows) { - if (window.Visible) + if (window.Visible) { window.Present (); + has_visible_windows = true; + } } + if (!has_visible_windows) + Program.Controller.HandleReopen (); + } else { Setup = new SparkleSetup (); EventLog = new SparkleEventLog (); diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index 09cb8e00..0eb53ee3 100755 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -58,7 +58,7 @@ namespace SparkleShare { public void Run () { - NSApplication.Main (new string [0]); + NSApplication.Main (Program.Arguments); } @@ -76,5 +76,14 @@ namespace SparkleShare { { Program.Controller.Quit (); } + + + public override bool ApplicationShouldHandleReopen (NSApplication sender, bool has_visible_windows) + { + if (!has_visible_windows) + Program.Controller.HandleReopen (); + + return true; + } } } diff --git a/SparkleShare/Program.cs b/SparkleShare/Program.cs index 7087e9e8..4b98c8a8 100644 --- a/SparkleShare/Program.cs +++ b/SparkleShare/Program.cs @@ -27,6 +27,7 @@ namespace SparkleShare { public static SparkleController Controller; public static SparkleUI UI; + public static string [] Arguments; private static Mutex program_mutex = new Mutex (false, "SparkleShare"); @@ -36,6 +37,8 @@ namespace SparkleShare { #endif public static void Main (string [] args) { + Arguments = args; + if (args.Length != 0 && !args [0].Equals ("help") && SparkleBackend.Platform != PlatformID.MacOSX && SparkleBackend.Platform != PlatformID.Win32NT) { diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 363f6d0f..22ce3934 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -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 () { if (this.lost_folders_path) {