Skip to content

Commit 5f1d7e1

Browse files
committed
Update SwiftAutoGUI and adopt Action API
1 parent 57b8539 commit 5f1d7e1

6 files changed

Lines changed: 48 additions & 56 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can operate the mouse according to your hand movements as follows.
2929
[SwiftAutoGUI](https://github.com/NakaokaRei/SwiftAutoGUI) is used for mouse operation.
3030

3131
> **Warning**
32-
> This app only works on Apple Silicon.
32+
> This app requires macOS 26 or later and Apple Silicon.
3333
3434
<img src="img/demo.gif" width="700">
3535

@@ -49,4 +49,4 @@ You can operate the mouse according to your hand movements as follows.
4949
<!-- CREATED_BY_LEADYOU_README_GENERATOR -->
5050

5151
# License
52-
MIT license. See the [LICENSE file](/LICENSE) for details.
52+
MIT license. See the [LICENSE file](/LICENSE) for details.

TrackpadAir.xcodeproj/project.pbxproj

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@
383383
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
384384
GCC_WARN_UNUSED_FUNCTION = YES;
385385
GCC_WARN_UNUSED_VARIABLE = YES;
386-
MACOSX_DEPLOYMENT_TARGET = 12.6;
386+
MACOSX_DEPLOYMENT_TARGET = 26.0;
387387
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
388388
MTL_FAST_MATH = YES;
389389
ONLY_ACTIVE_ARCH = YES;
@@ -440,7 +440,7 @@
440440
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
441441
GCC_WARN_UNUSED_FUNCTION = YES;
442442
GCC_WARN_UNUSED_VARIABLE = YES;
443-
MACOSX_DEPLOYMENT_TARGET = 12.6;
443+
MACOSX_DEPLOYMENT_TARGET = 26.0;
444444
MTL_ENABLE_DEBUG_INFO = NO;
445445
MTL_FAST_MATH = YES;
446446
SDKROOT = macosx;
@@ -476,13 +476,13 @@
476476
"$(inherited)",
477477
"@executable_path/../Frameworks",
478478
);
479-
MACOSX_DEPLOYMENT_TARGET = 13.0;
479+
MACOSX_DEPLOYMENT_TARGET = 26.0;
480480
MARKETING_VERSION = 0.1.3;
481481
PRODUCT_BUNDLE_IDENTIFIER = com.TrackpadAir;
482482
PRODUCT_NAME = "$(TARGET_NAME)";
483483
PROVISIONING_PROFILE_SPECIFIER = "";
484484
SWIFT_EMIT_LOC_STRINGS = YES;
485-
SWIFT_VERSION = 5.0;
485+
SWIFT_VERSION = 6.0;
486486
};
487487
name = Debug;
488488
};
@@ -510,13 +510,13 @@
510510
"$(inherited)",
511511
"@executable_path/../Frameworks",
512512
);
513-
MACOSX_DEPLOYMENT_TARGET = 13.0;
513+
MACOSX_DEPLOYMENT_TARGET = 26.0;
514514
MARKETING_VERSION = 0.1.3;
515515
PRODUCT_BUNDLE_IDENTIFIER = com.TrackpadAir;
516516
PRODUCT_NAME = "$(TARGET_NAME)";
517517
PROVISIONING_PROFILE_SPECIFIER = "";
518518
SWIFT_EMIT_LOC_STRINGS = YES;
519-
SWIFT_VERSION = 5.0;
519+
SWIFT_VERSION = 6.0;
520520
};
521521
name = Release;
522522
};
@@ -533,15 +533,15 @@
533533
GENERATE_INFOPLIST_FILE = YES;
534534
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
535535
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
536-
MACOSX_DEPLOYMENT_TARGET = 14.5;
536+
MACOSX_DEPLOYMENT_TARGET = 26.0;
537537
MARKETING_VERSION = 1.0;
538538
PRODUCT_BUNDLE_IDENTIFIER = com.me.n.rei.TrackpadAirTests;
539539
PRODUCT_NAME = "$(TARGET_NAME)";
540540
SDKROOT = auto;
541541
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
542542
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
543543
SWIFT_EMIT_LOC_STRINGS = NO;
544-
SWIFT_VERSION = 5.0;
544+
SWIFT_VERSION = 6.0;
545545
TARGETED_DEVICE_FAMILY = "1,2,7";
546546
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TrackpadAir.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/TrackpadAir";
547547
XROS_DEPLOYMENT_TARGET = 2.0;
@@ -561,14 +561,14 @@
561561
GENERATE_INFOPLIST_FILE = YES;
562562
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
563563
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
564-
MACOSX_DEPLOYMENT_TARGET = 14.5;
564+
MACOSX_DEPLOYMENT_TARGET = 26.0;
565565
MARKETING_VERSION = 1.0;
566566
PRODUCT_BUNDLE_IDENTIFIER = com.me.n.rei.TrackpadAirTests;
567567
PRODUCT_NAME = "$(TARGET_NAME)";
568568
SDKROOT = auto;
569569
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
570570
SWIFT_EMIT_LOC_STRINGS = NO;
571-
SWIFT_VERSION = 5.0;
571+
SWIFT_VERSION = 6.0;
572572
TARGETED_DEVICE_FAMILY = "1,2,7";
573573
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TrackpadAir.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/TrackpadAir";
574574
XROS_DEPLOYMENT_TARGET = 2.0;
@@ -612,8 +612,8 @@
612612
isa = XCRemoteSwiftPackageReference;
613613
repositoryURL = "https://github.com/NakaokaRei/SwiftAutoGUI";
614614
requirement = {
615-
branch = master;
616-
kind = branch;
615+
kind = upToNextMajorVersion;
616+
minimumVersion = 0.22.0;
617617
};
618618
};
619619
/* End XCRemoteSwiftPackageReference section */

TrackpadAir.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TrackpadAir/Manager/HandPoseManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Foundation
99
import Vision
1010

11+
@MainActor
1112
class HandPoseManager {
1213
private var handPoseResquest = VNDetectHumanHandPoseRequest()
1314

@@ -61,4 +62,3 @@ class HandPoseManager {
6162
return fingerTips
6263
}
6364
}
64-

TrackpadAir/View/HandGesture/HandGestureViewModel.swift

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class HandGestureViewModel: ObservableObject {
5050
height: self.imageHeight
5151
)
5252

53-
self.operate()
53+
await self.operate()
5454
}
5555
}
5656
}
@@ -61,7 +61,7 @@ class HandGestureViewModel: ObservableObject {
6161
event = nil
6262
}
6363

64-
func operate() {
64+
func operate() async {
6565
guard let fingerTips else { return }
6666
let gesture = HandGestureProcessor.process(fingerTips: fingerTips)
6767
recognizedGesture = gesture
@@ -71,7 +71,7 @@ class HandGestureViewModel: ObservableObject {
7171
return
7272
}
7373

74-
event = actionExecutor.execute(
74+
event = await actionExecutor.execute(
7575
action: action,
7676
fingerTips: fingerTips,
7777
previousFingerTips: buffTips
@@ -85,34 +85,34 @@ protocol GestureActionExecuting {
8585
action: Event,
8686
fingerTips: FingerTips?,
8787
previousFingerTips: FingerTips?
88-
) -> Event?
88+
) async -> Event?
8989
}
9090

9191
struct GestureActionExecutor: GestureActionExecuting {
9292
func execute(
9393
action: Event,
9494
fingerTips: FingerTips?,
9595
previousFingerTips: FingerTips?
96-
) -> Event? {
96+
) async -> Event? {
9797
switch action {
9898
case .moveMouse:
9999
guard let fingerTips, let previousFingerTips else { return nil }
100100
let dx = fingerTips.index.x - previousFingerTips.index.x
101101
let dy = fingerTips.index.y - previousFingerTips.index.y
102-
SwiftAutoGUI.moveMouse(dx: dx * 5, dy: dy * 5)
102+
await Action.moveMouse(dx: dx * 5, dy: dy * 5).execute()
103103
return .moveMouse
104104
case .leftClick:
105-
SwiftAutoGUI.leftClick()
105+
await Action.leftClick.execute()
106106
return .leftClick
107107
case .scroll:
108108
guard let fingerTips, let previousFingerTips else { return nil }
109109
let dx = previousFingerTips.index.x - fingerTips.index.x
110110
let dy = previousFingerTips.index.y - fingerTips.index.y
111111

112112
if abs(dx) >= abs(dy) {
113-
SwiftAutoGUI.hscroll(clicks: Int(dx / 3))
113+
await Action.hscroll(clicks: Int(dx / 3)).execute()
114114
} else {
115-
SwiftAutoGUI.vscroll(clicks: Int(dy / 3))
115+
await Action.vscroll(clicks: Int(dy / 3)).execute()
116116
}
117117
return .scroll
118118
}
@@ -124,33 +124,7 @@ struct PreviewGestureActionExecutor: GestureActionExecuting {
124124
action: Event,
125125
fingerTips: FingerTips?,
126126
previousFingerTips: FingerTips?
127-
) -> Event? {
127+
) async -> Event? {
128128
action
129129
}
130130
}
131-
132-
extension HandGestureViewModel {
133-
func moveMouse() {
134-
event = actionExecutor.execute(
135-
action: .moveMouse,
136-
fingerTips: fingerTips,
137-
previousFingerTips: buffTips
138-
)
139-
}
140-
141-
func scroll() {
142-
event = actionExecutor.execute(
143-
action: .scroll,
144-
fingerTips: fingerTips,
145-
previousFingerTips: buffTips
146-
)
147-
}
148-
149-
func leftClick() {
150-
event = actionExecutor.execute(
151-
action: .leftClick,
152-
fingerTips: fingerTips,
153-
previousFingerTips: buffTips
154-
)
155-
}
156-
}

TrackpadAirTests/TrackpadAirTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct TrackpadAirTests {
9393
}
9494

9595
@MainActor
96-
@Test func viewModelResolvesConfiguredAction() {
96+
@Test func viewModelResolvesConfiguredAction() async {
9797
let setting = Setting(userDefaults: makeUserDefaults())
9898
setting.setAction(.leftClick, for: .ringPinch)
9999
let viewModel = HandGestureViewModel(
@@ -108,7 +108,7 @@ struct TrackpadAirTests {
108108
little: .init(x: 60, y: 0)
109109
)
110110

111-
viewModel.operate()
111+
await viewModel.operate()
112112

113113
#expect(viewModel.recognizedGesture == .ringPinch)
114114
#expect(viewModel.event == .leftClick)
@@ -127,7 +127,7 @@ private struct FakeGestureActionExecutor: GestureActionExecuting {
127127
action: Event,
128128
fingerTips: FingerTips?,
129129
previousFingerTips: FingerTips?
130-
) -> Event? {
130+
) async -> Event? {
131131
action
132132
}
133133
}

0 commit comments

Comments
 (0)