diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2019-11-11 15:15:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-11 15:15:29 +0300 |
commit | d20d9e94f903903c0b492240f2c7c2d2d57ff4e0 (patch) | |
tree | 4ca75a857b2d379e6f355db5a0c459170005e478 | |
parent | 9a698e3b21ccff481668ef0656873b08099e365b (diff) | |
parent | c16366bb19267eec033278dca48dc65699dfe963 (diff) |
Merge pull request #1004 from mono/pr-abock-appdelegate
MacEngine: support custom NSApplicationDelegate, improve init
-rw-r--r-- | Xwt.XamMac/Xwt.Mac/MacEngine.cs | 4 | ||||
-rw-r--r-- | Xwt.XamMac/Xwt.Mac/NSApplicationInitializer.cs | 17 |
2 files changed, 11 insertions, 10 deletions
diff --git a/Xwt.XamMac/Xwt.Mac/MacEngine.cs b/Xwt.XamMac/Xwt.Mac/MacEngine.cs index bc6c19ca..547e2507 100644 --- a/Xwt.XamMac/Xwt.Mac/MacEngine.cs +++ b/Xwt.XamMac/Xwt.Mac/MacEngine.cs @@ -36,6 +36,8 @@ namespace Xwt.Mac { public class MacEngine: Xwt.Backends.ToolkitEngineBackend { + public static Func<bool, AppDelegate> AppDelegateFactory; + static AppDelegate appDelegate; static NSAutoreleasePool pool; @@ -51,7 +53,7 @@ namespace Xwt.Mac if (pool != null) pool.Dispose (); pool = new NSAutoreleasePool (); - appDelegate = new AppDelegate (IsGuest); + appDelegate = AppDelegateFactory?.Invoke(IsGuest) ?? new AppDelegate (IsGuest); NSApplication.SharedApplication.Delegate = appDelegate; // If NSPrincipalClass is not set, set it now. This allows running diff --git a/Xwt.XamMac/Xwt.Mac/NSApplicationInitializer.cs b/Xwt.XamMac/Xwt.Mac/NSApplicationInitializer.cs index b051f47a..580573c3 100644 --- a/Xwt.XamMac/Xwt.Mac/NSApplicationInitializer.cs +++ b/Xwt.XamMac/Xwt.Mac/NSApplicationInitializer.cs @@ -24,23 +24,22 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; + using AppKit; namespace Xwt.Mac { static class NSApplicationInitializer { + [ThreadStatic] + static bool initialized; + public static void Initialize () { - var ds = System.Threading.Thread.GetNamedDataSlot ("NSApplication.Initialized"); - if (System.Threading.Thread.GetData (ds) == null) { - System.Threading.Thread.SetData (ds, true); - - // IgnoreMissingAssembliesDuringRegistration is only avalilable in Xamarin.Mac 3.4+ - // Use reflection to not break builds with older Xamarin.Mac - var ignoreMissingAssemblies = typeof (NSApplication).GetField ("IgnoreMissingAssembliesDuringRegistration", - System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); - ignoreMissingAssemblies?.SetValue (null, true); + if (!initialized) { + initialized = true; + NSApplication.IgnoreMissingAssembliesDuringRegistration = true; NSApplication.Init (); } } |