[tomboy/autosync: 232/241] Restructure RemoteControl and command line execution



commit 2638d1f247bdcbb32f87386c0b7a2974dad83f64
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             |   40 +++++++++++++++-------------------------
 Tomboy/tomboy.in             |    2 --
 3 files changed, 20 insertions(+), 33 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 a8bbc72..eb2e482 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) {
+			if (!RemoteControlProxy.FirstInstance) {
+				if (!cmd_line.NeedsExecute)
+					cmd_line = new TomboyCommandLine (new string [] {"--search"});
 				// Execute args at an existing tomboy instance...
+				Console.WriteLine ("Tomboy is already running.  Exiting...");
 				cmd_line.Execute ();
 				return;
 			}
-#else // Without DBus enabled, need to manually check if this is the first instance
-			if (cmd_line.NeedsExecute && !RemoteControlProxy.FirstInstance) {
-				// Execute args at an existing tomboy instance...
-				cmd_line.Execute ();
-				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,25 +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
-
 			// TODO: Instead of just delaying, lazy-load
 			//       (only an issue for add-ins that need to be
 			//       available at Tomboy startup, and restoring
@@ -122,6 +105,13 @@ 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 ();
+				}
+
 				return false;
 			});
 
@@ -219,7 +209,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) {
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]