Currently Moonlight has a tool called mopen which allows you to host xap files in a desktop widget which is a nice way to package your entire application up and get it to run on the desktop. There is a tool called mpack which you can use to build the desktop xap file to use with mopen. However if you want to just have an exe and load the dll's locally then mopen is not going to cut it..yet, there are comments in the code which suggest this might be added in the future.
In order to develop full desktop applications with moonlight you will need to patch the current moonlight trunk with the patch at the end of this entry. I wont go into the details on how to get moonlight building as there are notes on how to do this in the README files on git.
If you would rather not have to build the source yourself I have a public repository for ubuntu distros which contains both the runtime only environment (no compilers or debug support) and the development environment, these debians are based on the latest mono trunk (2.11) and the latest moonlight 4 trunk.
The runtime debian is about 30MB, the development one is 97MB. Note there are allot (and I mean allot) of dependencies for moonlight so it might take a while.
To use the repository you will need to add
deb http://repo.infinitespace-online.net /to your sources.list (via the GUI or via the command line) then run
sudo apt-get update sudo apt-get install moon4-desktopfor the runtime or
sudo apt-get update sudo apt-get install moon4-desktop-devfor the development environment.
Both debians install into the /opt/ folder rather than in /usr. This is so you dont mess up any existing mono installation. However you will need to use the "source" command to update your environment do use the new mono install. Both debians place a script in /usr/local/bin so you can run the following commands
source /usr/local/bin/moon4-env
for the runtime environment and
source /usr/loca/bin/moon4-dev-env
for the development environment. In both cases your terminal should change from your usual
Now if you want to build your own version of the desktop support then you will need to get the latest moon trunk from git and apply the following patch.
diff --git a/class/System.Windows/System.Windows/Deployment.cs b/class/System.Windows/System.Windows/Deployment.cs index 9962983..ea3c94c 100644 --- a/class/System.Windows/System.Windows/Deployment.cs +++ b/class/System.Windows/System.Windows/Deployment.cs @@ -299,11 +299,28 @@ namespace System.Windows { throw new MoonException (2105, e.Message); } } + + internal bool InitializeDeployment (string localPath) { + XapDir = localPath; + TerminateAndSetCulture (null, null); + + NativeMethods.deployment_set_initialization (native, true); + try { + EntryPointType = "System.Windows.Application"; + EntryPointAssembly = typeof (Application).Assembly.GetName ().Name; + EntryAssembly = typeof (Application).Assembly; + ReadManifest (); + return LoadAssemblies (); + } + finally { + NativeMethods.deployment_set_initialization (native, false); + } + } internal bool InitializeDeployment (string culture, string uiCulture) { TerminateAndSetCulture (culture, uiCulture); - + NativeMethods.deployment_set_initialization (native, true); try { EntryPointType = "System.Windows.Application"; diff --git a/gtk/Moonlight.Gtk/MoonlightHost.cs b/gtk/Moonlight.Gtk/MoonlightHost.cs index b2a17e9..a085b13 100644 --- a/gtk/Moonlight.Gtk/MoonlightHost.cs +++ b/gtk/Moonlight.Gtk/MoonlightHost.cs @@ -70,10 +70,10 @@ namespace Moonlight.Gtk Mono.Xaml.XamlLoader.AllowMultipleSurfacesPerDomain = true; windowingSystem = NativeMethods.runtime_get_windowing_system (); - window = NativeMethods.moon_windowing_system_create_window (windowingSystem, MoonWindowType.Plugin, 0, 0, IntPtr.Zero, IntPtr.Zero); + window = NativeMethods.moon_windowing_system_create_window (windowingSystem, MoonWindowType.Plugin, 0, 0, IntPtr.Zero, IntPtr.Zero); surface = NativeMethods.surface_new (window); Raw = NativeMethods.moon_window_gtk_get_native_widget (window); - + SizeAllocated += OnSizeAllocated; } @@ -122,6 +122,17 @@ namespace Moonlight.Gtk } ///+ /// Initializes the Moonlight Plugin for a Desktop environment + /// This will allow moonlight data to be loaded from other dll's and not from within a xap file. + /// + public void LoadDesklet() + { + string path = System.IO.Path.GetDirectoryName("."); + + Deployment.Current.InitializeDeployment(path); + } + + ////// Initializes the Surface widget from the XAML contents in a string /// /// The contents of the string.@@ -146,6 +157,7 @@ namespace Moonlight.Gtk Content = (FrameworkElement)toplevel; } + ////// Initializes the GtkSilver widget from the XAML contents in a file /// diff --git a/src/bitmapimage.cpp b/src/bitmapimage.cpp index 0d1c901..f183d66 100644 --- a/src/bitmapimage.cpp +++ b/src/bitmapimage.cpp @@ -502,7 +502,7 @@ BitmapImage::CreateLoader (unsigned char *buffer) moon_error = new MoonError (MoonError::EXCEPTION, 4001, "unsupported image type"); } } else { - loader = Runtime::GetWindowingSystem ()->CreatePixbufLoader (NULL); + loader = Runtime::GetWindowingSystem ()->CreatePixbufLoader ("png"); } } diff --git a/src/deployment.cpp b/src/deployment.cpp index 14e55fa..3fe738f 100644 --- a/src/deployment.cpp +++ b/src/deployment.cpp @@ -205,6 +205,7 @@ Deployment::Initialize (const char *platform_dir, bool create_root_domain) Deployment::desktop_deployment->InitializeDesktop (root_domain); Deployment::SetCurrent (Deployment::desktop_deployment); Deployment::desktop_deployment->EnsureManagedPeer (); + Deployment::desktop_deployment->InitializeAppDomain(); Application *desktop_app = MoonUnmanagedFactory::CreateApplication (); desktop_deployment->SetCurrentApplication (desktop_app);
then build and install.
The Patch adds a new method (amongst other things) to the Moonlight.Gtk.MoonlightHost class called LoadDesklet which initializes the moonlight engine to allow local dll's to be loaded rather than expecting the binaries to be packed up in a xap file. This is more like the way WPF works under windows. Although you are still restricted to Silverlight 3/4 based Xaml support.
Next time I'll go through how to use this new stuff to develop desktop applications.
great article!
ReplyDeleteCould you describe here any pitfalls, you encountered in the development under moonlight-desktop? Is there any serious problems with the performance of rendering UI?
The rendering performance is good, we've have not seen any issues. The hard part is when you start including .xaml resources. You have to use the xml2g command line tool to generate the g.resources file which you can then include in the dll or exe. Getting this part wrong causes problems. I'll try and write that up at some point.
ReplyDelete