caoimhebyrne / localauthentication-rs

A wrapper for LocalAuthentication.framework in Rust
Apache License 2.0
14 stars 2 forks source link

[Proposal]: Creating NSHapticFeedbackPerformer-rs #3

Open doroved opened 11 months ago

doroved commented 11 months ago

Hi, I couldn't find your contacts, I apologize for writing here. Could you consider creating a crate to manage HapticFeedback? https://developer.apple.com/documentation/appkit/nshapticfeedbackperformer

Unfortunately still no such option on rust, I couldn't find any options.

doroved commented 11 months ago

GPT has never been able to tell me how to do a manager check, so this would have to be implemented. And it would probably be great if you could pass arguments to FeedbackPattern and PerformanceTime functions from rust. (although I've tried all variations of the arguments and haven't noticed a difference in tactile feedback)

In this example, the tactile vibration is triggered 2 times, when we hover the mouse and when we remove it. I hope there will be no duplication when calling a function from rust.

import SwiftUI
import AppKit

func triggerHapticFeedback() {
    if #available(OSX 10.11, *) {
        let manager = NSHapticFeedbackManager.defaultPerformer
        manager.perform(NSHapticFeedbackManager.FeedbackPattern.generic, performanceTime: .now)
    } else {
        // Handle for versions prior to macOS 10.11
    }
}

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
                .onHover { _ in
                    triggerHapticFeedback()
                }
        }
        .padding()
    }
}

#Preview {
    ContentView()
}
caoimhebyrne commented 11 months ago

I can try to make a crate for this, but it might require an NSApplication context - I'll keep you updated with what I find.