EmbedSample.Mac.cs 791 B

1234567891011121314151617181920212223242526272829303132
  1. #if DESKTOP
  2. using Avalonia.Platform;
  3. using Avalonia.Threading;
  4. using MonoMac.Foundation;
  5. using MonoMac.WebKit;
  6. namespace NativeEmbedSample;
  7. public partial class EmbedSample
  8. {
  9. IPlatformHandle CreateOSX(IPlatformHandle parent)
  10. {
  11. // Note: We are using MonoMac for example purposes
  12. // It shouldn't be used in production apps
  13. MacHelper.EnsureInitialized();
  14. var webView = new WebView();
  15. Dispatcher.UIThread.Post(() =>
  16. {
  17. webView.MainFrame.LoadRequest(new NSUrlRequest(new NSUrl(
  18. IsSecond ? "https://bing.com": "https://google.com/")));
  19. });
  20. return new MacOSViewHandle(webView);
  21. }
  22. void DestroyOSX(IPlatformHandle handle)
  23. {
  24. ((MacOSViewHandle)handle).Dispose();
  25. }
  26. }
  27. #endif