mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
feat(ui): Show warning if Input Monitoring is not allowed
Related to #125
This commit is contained in:
@@ -16,6 +16,9 @@ namespace BlackInput
|
||||
public:
|
||||
CMacOSInputUtils() = delete;
|
||||
|
||||
//! Check OS permission for input monitoring access
|
||||
static bool hasAccess();
|
||||
|
||||
//! Request OS permission for input monitoring access
|
||||
static bool requestAccess();
|
||||
|
||||
|
||||
@@ -8,6 +8,19 @@
|
||||
|
||||
namespace BlackInput
|
||||
{
|
||||
|
||||
bool CMacOSInputUtils::hasAccess()
|
||||
{
|
||||
if (@available(macOS 10.15, *))
|
||||
{
|
||||
return IOHIDCheckAccess(kIOHIDRequestTypeListenEvent) == IOHIDAccessType::kIOHIDAccessTypeGranted;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool CMacOSInputUtils::requestAccess()
|
||||
{
|
||||
if (@available(macOS 10.15, *))
|
||||
|
||||
@@ -29,6 +29,8 @@ target_link_libraries(swiftguistd
|
||||
)
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(swiftguistd PUBLIC input)
|
||||
|
||||
set_target_properties(swiftguistd PROPERTIES MACOSX_BUNDLE TRUE)
|
||||
set_target_properties(swiftguistd PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
|
||||
set(RESOURCE_FILES swift.icns qt.conf)
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
#include "blackmisc/threadutils.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
|
||||
#if defined(Q_OS_MACOS)
|
||||
# include "blackinput/macos/macosinpututils.h"
|
||||
#endif
|
||||
|
||||
#include "swiftguistd.h"
|
||||
#include <QAction>
|
||||
#include <QDateTime>
|
||||
@@ -475,6 +479,16 @@ void SwiftGuiStd::verifyPrerequisites()
|
||||
msgs.push_back(sGui->getIContextSimulator()->verifyPrerequisites());
|
||||
}
|
||||
|
||||
#if defined(Q_OS_MACOS)
|
||||
if (!BlackInput::CMacOSInputUtils::hasAccess())
|
||||
{
|
||||
// A log message about missing permissions is already emitted when initializing the keyboard.
|
||||
// But this happens way before initializing the GUI. Hence do the check here again to show an error message
|
||||
// to the user
|
||||
msgs.push_back(CLogMessage(this).error(u"Cannot access the keyboard. Is \"Input Monitoring\" for swift enabled?"));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (msgs.hasWarningOrErrorMessages())
|
||||
{
|
||||
if (msgs.size() > 1) { this->displayInOverlayWindow(msgs); }
|
||||
|
||||
Reference in New Issue
Block a user