SvenTiigi / WhatsNewKit

Showcase your awesome new app features 📱
https://sventiigi.github.io/WhatsNewKit/
MIT License
3.92k stars 193 forks source link

Idea: create a dummy for notification and haptic on macOS #61

Closed chbeer closed 2 years ago

chbeer commented 2 years ago

Notifications and haptics are not available on macOS. So code that uses them does not build on macOS. You can add conditions to fix this but it makes things more complicated.

Would creating dummies for these on macOS be a way to go? Then the same code would build also on macOS.

There could be a log message on macOS.

SvenTiigi commented 2 years ago

Hi @chbeer,

As UIFeedbackGenerator alongside with its subclasses are unavailable on macOS the usage of WhatsNew.HapticFeedback should be surrounded with an OS-Availability check.

A fix for your PR https://github.com/SvenTiigi/WhatsNewKit/pull/60 could be the following one.

// ...

decoder.userInfo["continue"] = WhatsNew.PrimaryAction(
    title: "Continue",
    backgroundColor: .accentColor,
    foregroundColor: .white,
    hapticFeedback: {
        #if !os(macOS)
        return .notification(.success)
        #else
        return nil
        #endif
    }(),
    onDismiss: {
        print("WhatsNewView has been dismissed")
    }
)

// ...

#if !os(macOS)
XCTAssertEqual(whatsNew.primaryAction.hapticFeedback, .notification(.success))
#endif
chbeer commented 2 years ago

Fixed my PR with your suggestion