22using System . Collections . Generic ;
33using System . Diagnostics ;
44using System . IO ;
5+ using System . Runtime . InteropServices ;
56using System . Runtime . Versioning ;
67
78using Avalonia ;
@@ -13,6 +14,18 @@ namespace SourceGit.Native
1314 [ SupportedOSPlatform ( "macOS" ) ]
1415 internal class MacOS : OS . IBackend
1516 {
17+ [ DllImport ( "/usr/lib/libobjc.dylib" , EntryPoint = "objc_getClass" ) ]
18+ public static extern IntPtr objc_getClass ( string name ) ;
19+
20+ [ DllImport ( "/usr/lib/libobjc.dylib" , EntryPoint = "sel_registerName" ) ]
21+ public static extern IntPtr sel_registerName ( string name ) ;
22+
23+ [ DllImport ( "/usr/lib/libobjc.dylib" , EntryPoint = "objc_msgSend" ) ]
24+ public static extern IntPtr objc_msgSend ( IntPtr receiver , IntPtr selector ) ;
25+
26+ [ DllImport ( "/usr/lib/libobjc.dylib" , EntryPoint = "objc_msgSend" ) ]
27+ public static extern IntPtr objc_msgSendWithArg ( IntPtr receiver , IntPtr selector , IntPtr arg ) ;
28+
1629 public void SetupApp ( AppBuilder builder )
1730 {
1831 builder . With ( new MacOSPlatformOptions ( )
@@ -44,6 +57,39 @@ public void SetupWindow(Window window)
4457 window . ExtendClientAreaToDecorationsHint = true ;
4558 }
4659
60+ public void HideSelf ( )
61+ {
62+ IntPtr nsApplicationClass = objc_getClass ( "NSApplication" ) ;
63+ IntPtr nsSharedApplicationSelector = sel_registerName ( "sharedApplication" ) ;
64+ IntPtr nsApp = objc_msgSend ( nsApplicationClass , nsSharedApplicationSelector ) ;
65+ IntPtr nsMethodSelector = sel_registerName ( "hide:" ) ;
66+ IntPtr nsDelegateSelector = sel_registerName ( "delegate" ) ;
67+ IntPtr nsDelegate = objc_msgSend ( nsApp , nsDelegateSelector ) ;
68+ objc_msgSendWithArg ( nsApp , nsMethodSelector , nsDelegate ) ;
69+ }
70+
71+ public void HideOtherApplications ( )
72+ {
73+ IntPtr nsApplicationClass = objc_getClass ( "NSApplication" ) ;
74+ IntPtr nsSharedApplicationSelector = sel_registerName ( "sharedApplication" ) ;
75+ IntPtr nsApp = objc_msgSend ( nsApplicationClass , nsSharedApplicationSelector ) ;
76+ IntPtr nsMethodSelector = sel_registerName ( "hideOtherApplications:" ) ;
77+ IntPtr nsDelegateSelector = sel_registerName ( "delegate" ) ;
78+ IntPtr nsDelegate = objc_msgSend ( nsApp , nsDelegateSelector ) ;
79+ objc_msgSendWithArg ( nsApp , nsMethodSelector , nsDelegate ) ;
80+ }
81+
82+ public void ShowAllApplications ( )
83+ {
84+ IntPtr nsApplicationClass = objc_getClass ( "NSApplication" ) ;
85+ IntPtr nsSharedApplicationSelector = sel_registerName ( "sharedApplication" ) ;
86+ IntPtr nsApp = objc_msgSend ( nsApplicationClass , nsSharedApplicationSelector ) ;
87+ IntPtr nsMethodSelector = sel_registerName ( "unhideAllApplications:" ) ;
88+ IntPtr nsDelegateSelector = sel_registerName ( "delegate" ) ;
89+ IntPtr nsDelegate = objc_msgSend ( nsApp , nsDelegateSelector ) ;
90+ objc_msgSendWithArg ( nsApp , nsMethodSelector , nsDelegate ) ;
91+ }
92+
4793 public string GetDataDir ( )
4894 {
4995 return Path . Combine (
0 commit comments