-
-
Save chamons/05bea0e3a235e195d305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class NSWorkspacePatch | |
{ | |
static readonly IntPtr selOpenURLsWithAppBundleIdentifierOptionsAdditionalEventParamDescriptorLaunchIdentifiers_Handle = Selector.GetHandle ("openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:"); | |
public static bool OpenUrls (this NSWorkspace ws, NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor) | |
{ | |
global::MonoMac.AppKit.NSApplication.EnsureUIThread (); | |
if (urls == null) | |
throw new ArgumentNullException ("urls"); | |
if (bundleIdentifier == null) | |
throw new ArgumentNullException ("bundleIdentifier"); | |
if (descriptor == null) | |
throw new ArgumentNullException ("descriptor"); | |
var nsa_urls = NSArray.FromNSObjects (urls); | |
var nsbundleIdentifier = NSString.CreateNative (bundleIdentifier); | |
bool ret = global::MonoMac.ObjCRuntime.Messaging.bool_objc_msgSend_IntPtr_IntPtr_int_IntPtr_IntPtr | |
(ws.Handle, selOpenURLsWithAppBundleIdentifierOptionsAdditionalEventParamDescriptorLaunchIdentifiers_Handle, | |
nsa_urls.Handle, nsbundleIdentifier, (int)options, descriptor.Handle, IntPtr.Zero); | |
nsa_urls.Dispose (); | |
NSString.ReleaseNative (nsbundleIdentifier); | |
return ret; | |
} | |
} | |
public partial class AppDelegate : NSApplicationDelegate | |
{ | |
MainWindowController mainWindowController; | |
public override void DidFinishLaunching (NSNotification notification) | |
{ | |
mainWindowController = new MainWindowController (); | |
mainWindowController.Window.MakeKeyAndOrderFront (this); | |
NSWorkspace.SharedWorkspace.OpenUrls (new [] { new NSUrl ("https://www.google.com/") }, | |
"com.Apple.Safari", NSWorkspaceLaunchOptions.Default, NSAppleEventDescriptor.NullDescriptor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment