Skip to content

Commit 613bfaf

Browse files
committed
Restructure Swift package and add NativeAPI module skeleton
Add initial NativeAPI Swift module with stubs for Display, AccessibilityManager, KeyboardMonitor, and other components. Update Package.swift for new targets and platform support. Replace Example main.swift with a basic usage demo. Add initial test file for Display.
1 parent ec62848 commit 613bfaf

File tree

14 files changed

+121
-166
lines changed

14 files changed

+121
-166
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.build/
22
.swiftpm/
3-
.swift-version
3+
.vscode/
4+
.swift-version

Package.swift

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,60 @@
22
import PackageDescription
33

44
let package = Package(
5-
name: "nativeapi",
5+
name: "NativeAPI",
6+
platforms: [
7+
.macOS(.v10_15),
8+
.iOS(.v13),
9+
],
610
products: [
7-
.library(name: "nativeapi", targets: ["nativeapi"])
11+
.library(name: "NativeAPI", targets: ["NativeAPI"]),
12+
.executable(name: "Example", targets: ["Example"]),
813
],
914
targets: [
1015
.executableTarget(
1116
name: "Example",
12-
dependencies: ["nativeapi"],
17+
dependencies: ["NativeAPI"],
1318
swiftSettings: [
1419
.interoperabilityMode(.Cxx)
1520
]
1621
),
1722
.target(
18-
name: "nativeapi",
23+
name: "CNativeAPI",
1924
path: "Sources/libnativeapi",
20-
exclude: [
21-
"examples",
22-
"src/platform/linux",
23-
"src/platform/windows",
24-
],
25-
linkerSettings: [
26-
.linkedFramework("Cocoa"),
27-
.linkedFramework("Foundation"),
25+
exclude: {
26+
var excluded = ["examples"]
27+
#if os(Linux)
28+
excluded.append(contentsOf: ["src/platform/macos", "src/platform/windows"])
29+
#elseif os(macOS)
30+
excluded.append(contentsOf: ["src/platform/linux", "src/platform/windows"])
31+
#elseif os(Windows)
32+
excluded.append(contentsOf: ["src/platform/macos", "src/platform/linux"])
33+
#endif
34+
return excluded
35+
}(),
36+
linkerSettings: {
37+
#if os(macOS) || os(iOS)
38+
return [
39+
.linkedFramework("Cocoa"),
40+
.linkedFramework("Foundation"),
41+
]
42+
#else
43+
return []
44+
#endif
45+
}()
46+
),
47+
.target(
48+
name: "NativeAPI",
49+
dependencies: ["CNativeAPI"],
50+
swiftSettings: [
51+
.interoperabilityMode(.Cxx)
52+
]
53+
),
54+
.testTarget(
55+
name: "NativeAPITests",
56+
dependencies: ["NativeAPI"],
57+
swiftSettings: [
58+
.interoperabilityMode(.Cxx)
2859
]
2960
),
3061
],

Sources/Example/main.swift

Lines changed: 19 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,34 @@
11
import Foundation
2-
import nativeapi
3-
4-
// MARK: - Helper Functions
5-
6-
/// Convert display orientation to readable string
7-
func orientationToString(_ orientation: nativeapi.DisplayOrientation) -> String {
8-
switch orientation {
9-
case .portrait:
10-
return "Portrait (0 deg)"
11-
case .landscape:
12-
return "Landscape (90 deg)"
13-
case .portraitFlipped:
14-
return "Portrait Flipped (180 deg)"
15-
case .landscapeFlipped:
16-
return "Landscape Flipped (270 deg)"
17-
@unknown default:
18-
return "Unknown"
19-
}
20-
}
21-
22-
/// Truncate string if it's too long
23-
func truncateString(_ str: String, maxLength: Int) -> String {
24-
if str.count <= maxLength {
25-
return str
26-
}
27-
let truncated = String(str.prefix(maxLength - 3))
28-
return truncated + "..."
29-
}
30-
31-
/// Format a table row with proper alignment
32-
func formatTableRow(_ content: String, totalWidth: Int = 70) -> String {
33-
let truncated = truncateString(content, maxLength: totalWidth - 4)
34-
let padding = totalWidth - 4 - truncated.count
35-
return "\(truncated)\(String(repeating: " ", count: padding))"
36-
}
37-
38-
/// Create table border using ASCII characters
39-
func createTableBorder(totalWidth: Int = 70) -> String {
40-
return "+" + String(repeating: "-", count: totalWidth - 2) + "+"
41-
}
42-
43-
/// Print display information in a formatted table
44-
func printDisplayInfo(_ display: nativeapi.Display) {
45-
let tableWidth = 70
46-
47-
print(createTableBorder(totalWidth: tableWidth))
48-
print(formatTableRow("Display: \(display.name)", totalWidth: tableWidth))
49-
print(createTableBorder(totalWidth: tableWidth))
50-
print(formatTableRow("ID: \(display.id)", totalWidth: tableWidth))
51-
52-
// Position
53-
let positionStr = "Position: (\(Int(display.position.x)), \(Int(display.position.y)))"
54-
print(formatTableRow(positionStr, totalWidth: tableWidth))
55-
56-
// Size
57-
let sizeStr = "Size: \(Int(display.size.width)) x \(Int(display.size.height))"
58-
print(formatTableRow(sizeStr, totalWidth: tableWidth))
59-
60-
// Work Area
61-
let workAreaStr =
62-
"Work Area: (\(Int(display.workArea.x)), \(Int(display.workArea.y))) \(Int(display.workArea.width)) x \(Int(display.workArea.height))"
63-
print(formatTableRow(workAreaStr, totalWidth: tableWidth))
64-
65-
// Scale Factor
66-
let scaleStr = String(format: "Scale Factor: %.2f", display.scaleFactor)
67-
print(formatTableRow(scaleStr, totalWidth: tableWidth))
68-
69-
// Primary status
70-
let primaryStr = "Primary: \(display.isPrimary ? "Yes" : "No")"
71-
print(formatTableRow(primaryStr, totalWidth: tableWidth))
72-
73-
// Orientation
74-
let orientationStr = "Orientation: \(orientationToString(display.orientation))"
75-
print(formatTableRow(orientationStr, totalWidth: tableWidth))
76-
77-
// Refresh Rate
78-
let refreshStr = "Refresh Rate: \(display.refreshRate) Hz"
79-
print(formatTableRow(refreshStr, totalWidth: tableWidth))
80-
81-
// Bit Depth (if available)
82-
if display.bitDepth > 0 {
83-
let bitDepthStr = "Bit Depth: \(display.bitDepth) bits"
84-
print(formatTableRow(bitDepthStr, totalWidth: tableWidth))
85-
}
86-
87-
// Manufacturer (if available)
88-
if !display.manufacturer.isEmpty {
89-
let manufacturerStr = "Manufacturer: \(display.manufacturer)"
90-
print(formatTableRow(manufacturerStr, totalWidth: tableWidth))
91-
}
92-
93-
// Model (if available)
94-
if !display.model.isEmpty {
95-
let modelStr = "Model: \(display.model)"
96-
print(formatTableRow(modelStr, totalWidth: tableWidth))
97-
}
98-
99-
print(createTableBorder(totalWidth: tableWidth))
100-
}
2+
import NativeAPI
1013

1024
// MARK: - Main Program
1035

104-
print("=== Native API Display Manager Demo ===")
6+
print("=== NativeAPI Swift Example ===")
1057
print()
1068

107-
var displayManager = nativeapi.DisplayManager()
9+
// Test basic Display functionality
10+
print("🚀 Testing NativeAPI Display...")
10811

109-
// Get all displays
110-
let displays = displayManager.GetAll()
12+
let accessibilityManager = AccessibilityManager()
11113

112-
if displays.isEmpty {
113-
print("❌ No displays found!")
114-
exit(1)
115-
}
14+
accessibilityManager.enable()
11615

117-
print("📺 Found \(displays.count) display(s):")
118-
print()
16+
let isAccessibilityEnabled = accessibilityManager.isEnabled()
11917

120-
// Display primary display first
121-
let primaryDisplay = displayManager.GetPrimary()
122-
print("🌟 PRIMARY DISPLAY:")
123-
printDisplayInfo(primaryDisplay)
124-
print()
125-
126-
// Display secondary displays
127-
let secondaryDisplays = displays.filter { !$0.isPrimary }
128-
if !secondaryDisplays.isEmpty {
129-
print("📱 SECONDARY DISPLAYS:")
130-
for display in secondaryDisplays {
131-
printDisplayInfo(display)
132-
print()
133-
}
134-
}
18+
print("✅ Accessibility is enabled:", isAccessibilityEnabled)
13519

136-
// Display cursor position
137-
let cursorPosition = displayManager.GetCursorPosition()
138-
print("🖱️ Current Cursor Position: (\(cursorPosition.x), \(cursorPosition.y))")
20+
let display = Display()
21+
print("✅ Display instance created successfully!")
13922
print()
14023

141-
// Display summary statistics
142-
let totalWidth = displays.reduce(0) { $0 + $1.size.width }
143-
let totalHeight = displays.map { $0.size.height }.max() ?? 0
144-
let scaleFactors = displays.map { $0.scaleFactor }
145-
let minScaleFactor = scaleFactors.min() ?? 0
146-
let maxScaleFactor = scaleFactors.max() ?? 0
147-
148-
let summaryWidth = 60
149-
print("📊 SUMMARY:")
150-
print(createTableBorder(totalWidth: summaryWidth))
151-
152-
let totalDisplaysStr = "Total Displays: \(displays.count)"
153-
print(formatTableRow(totalDisplaysStr, totalWidth: summaryWidth))
154-
155-
let combinedWidthStr = "Combined Width: \(Int(totalWidth))"
156-
print(formatTableRow(combinedWidthStr, totalWidth: summaryWidth))
157-
158-
let maxHeightStr = "Max Height: \(Int(totalHeight))"
159-
print(formatTableRow(maxHeightStr, totalWidth: summaryWidth))
160-
161-
let scaleRangeStr = String(format: "Scale Range: %.1fx - %.1fx", minScaleFactor, maxScaleFactor)
162-
print(formatTableRow(scaleRangeStr, totalWidth: summaryWidth))
163-
164-
print(createTableBorder(totalWidth: summaryWidth))
24+
print("📱 NativeAPI is working correctly!")
25+
print("💡 This example demonstrates that the NativeAPI library can be imported and used.")
26+
print()
16527

28+
print("🎯 Next steps:")
29+
print(" - Implement more functionality in the NativeAPI module")
30+
print(" - Add real display management features")
31+
print(" - Test with actual display operations")
16632
print()
167-
print("✅ Display information retrieved successfully!")
33+
34+
print("✅ Example completed successfully!")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import CNativeAPI
2+
3+
public class AccessibilityManager {
4+
public init() {
5+
// Initialize the accessibility manager
6+
}
7+
8+
public func enable() {
9+
native_accessibility_manager_enable()
10+
}
11+
12+
public func isEnabled() -> Bool {
13+
return native_accessibility_manager_is_enabled()
14+
}
15+
}

Sources/NativeAPI/AppRunner.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class AppRunner {
2+
public func run() {
3+
4+
}
5+
}

Sources/NativeAPI/Display.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Display {
2+
public init() {
3+
// Initialize the display
4+
}
5+
}

Sources/NativeAPI/DisplayManager.swift

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import CNativeAPI
2+
3+
public class KeyboardMonitor {
4+
// Start the keyboard monitor
5+
public func start() {
6+
7+
}
8+
9+
// Stop the keyboard monitor
10+
public func stop() {
11+
12+
}
13+
14+
// Check if the keyboard monitor is monitoring
15+
public func isMonitoring() -> Bool {
16+
// return native_keyboard_monitor_is_monitoring()
17+
return false
18+
}
19+
}

Sources/NativeAPI/TrayIcon.swift

Whitespace-only changes.

Sources/NativeAPI/TrayManager.swift

Whitespace-only changes.

0 commit comments

Comments
 (0)