<commit_before>using System;
using Eto.Forms;
using MonoMac.AppKit;
using MonoMac.Foundation;
using Eto.Platform.Mac.Forms.Actions;
using System.ComponentModel;
using MonoMac.ObjCRuntime;

namespace Eto.Platform.Mac.Forms
{
	public class ApplicationHandler : WidgetHandler<NSApplication, Application>, IApplication
	{
		public NSApplicationDelegate AppDelegate { get; set; }
		
		public bool AddFullScreenMenuItem { get; set; }

		public bool AddPrintingMenuItems { get; set; }
		
		public static ApplicationHandler Instance {
			get { return Application.Instance.Handler as ApplicationHandler; }
		}

		public string BadgeLabel
		{
			get {
				var badgeLabel = Control.DockTile.BadgeLabel;
				return string.IsNullOrEmpty(badgeLabel) ? null : badgeLabel;
			}
			set
			{
				Control.DockTile.BadgeLabel = value ?? string.Empty;
			}
		}

		public ApplicationHandler ()
		{
			EtoBundle.Init();
			Control = NSApplication.SharedApplication;
			// until everything is marked as thread safe correctly in monomac
			// e.g. overriding NSButtonCell.DrawBezelWithFrame will throw an exception
			NSApplication.CheckForIllegalCrossThreadCalls = false;
		}
		
		static void restart_WillTerminate (object sender, EventArgs e)
		{
			// re-open after we terminate
			var args = new string[] {
				"-c",
				"open \"$1\"", 
				string.Empty,
				NSBundle.MainBundle.BundlePath
			};
			NSTask.LaunchFromPath ("/bin/sh", args);
		}

		public void Invoke (System.Action action)
		{
			var thread = NSThread.Current;
			if (thread != null && thread.IsMainThread)
				action ();
			else {
				Control.InvokeOnMainThread (delegate {
					action ();
				});
			}
		}

		public void AsyncInvoke (System.Action action)
		{
			var thread = NSThread.Current;
			if (thread != null && thread.IsMainThread)
				action ();
			else {
				Control.BeginInvokeOnMainThread (delegate {
					action ();
				});
			}
		}
		
		public void Restart ()
		{
			NSApplication.SharedApplication.WillTerminate += restart_WillTerminate;
			NSApplication.SharedApplication.Terminate (AppDelegate);

			// only get here if cancelled, remove event to restart
			NSApplication.SharedApplication.WillTerminate -= restart_WillTerminate;
		}

		public void RunIteration ()
		{
			NSApplication.SharedApplication.NextEvent (NSEventMask.AnyEvent, NSDate.DistantFuture, NSRunLoop.NSDefaultRunLoopMode, true);
		}
		
		
		
		public void Run (string[] args)
		{
			if (Control.Delegate == null)
				Control.Delegate = this.AppDelegate ?? new AppDelegate ();
			NSApplication.Main (args);
		}
		
		public void Initialize (NSApplicationDelegate appdelegate)
		{
			this.AppDelegate = appdelegate;
			Widget.OnInitialized (EventArgs.Empty);	
		}

		public void Quit ()
		{
			NSApplication.SharedApplication.Terminate (AppDelegate);
		}
		
		public void Open (string url)
		{
			NSWorkspace.SharedWorkspace.OpenUrl (new NSUrl (url));
		}
		<commit_msg>Mac: Only init the bundle when calling Application.Run()<commit_after>using System;
using Eto.Forms;
using MonoMac.AppKit;
using MonoMac.Foundation;
using Eto.Platform.Mac.Forms.Actions;
using System.ComponentModel;
using MonoMac.ObjCRuntime;

namespace Eto.Platform.Mac.Forms
{
	public class ApplicationHandler : WidgetHandler<NSApplication, Application>, IApplication
	{
		public NSApplicationDelegate AppDelegate { get; set; }
		
		public bool AddFullScreenMenuItem { get; set; }

		public bool AddPrintingMenuItems { get; set; }
		
		public static ApplicationHandler Instance {
			get { return Application.Instance.Handler as ApplicationHandler; }
		}

		public string BadgeLabel
		{
			get {
				var badgeLabel = Control.DockTile.BadgeLabel;
				return string.IsNullOrEmpty(badgeLabel) ? null : badgeLabel;
			}
			set
			{
				Control.DockTile.BadgeLabel = value ?? string.Empty;
			}
		}

		public ApplicationHandler ()
		{
			Control = NSApplication.SharedApplication;
			// until everything is marked as thread safe correctly in monomac
			// e.g. overriding NSButtonCell.DrawBezelWithFrame will throw an exception
			NSApplication.CheckForIllegalCrossThreadCalls = false;
		}
		
		static void restart_WillTerminate (object sender, EventArgs e)
		{
			// re-open after we terminate
			var args = new string[] {
				"-c",
				"open \"$1\"", 
				string.Empty,
				NSBundle.MainBundle.BundlePath
			};
			NSTask.LaunchFromPath ("/bin/sh", args);
		}

		public void Invoke (System.Action action)
		{
			var thread = NSThread.Current;
			if (thread != null && thread.IsMainThread)
				action ();
			else {
				Control.InvokeOnMainThread (delegate {
					action ();
				});
			}
		}

		public void AsyncInvoke (System.Action action)
		{
			var thread = NSThread.Current;
			if (thread != null && thread.IsMainThread)
				action ();
			else {
				Control.BeginInvokeOnMainThread (delegate {
					action ();
				});
			}
		}
		
		public void Restart ()
		{
			NSApplication.SharedApplication.WillTerminate += restart_WillTerminate;
			NSApplication.SharedApplication.Terminate (AppDelegate);

			// only get here if cancelled, remove event to restart
			NSApplication.SharedApplication.WillTerminate -= restart_WillTerminate;
		}

		public void RunIteration ()
		{
			NSApplication.SharedApplication.NextEvent (NSEventMask.AnyEvent, NSDate.DistantFuture, NSRunLoop.NSDefaultRunLoopMode, true);
		}
		
		
		
		public void Run (string[] args)
		{
			EtoBundle.Init();

			if (Control.Delegate == null)
				Control.Delegate = this.AppDelegate ?? new AppDelegate ();
			NSApplication.Main (args);
		}
		
		public void Initialize (NSApplicationDelegate appdelegate)
		{
			this.AppDelegate = appdelegate;
			Widget.OnInitialized (EventArgs.Empty);	
		}

		public void Quit ()
		{
			NSApplication.SharedApplication.Terminate (AppDelegate);
		}
		
		public void Open (string url)
		{
			NSWorkspace.SharedWorkspace.OpenUrl (new NSUrl (url));
		}
		
{'fraction_non_alphanumeric': 0.09685147159479808, 'fraction_numerical': 0.00034223134839151266, 'mean_word_length': 3.4754977029096477, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3429060', 'n_tokens_mistral': 2101, 'n_tokens_neox': 1716, 'n_words': 417}