snapshot of https://github.com/tauri-apps/plugins-workspace.git (v2, 2026-09-23; blobs > 131072B omitted)
Some checks failed
integration tests / run-integration-tests (windows-latest) (push) Has been cancelled
Test Rust / test (push) Has been cancelled
test plugins e2e (mobile) / ios (push) Has been cancelled
test plugins e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test plugins e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
integration tests / run-integration-tests (macos-latest) (push) Has been cancelled
version or publish / version-or-publish (push) Failing after 0s
integration tests / run-integration-tests (ubuntu-22.04) (push) Failing after 0s
Lint JavaScript / eslint (push) Failing after 0s
Sync / sync-to-mirrors (push) Failing after 0s
test plugins e2e (mobile) / android (push) Failing after 0s
test plugins e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
Test Rust / changes (push) Failing after 0s
Lint Rust / changes (push) Failing after 0s
Lint Rust / clippy (push) Has been skipped
Audit Rust / audit-rust (push) Failing after 1s
Audit JavaScript / audit-js (push) Failing after 1s
Some checks failed
integration tests / run-integration-tests (windows-latest) (push) Has been cancelled
Test Rust / test (push) Has been cancelled
test plugins e2e (mobile) / ios (push) Has been cancelled
test plugins e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test plugins e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
integration tests / run-integration-tests (macos-latest) (push) Has been cancelled
version or publish / version-or-publish (push) Failing after 0s
integration tests / run-integration-tests (ubuntu-22.04) (push) Failing after 0s
Lint JavaScript / eslint (push) Failing after 0s
Sync / sync-to-mirrors (push) Failing after 0s
test plugins e2e (mobile) / android (push) Failing after 0s
test plugins e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
Test Rust / changes (push) Failing after 0s
Lint Rust / changes (push) Failing after 0s
Lint Rust / clippy (push) Has been skipped
Audit Rust / audit-rust (push) Failing after 1s
Audit JavaScript / audit-js (push) Failing after 1s
This commit is contained in:
10
plugins/haptics/ios/.gitignore
vendored
Normal file
10
plugins/haptics/ios/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/config/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
Package.resolved
|
||||
34
plugins/haptics/ios/Package.swift
Normal file
34
plugins/haptics/ios/Package.swift
Normal file
@@ -0,0 +1,34 @@
|
||||
// swift-tools-version:5.3
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "tauri-plugin-haptics",
|
||||
platforms: [
|
||||
.macOS(.v10_13),
|
||||
.iOS(.v13),
|
||||
],
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "tauri-plugin-haptics",
|
||||
type: .static,
|
||||
targets: ["tauri-plugin-haptics"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(name: "Tauri", path: "../.tauri/tauri-api")
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||
.target(
|
||||
name: "tauri-plugin-haptics",
|
||||
dependencies: [
|
||||
.byName(name: "Tauri")
|
||||
],
|
||||
path: "Sources")
|
||||
]
|
||||
)
|
||||
3
plugins/haptics/ios/README.md
Normal file
3
plugins/haptics/ios/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Tauri Plugin Haptics
|
||||
|
||||
A description of this package.
|
||||
133
plugins/haptics/ios/Sources/HapticsPlugin.swift
Normal file
133
plugins/haptics/ios/Sources/HapticsPlugin.swift
Normal file
@@ -0,0 +1,133 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import AudioToolbox
|
||||
import CoreHaptics
|
||||
import SwiftRs
|
||||
import Tauri
|
||||
import UIKit
|
||||
import WebKit
|
||||
|
||||
class ImpactFeedbackOptions: Decodable {
|
||||
let style: ImpactFeedbackStyle
|
||||
}
|
||||
|
||||
enum ImpactFeedbackStyle: String, Decodable {
|
||||
case light, medium, heavy, soft, rigid
|
||||
|
||||
func into() -> UIImpactFeedbackGenerator.FeedbackStyle {
|
||||
switch self {
|
||||
case .light:
|
||||
return .light
|
||||
case .medium:
|
||||
return .medium
|
||||
case .heavy:
|
||||
return .heavy
|
||||
case .soft:
|
||||
return .soft
|
||||
case .rigid:
|
||||
return .rigid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NotificationFeedbackOptions: Decodable {
|
||||
let type: NotificationFeedbackType
|
||||
}
|
||||
|
||||
enum NotificationFeedbackType: String, Decodable {
|
||||
case success, warning, error
|
||||
|
||||
func into() -> UINotificationFeedbackGenerator.FeedbackType {
|
||||
switch self {
|
||||
case .success:
|
||||
return .success
|
||||
case .warning:
|
||||
return .warning
|
||||
case .error:
|
||||
return .error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VibrateOptions: Decodable {
|
||||
// TODO: Array
|
||||
let duration: Double
|
||||
}
|
||||
|
||||
class HapticsPlugin: Plugin {
|
||||
//
|
||||
// Tauri commands
|
||||
//
|
||||
|
||||
@objc public func vibrate(_ invoke: Invoke) throws {
|
||||
let args = try invoke.parseArgs(VibrateOptions.self)
|
||||
if CHHapticEngine.capabilitiesForHardware().supportsHaptics {
|
||||
do {
|
||||
let engine = try CHHapticEngine()
|
||||
try engine.start()
|
||||
engine.resetHandler = { [] in
|
||||
do {
|
||||
try engine.start()
|
||||
} catch {
|
||||
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate)
|
||||
}
|
||||
}
|
||||
// TODO: Make some of this (or all) configurable?
|
||||
let intensity: CHHapticEventParameter = CHHapticEventParameter(
|
||||
parameterID: .hapticIntensity, value: 1.0)
|
||||
let sharpness: CHHapticEventParameter = CHHapticEventParameter(
|
||||
parameterID: .hapticSharpness, value: 1.0)
|
||||
let continuousEvent = CHHapticEvent(
|
||||
eventType: .hapticContinuous,
|
||||
parameters: [intensity, sharpness],
|
||||
relativeTime: 0.0,
|
||||
duration: args.duration / 1000
|
||||
)
|
||||
let pattern = try CHHapticPattern(events: [continuousEvent], parameters: [])
|
||||
let player = try engine.makePlayer(with: pattern)
|
||||
|
||||
try player.start(atTime: 0)
|
||||
} catch {
|
||||
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate)
|
||||
}
|
||||
} else {
|
||||
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate)
|
||||
}
|
||||
|
||||
invoke.resolve()
|
||||
}
|
||||
|
||||
@objc public func impactFeedback(_ invoke: Invoke) throws {
|
||||
let args = try invoke.parseArgs(ImpactFeedbackOptions.self)
|
||||
let generator = UIImpactFeedbackGenerator(style: args.style.into())
|
||||
generator.prepare()
|
||||
generator.impactOccurred()
|
||||
|
||||
invoke.resolve()
|
||||
}
|
||||
|
||||
@objc public func notificationFeedback(_ invoke: Invoke) throws {
|
||||
let args = try invoke.parseArgs(NotificationFeedbackOptions.self)
|
||||
let generator = UINotificationFeedbackGenerator()
|
||||
generator.prepare()
|
||||
generator.notificationOccurred(args.type.into())
|
||||
|
||||
invoke.resolve()
|
||||
}
|
||||
|
||||
// TODO: Consider breaking this up into Start,Change,End like capacitor
|
||||
@objc public func selectionFeedback(_ invoke: Invoke) throws {
|
||||
let generator = UISelectionFeedbackGenerator()
|
||||
generator.prepare()
|
||||
generator.selectionChanged()
|
||||
|
||||
invoke.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("init_plugin_haptics")
|
||||
func initPlugin() -> Plugin {
|
||||
return HapticsPlugin()
|
||||
}
|
||||
12
plugins/haptics/ios/Tests/PluginTests/PluginTests.swift
Normal file
12
plugins/haptics/ios/Tests/PluginTests/PluginTests.swift
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import XCTest
|
||||
@testable import ExamplePlugin
|
||||
|
||||
final class ExamplePluginTests: XCTestCase {
|
||||
func testExample() throws {
|
||||
let plugin = ExamplePlugin()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user