From 42693ea2387a9988a775ee0d8d3d2e61a305d084 Mon Sep 17 00:00:00 2001 From: Tomas Camin Date: Wed, 12 Aug 2020 14:38:17 +0200 Subject: [PATCH] Add mouse move --- README.md | 4 ++++ .../SBTUITunnelHostServer/AppDelegate.swift | 9 +++++++++ SBTUITunnelHostServer/SBTUITunnelHostServer/Info.plist | 2 +- .../SBTUITunnelHostServer/MouseMagic.swift | 6 ++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b75683..cb57b35 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ Add files in the *SBTUITestTunnelHost* to the UI test target. Launch the Mac App (either by compiling the `SBTUITunnelHostServer/SBTUITunnelHostServer.xcworkspace` or launching the executable in `SBTUITunnelHostServer/Binary/SBTUITestTunnelServer.zip`) which will fire a server on your local machine on port 8667. The current status of the server will be shown in the macOS menubar. +#### Mouse actions - Catalina + +To allow SBTUITestTunnelServer to interact with machine mouse you'll need to explicitly grant Accessibility permissions under 'Securtity & Privacy' > 'Privacy' in System preferences. If the SBTUITestTunnelServer is already listed but mouse interaction do not work try removing the entry and launching the app again. + #### Executable under Pods folder Usually you should place the executable under _/Applications_ so that the same instance can be shared across multiple projects, however there are scenarios where you might prefer to place the server's executable under your project _Pods_ folder. This can be achieved adding the following post_install step in your Podfile: diff --git a/SBTUITunnelHostServer/SBTUITunnelHostServer/AppDelegate.swift b/SBTUITunnelHostServer/SBTUITunnelHostServer/AppDelegate.swift index da6fb38..7ace0a4 100644 --- a/SBTUITunnelHostServer/SBTUITunnelHostServer/AppDelegate.swift +++ b/SBTUITunnelHostServer/SBTUITunnelHostServer/AppDelegate.swift @@ -25,6 +25,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, GCDWebServerDelegate { let serverPort: UInt = 8_667 var server: GCDWebServer? + var mouseInteractionEnabled: Bool = false + let statusBar = NSStatusBar.system var statusBarItem = NSStatusItem() @@ -37,6 +39,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, GCDWebServerDelegate { }() func applicationDidFinishLaunching(_ aNotification: Notification) { + mouseInteractionEnabled = ProcessInfo().arguments.contains("--enable-mouse-interaction") + if mouseInteractionEnabled { + let mouse = Mouse() + let point = CGPoint(x: 0, y: 0) + mouse.move(to: point) + } + statusBarItem = statusBar.statusItem(withLength: NSStatusItem.variableLength) restoreDefaultStatusBarImage() diff --git a/SBTUITunnelHostServer/SBTUITunnelHostServer/Info.plist b/SBTUITunnelHostServer/SBTUITunnelHostServer/Info.plist index 5e7ed40..0f11609 100644 --- a/SBTUITunnelHostServer/SBTUITunnelHostServer/Info.plist +++ b/SBTUITunnelHostServer/SBTUITunnelHostServer/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.20 + 1.30 CFBundleSignature ???? CFBundleVersion diff --git a/SBTUITunnelHostServer/SBTUITunnelHostServer/MouseMagic.swift b/SBTUITunnelHostServer/SBTUITunnelHostServer/MouseMagic.swift index 4d3a222..4c82c6b 100644 --- a/SBTUITunnelHostServer/SBTUITunnelHostServer/MouseMagic.swift +++ b/SBTUITunnelHostServer/SBTUITunnelHostServer/MouseMagic.swift @@ -57,4 +57,10 @@ class Mouse { mouseUp?.post(tap: .cghidEventTap) Thread.sleep(forTimeInterval: 1e-3 * 150.0) } + + func move(to point: CGPoint) { + let mouseMove = CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left) + + mouseMove?.post(tap: .cghidEventTap) + } }