From 1287646dec793c5ab6e255866ce1bbb15c59ce08 Mon Sep 17 00:00:00 2001 From: Vsevolod Kukol Date: Tue, 16 Jul 2019 18:32:03 +0200 Subject: [Mac] Fix NSImageCacheException exception when getting the app icon SharedApplication.ApplicationIconImage is not meant to be used to retrieve the actual bundle icon, but only to change the default icon. Instead of SharedApplication.ApplicationIconImage get the icon directly from the bundle by default and fall-back to BrandingService if not running from an app bundle. Fixes VSTS #905844 --- .../MacPlatform/Dialogs/MacAlertDialogHandler.cs | 2 +- main/src/addins/MacPlatform/MacPlatform.cs | 18 +++++++++++++++++- .../addins/MacPlatform/MacProxyCredentialProvider.cs | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'main') diff --git a/main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs b/main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs index 05ce4d84fb..eaed84e665 100644 --- a/main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs +++ b/main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs @@ -73,7 +73,7 @@ namespace MonoDevelop.MacIntegration alert.Icon = img.ToNSImage (); } else { //for some reason the NSAlert doesn't pick up the app icon by default - alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; + alert.Icon = MacPlatformService.ApplicationIcon; } alert.MessageText = data.Message.Text; diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs index 34a34620e9..5f1d44a632 100644 --- a/main/src/addins/MacPlatform/MacPlatform.cs +++ b/main/src/addins/MacPlatform/MacPlatform.cs @@ -763,6 +763,22 @@ namespace MonoDevelop.MacIntegration [DllImport ("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] public extern static IntPtr IntPtr_objc_msgSend_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1); + private static NSImage applicationIcon; + internal static NSImage ApplicationIcon { + get { + if (applicationIcon == null) { + // use the bundle icon by default + // if run from a bundle, this will be the icon from the bundle icon file. + // if not run from a bundle, this will be the default file icon of the mono framework folder. + applicationIcon = NSWorkspace.SharedWorkspace.IconForFile (NSBundle.MainBundle.BundlePath); + } + return applicationIcon; + } + set { + applicationIcon = value; + } + } + static void SetupDockIcon () { NSObject initialBundleIconFileValue; @@ -790,7 +806,7 @@ namespace MonoDevelop.MacIntegration var imageFile = new NSString (iconFile); IntPtr p = IntPtr_objc_msgSend_IntPtr (image.Handle, Selector.GetHandle ("initByReferencingFile:"), imageFile.Handle); - NSApplication.SharedApplication.ApplicationIconImage = ObjCRuntime.Runtime.GetNSObject (p); + NSApplication.SharedApplication.ApplicationIconImage = applicationIcon = ObjCRuntime.Runtime.GetNSObject (p); } } diff --git a/main/src/addins/MacPlatform/MacProxyCredentialProvider.cs b/main/src/addins/MacPlatform/MacProxyCredentialProvider.cs index 7b21f4fbae..423d92b043 100644 --- a/main/src/addins/MacPlatform/MacProxyCredentialProvider.cs +++ b/main/src/addins/MacPlatform/MacProxyCredentialProvider.cs @@ -122,7 +122,7 @@ namespace MonoDevelop.MacIntegration var okButton = alert.AddButton (GettextCatalog.GetString ("OK")); var cancelButton = alert.AddButton (GettextCatalog.GetString ("Cancel")); - alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; + alert.Icon = MacPlatformService.ApplicationIcon; var view = new NSView (new CGRect (0, 0, 313, 91)); -- cgit v1.2.3 From b264c6e7567563b400bd084f8e1910cabdf44eed Mon Sep 17 00:00:00 2001 From: Vsevolod Kukol Date: Wed, 17 Jul 2019 09:25:59 +0200 Subject: [Mac] Improve ApplicationIcon logic and make setter private --- main/src/addins/MacPlatform/MacPlatform.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'main') diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs index 5f1d44a632..d723648c6b 100644 --- a/main/src/addins/MacPlatform/MacPlatform.cs +++ b/main/src/addins/MacPlatform/MacPlatform.cs @@ -774,8 +774,8 @@ namespace MonoDevelop.MacIntegration } return applicationIcon; } - set { - applicationIcon = value; + private set { + NSApplication.SharedApplication.ApplicationIconImage = applicationIcon = value; } } @@ -806,7 +806,7 @@ namespace MonoDevelop.MacIntegration var imageFile = new NSString (iconFile); IntPtr p = IntPtr_objc_msgSend_IntPtr (image.Handle, Selector.GetHandle ("initByReferencingFile:"), imageFile.Handle); - NSApplication.SharedApplication.ApplicationIconImage = applicationIcon = ObjCRuntime.Runtime.GetNSObject (p); + ApplicationIcon = ObjCRuntime.Runtime.GetNSObject (p); } } -- cgit v1.2.3