|
15 | 15 | #include "io.h" |
16 | 16 | #include "snprintf.h" |
17 | 17 | #include "microsleep.h" |
| 18 | +#if defined(__APPLE__) |
| 19 | + #include <ApplicationServices/ApplicationServices.h> |
| 20 | +#endif |
18 | 21 | #if defined(USE_X11) |
19 | 22 | #include "xdisplay.h" |
20 | 23 | #endif |
@@ -1747,6 +1750,62 @@ Napi::Value saveImageWrapper(const Napi::CallbackInfo& info) |
1747 | 1750 | return Napi::Boolean::New(env, true); |
1748 | 1751 | } |
1749 | 1752 |
|
| 1753 | +Napi::Value getAccessibilityPermissionWrapper(const Napi::CallbackInfo& info) |
| 1754 | +{ |
| 1755 | + Napi::Env env = info.Env(); |
| 1756 | + |
| 1757 | +#if defined(__APPLE__) |
| 1758 | + return Napi::Boolean::New(env, AXIsProcessTrusted()); |
| 1759 | +#else |
| 1760 | + return env.Null(); |
| 1761 | +#endif |
| 1762 | +} |
| 1763 | + |
| 1764 | +Napi::Value requestAccessibilityPermissionWrapper(const Napi::CallbackInfo& info) |
| 1765 | +{ |
| 1766 | + Napi::Env env = info.Env(); |
| 1767 | + |
| 1768 | +#if defined(__APPLE__) |
| 1769 | + const void *keys[] = { kAXTrustedCheckOptionPrompt }; |
| 1770 | + const void *values[] = { kCFBooleanTrue }; |
| 1771 | + CFDictionaryRef options = CFDictionaryCreate( |
| 1772 | + kCFAllocatorDefault, |
| 1773 | + keys, |
| 1774 | + values, |
| 1775 | + 1, |
| 1776 | + &kCFTypeDictionaryKeyCallBacks, |
| 1777 | + &kCFTypeDictionaryValueCallBacks |
| 1778 | + ); |
| 1779 | + const bool trusted = AXIsProcessTrustedWithOptions(options); |
| 1780 | + CFRelease(options); |
| 1781 | + return Napi::Boolean::New(env, trusted); |
| 1782 | +#else |
| 1783 | + return env.Null(); |
| 1784 | +#endif |
| 1785 | +} |
| 1786 | + |
| 1787 | +Napi::Value getScreenCapturePermissionWrapper(const Napi::CallbackInfo& info) |
| 1788 | +{ |
| 1789 | + Napi::Env env = info.Env(); |
| 1790 | + |
| 1791 | +#if defined(__APPLE__) |
| 1792 | + return Napi::Boolean::New(env, CGPreflightScreenCaptureAccess()); |
| 1793 | +#else |
| 1794 | + return env.Null(); |
| 1795 | +#endif |
| 1796 | +} |
| 1797 | + |
| 1798 | +Napi::Value requestScreenCapturePermissionWrapper(const Napi::CallbackInfo& info) |
| 1799 | +{ |
| 1800 | + Napi::Env env = info.Env(); |
| 1801 | + |
| 1802 | +#if defined(__APPLE__) |
| 1803 | + return Napi::Boolean::New(env, CGRequestScreenCaptureAccess()); |
| 1804 | +#else |
| 1805 | + return env.Null(); |
| 1806 | +#endif |
| 1807 | +} |
| 1808 | + |
1750 | 1809 | Napi::Object InitAll(Napi::Env env, Napi::Object exports) |
1751 | 1810 | { |
1752 | 1811 | exports.Set(Napi::String::New(env, "dragMouse"), |
@@ -1842,6 +1901,18 @@ Napi::Object InitAll(Napi::Env env, Napi::Object exports) |
1842 | 1901 | exports.Set(Napi::String::New(env, "setXDisplayName"), |
1843 | 1902 | Napi::Function::New(env, setXDisplayNameWrapper)); |
1844 | 1903 |
|
| 1904 | + exports.Set(Napi::String::New(env, "getAccessibilityPermission"), |
| 1905 | + Napi::Function::New(env, getAccessibilityPermissionWrapper)); |
| 1906 | + |
| 1907 | + exports.Set(Napi::String::New(env, "requestAccessibilityPermission"), |
| 1908 | + Napi::Function::New(env, requestAccessibilityPermissionWrapper)); |
| 1909 | + |
| 1910 | + exports.Set(Napi::String::New(env, "getScreenCapturePermission"), |
| 1911 | + Napi::Function::New(env, getScreenCapturePermissionWrapper)); |
| 1912 | + |
| 1913 | + exports.Set(Napi::String::New(env, "requestScreenCapturePermission"), |
| 1914 | + Napi::Function::New(env, requestScreenCapturePermissionWrapper)); |
| 1915 | + |
1845 | 1916 | return exports; |
1846 | 1917 | } |
1847 | 1918 |
|
|
0 commit comments