[tomboy] Restructure RemoteControl and command line execution



commit 123677b19bf7cc54cf872c1ec0da2a544e0b0df2
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date:   Sun Jan 24 21:35:19 2010 -0800

    Restructure RemoteControl and command line execution
    
    One important thing to note is that we are no longer setting
    MONO_DISABLE_SHM=1 (see bug #514434), which means that Tomboy
    may write to disk every 40 seconds unless you upgrade to Mono 2.4.3
    or later.
    
    This change was made so that we can depend on a named mutex for
    single-instance detection.

 Tomboy/RemoteControlProxy.cs |   11 ++---
 Tomboy/Tomboy.cs             |   90 ++++++++++++++++--------------------------
 Tomboy/tomboy.in             |    2 -
 3 files changed, 39 insertions(+), 64 deletions(-)
---
diff --git a/Tomboy/RemoteControlProxy.cs b/Tomboy/RemoteControlProxy.cs
index cc13c61..cbc44f4 100644
--- a/Tomboy/RemoteControlProxy.cs
+++ b/Tomboy/RemoteControlProxy.cs
@@ -1,4 +1,5 @@
 using System;
+using System.Threading;
 #if ENABLE_DBUS
 using NDesk.DBus;
 using org.freedesktop.DBus;
@@ -7,20 +8,19 @@ using System.Runtime.Remoting;
 using System.Runtime.Remoting.Activation;
 using System.Runtime.Remoting.Channels;
 using System.Runtime.Remoting.Channels.Ipc;
-using System.Threading;
 #endif
 
 namespace Tomboy
 {
 	public static class RemoteControlProxy {
+		private static Mutex mutex;
+		private static bool firstInstance;
+		private const string MutexName = "{9EF7D32D-3392-4940-8A28-1320A7BD42AB}";
 #if ENABLE_DBUS
 		private const string Path = "/org/gnome/Tomboy/RemoteControl";
 		private const string Namespace = "org.gnome.Tomboy";
 #else
-		private static Mutex mutex;
 		private static IpcChannel IpcChannel;
-		private static bool firstInstance;
-		private const string MutexName = "{9EF7D32D-3392-4940-8A28-1320A7BD42AB}";
 		private const string ServerName = "TomboyServer";
 		private const string ClientName = "TomboyClient";
 		private const string WrapperName = "TomboyRemoteControlWrapper";
@@ -99,7 +99,7 @@ namespace Tomboy
 			}
 #endif
 		}
-#if !ENABLE_DBUS
+
 		public static bool FirstInstance {
 			get {
 				// Use a mutex to provide single-instance detection
@@ -108,6 +108,5 @@ namespace Tomboy
 				return firstInstance;
 			}
 		}
-#endif
 	}
 }
diff --git a/Tomboy/Tomboy.cs b/Tomboy/Tomboy.cs
index 7d5c098..e08659e 100644
--- a/Tomboy/Tomboy.cs
+++ b/Tomboy/Tomboy.cs
@@ -59,27 +59,22 @@ namespace Tomboy
 				                                    Path.PathSeparator +
 				                                    Environment.GetEnvironmentVariable ("PATH"));
 #endif
-			// Initialize GETTEXT
 			Catalog.Init ("tomboy", Defines.GNOME_LOCALE_DIR);
 
 			TomboyCommandLine cmd_line = new TomboyCommandLine (args);
 			debugging = cmd_line.Debug;
-			Logger.LogLevel = debugging ? Level.DEBUG : Level.INFO;
-			is_panel_applet = cmd_line.UsePanelApplet;
 
-#if ENABLE_DBUS // Run command-line earlier with DBus enabled
-			if (cmd_line.NeedsExecute) {
-				// Execute args at an existing tomboy instance...
-				cmd_line.Execute ();
-				return;
-			}
-#else // Without DBus enabled, need to manually check if this is the first instance
-			if (cmd_line.NeedsExecute && !RemoteControlProxy.FirstInstance) {
+			if (!RemoteControlProxy.FirstInstance) {
+				if (!cmd_line.NeedsExecute)
+					cmd_line = new TomboyCommandLine (new string [] {"--search"});
 				// Execute args at an existing tomboy instance...
 				cmd_line.Execute ();
+				Console.WriteLine ("Tomboy is already running.  Exiting...");
 				return;
 			}
-#endif
+
+			Logger.LogLevel = debugging ? Level.DEBUG : Level.INFO;
+			is_panel_applet = cmd_line.UsePanelApplet;
 
 			// NOTE: It is important not to use the Preferences
 			//       class before this call.
@@ -89,46 +84,13 @@ namespace Tomboy
 			icon_theme = Gtk.IconTheme.Default;
 			icon_theme.AppendSearchPath (Path.Combine (Path.Combine (Defines.DATADIR, "tomboy"), "icons"));
 
-//   PluginManager.CheckPluginUnloading = cmd_line.CheckPluginUnloading;
-
 			// Create the default note manager instance.
 			string note_path = GetNotePath (cmd_line.NotePath);
 			manager = new NoteManager (note_path);
 
-			// Register the manager to handle remote requests.
-			RegisterRemoteControl (manager);
-
 			SetupGlobalActions ();
 			ActionManager am = Tomboy.ActionManager;
 
-#if !ENABLE_DBUS
-			if (cmd_line.NeedsExecute && RemoteControlProxy.FirstInstance) {
-				// Execute args on this instance
-				cmd_line.Execute ();
-			}
-#endif
-
-#if WIN32
-			if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
-				var os_version = Environment.OSVersion.Version;
-				if (( os_version.Major == 6 && os_version.Minor > 0 ) || os_version.Major > 6) {
-					JumpListManager.CreateJumpList (manager);
-
-					manager.NoteAdded += delegate (object sender, Note changed) {
-						JumpListManager.CreateJumpList (manager);
-					};
-
-					manager.NoteRenamed += delegate (Note sender, string old_title) {
-						JumpListManager.CreateJumpList (manager);
-					};
-
-					manager.NoteDeleted += delegate (object sender, Note changed) {
-						JumpListManager.CreateJumpList (manager);
-					};
-				}
-			}
-#endif
-
 			// TODO: Instead of just delaying, lazy-load
 			//       (only an issue for add-ins that need to be
 			//       available at Tomboy startup, and restoring
@@ -143,6 +105,32 @@ namespace Tomboy
 					addin.Initialize ();
 				}
 
+				// Register the manager to handle remote requests.
+				RegisterRemoteControl (manager);
+				if (cmd_line.NeedsExecute) {
+					// Execute args on this instance
+					cmd_line.Execute ();
+				}
+#if WIN32
+				if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
+					var os_version = Environment.OSVersion.Version;
+					if (( os_version.Major == 6 && os_version.Minor > 0 ) || os_version.Major > 6) {
+						JumpListManager.CreateJumpList (manager);
+
+						manager.NoteAdded += delegate (object sender, Note changed) {
+							JumpListManager.CreateJumpList (manager);
+						};
+
+						manager.NoteRenamed += delegate (Note sender, string old_title) {
+							JumpListManager.CreateJumpList (manager);
+						};
+
+						manager.NoteDeleted += delegate (object sender, Note changed) {
+							JumpListManager.CreateJumpList (manager);
+						};
+					}
+				}
+#endif
 				return false;
 			});
 
@@ -240,7 +228,7 @@ namespace Tomboy
 						remote.DisplaySearch ();
 					} catch {}
 
-					Logger.Log ("Tomboy is already running.  Exiting...");
+					Logger.Info ("Tomboy is already running.  Exiting...");
 					System.Environment.Exit (-1);
 				}
 			} catch (Exception e) {
@@ -497,7 +485,6 @@ namespace Tomboy
 		string note_path;
 		string search_text;
 		bool open_search;
-//  bool check_plugin_unloading;
 
 		public TomboyCommandLine (string [] args)
 		{
@@ -536,11 +523,6 @@ namespace Tomboy
 			}
 		}
 
-//  public bool CheckPluginUnloading
-//  {
-//   get { return check_plugin_unloading; }
-//  }
-
 		public static void PrintAbout ()
 		{
 			string about =
@@ -684,10 +666,6 @@ namespace Tomboy
 					open_search = true;
 					break;
 
-//    case "--check-plugin-unloading":
-//     check_plugin_unloading = true;
-//     break;
-
 				case "--version":
 					PrintAbout ();
 					PrintVersion();
diff --git a/Tomboy/tomboy.in b/Tomboy/tomboy.in
index b3e29ec..807dabf 100644
--- a/Tomboy/tomboy.in
+++ b/Tomboy/tomboy.in
@@ -1,7 +1,5 @@
 #!/usr/bin/env bash
 
-export MONO_DISABLE_SHM=1
-
 if [ "x$PWD" = "x srcdir@" ] ; then
     echo "*** Running uninstalled @target@ ***"
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]