Skip to content

Commit

Permalink
Add mouse move
Browse files Browse the repository at this point in the history
  • Loading branch information
tcamin committed Aug 12, 2020
1 parent 61f843a commit 42693ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions SBTUITunnelHostServer/SBTUITunnelHostServer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion SBTUITunnelHostServer/SBTUITunnelHostServer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.20</string>
<string>1.30</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
6 changes: 6 additions & 0 deletions SBTUITunnelHostServer/SBTUITunnelHostServer/MouseMagic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 42693ea

Please sign in to comment.