Skip to content

Commit

Permalink
Final adjustments for alpha release (#37)
Browse files Browse the repository at this point in the history
* Remove CocoaPods for now
* Provide index instead of context
* Pass "missing entitlement" error to state handler
* Fix build badge in README
  • Loading branch information
r-dent authored Mar 4, 2024
1 parent 1f09c7e commit 8bb4876
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 259 deletions.
28 changes: 10 additions & 18 deletions Documentation/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,24 @@ During the alpha phase, the app is not in available in the App Store. [Click her

## Installation

### Swift Package Manager
### Package

You can add the library to your XCode project via Swift Package Manager. See "[Adding package dependencies to your app](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app)".

If you want to add it to your own libraries `Package.swift`, use this code instead:

```swift
dependencies: [
.package(url: "https://github.com/elgatosf/streamdeck-kit-ipad.git", upToNextMajor: "0.0.1")
]
```

### CocoaPods

Example Podfile
### Entitlements

```Ruby
platform :ios, '16.0'

target 'YourAppTarget' do
use_frameworks!
pod 'StreamDeckKit'
pod 'StreamDeckSimulator', :configurations => ['Debug']
end
```
In order to connect to the Stream Deck driver, you need to add the "[Communicates with Drivers](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_driverkit_communicates-with-drivers)" (`com.apple.developer.driverkit.communicates-with-drivers`) capability to your app target. Refer to "[Adding capabilities to your app](https://developer.apple.com/documentation/xcode/adding-capabilities-to-your-app/)" for guidance.

## First steps

First, add the [DriverKit Communicates with Drivers](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_driverkit_communicates-with-drivers) capability to your app target. Refer to [Adding capabilities to your app](https://developer.apple.com/documentation/xcode/adding-capabilities-to-your-app/) for guidance.

Rendering content on a Stream Deck is very simple with SwiftUI, much like designing a typical app UI.

```swift
Expand Down Expand Up @@ -74,15 +66,15 @@ struct MyFirstStreamDeckLayout {
StreamDeckLayout {
// Define key area
// Use StreamDeckKeyAreaLayout for rendering separate keys
StreamDeckKeyAreaLayout { context in
StreamDeckKeyAreaLayout { keyIndex in
// Define content for each key.
// StreamDeckKeyAreaLayout provides a context for each available key,
// StreamDeckKeyAreaLayout provides an index for each available key,
// and StreamDeckKeyView provides a callback for the key action
// Example:
StreamDeckKeyView { pressed in
print("pressed \(pressed)")
} content: {
Text("\(context.index)")
Text("\(keyIndex)")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.teal)
}
Expand Down
14 changes: 7 additions & 7 deletions Documentation/Layout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ struct StatelessStreamDeckLayout {
StreamDeckLayout {
// Define key area
// Use StreamDeckKeyAreaLayout for rendering separate keys
StreamDeckKeyAreaLayout { context in
StreamDeckKeyAreaLayout { keyIndex in
// Define content for each key.
// StreamDeckKeyAreaLayout provides a context for each available key,
// StreamDeckKeyAreaLayout provides an index for each available key,
// and StreamDeckKeyView provides a callback for the key action
// Example:
StreamDeckKeyView { pressed in
print("pressed \(pressed)")
} content: {
Text("\(context.index)")
Text("\(keyIndex)")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.teal)
}
}.background(.purple)
} windowArea: {
// Define window area
// Use StreamDeckDialAreaLayout for rendering separate parts of the display
StreamDeckDialAreaLayout { context in
StreamDeckDialAreaLayout { dialIndex in
// Define content for each dial
// StreamDeckDialAreaLayout provides a context for each available dial,
// StreamDeckDialAreaLayout provides an index for each available dial,
// and StreamDeckDialView provides callbacks for the dial actions
// Example:
StreamDeckDialView { rotations in
Expand All @@ -72,9 +72,9 @@ struct StatelessStreamDeckLayout {
} touch: { location in
print("touched at \(location)")
} content: {
Text("\(context.index)")
Text("\(dialIndex)")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(white: Double(context.index) / 5 + 0.5))
.background(Color(white: Double(dialIndex) / 5 + 0.5))
}
}
}.background(.indigo)
Expand Down
14 changes: 7 additions & 7 deletions Example/Example App/Examples/1_StatelessStreamDeckLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ struct StatelessStreamDeckLayout {
StreamDeckLayout {
// Define key area
// Use StreamDeckKeyAreaLayout for rendering separate keys
StreamDeckKeyAreaLayout { context in
StreamDeckKeyAreaLayout { keyIndex in
// Define content for each key.
// StreamDeckKeyAreaLayout provides a context for each available key,
// StreamDeckKeyAreaLayout provides an index for each available key,
// and StreamDeckKeyView provides a callback for the key action
// Example:
StreamDeckKeyView { pressed in
print("pressed \(pressed)")
} content: {
Text("\(context.index)")
Text("\(keyIndex)")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.teal)
}
}.background(.purple)
} windowArea: {
// Define window area
// Use StreamDeckDialAreaLayout for rendering separate parts of the display
StreamDeckDialAreaLayout { context in
StreamDeckDialAreaLayout { dialIndex in
// Define content for each dial
// StreamDeckDialAreaLayout provides a context for each available dial,
// StreamDeckDialAreaLayout provides an index for each available dial,
// and StreamDeckDialView provides callbacks for the dial actions
// Example:
StreamDeckDialView { rotations in
Expand All @@ -43,9 +43,9 @@ struct StatelessStreamDeckLayout {
} touch: { location in
print("touched at \(location)")
} content: {
Text("\(context.index)")
Text("\(dialIndex)")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(white: Double(context.index) / 5 + 0.5))
.background(Color(white: Double(dialIndex) / 5 + 0.5))
}
}
}.background(.indigo)
Expand Down
7 changes: 4 additions & 3 deletions Example/Example App/StreamDeckKitExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ struct StreamDeckKitExampleApp: App {
// Uncomment the next line to enable StreamDeckKit internal logging.
// streamDeckLoggingHandler = { os_log($0, "\($1)") }

StreamDeckSession.setUp(newDeviceHandler: {
$0.render(BaseStreamDeckView())
})
StreamDeckSession.setUp(
stateHandler: { os_log("Stream Deck session state: %s", String(describing: $0)) },
newDeviceHandler: { $0.render(BaseStreamDeckView()) }
)
}

var body: some Scene {
Expand Down
3 changes: 0 additions & 3 deletions Gemfile

This file was deleted.

107 changes: 0 additions & 107 deletions Gemfile.lock

This file was deleted.

28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Stream Deck Kit is a Swift Library for controlling physical [Elgato Stream Deck](https://www.elgato.com/stream-deck) devices with an iPadOS app.

<a href="https://github.com/elgatosf/streamdeck-kit-ipad/actions/workflows/run-tests.yml" alt="Run tests">
<img src="https://github.com/elgatosf/streamdeck-kit-ipad/actions/workflows/run-tests.yml/badge.svg" />
</a>
![Build all targets workflow badge](https://github.com/elgatosf/streamdeck-kit-ipad/actions/workflows/build-all-targets.yml/badge.svg)
![Lint workflow badge](https://github.com/elgatosf/streamdeck-kit-ipad/actions/workflows/lint.yml/badge.svg)
![Tests workflow badge](https://github.com/elgatosf/streamdeck-kit-ipad/actions/workflows/test.yml/badge.svg)

## Features

Expand Down Expand Up @@ -46,32 +46,24 @@ However, if you want to verify your implementation using the [Stream Deck Simula

## Installation

### Swift Package Manager
### Package

You can add the library to your XCode project via Swift Package Manager. See "[Adding package dependencies to your app](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app)".

If you want to add it to your own libraries `Package.swift`, use this code instead:

```swift
dependencies: [
.package(url: "https://github.com/elgatosf/streamdeck-kit-ipad.git", upToNextMajor: "0.0.1")
]
```

### CocoaPods

Example Podfile
### Entitlements

```Ruby
platform :ios, '16.0'

target 'YourAppTarget' do
use_frameworks!
pod 'StreamDeckKit'
pod 'StreamDeckSimulator', :configurations => ['Debug']
end
```
In order to connect to the Stream Deck driver, you need to add the "[Communicates with Drivers](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_driverkit_communicates-with-drivers)" (`com.apple.developer.driverkit.communicates-with-drivers`) capability to your app target. Refer to "[Adding capabilities to your app](https://developer.apple.com/documentation/xcode/adding-capabilities-to-your-app/)" for guidance.

## Getting started

First, add the [DriverKit Communicates with Drivers](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_driverkit_communicates-with-drivers) capability to your app target. Refer to [Adding capabilities to your app](https://developer.apple.com/documentation/xcode/adding-capabilities-to-your-app/) for guidance.

Rendering content on a Stream Deck is very simple with SwiftUI, much like designing a typical app UI.

```swift
Expand Down
2 changes: 2 additions & 0 deletions Sources/StreamDeckCApi/StreamDeckCApi.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@

#include <stdio.h>
#import "include/StreamDeckCApi.h"

const IOReturn sdkIOReturnNotPermitted = kIOReturnNotPermitted;
3 changes: 3 additions & 0 deletions Sources/StreamDeckCApi/include/StreamDeckCApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
#include <IOKit/IOKitLib.h>
#include "StreamDeckDriverShared.h"

/// Exported error constant to handle problems with "Communicates with Driver" capability in Swift.
extern const IOReturn sdkIOReturnNotPermitted;

#endif /* StreamDeckCApi_h */
13 changes: 7 additions & 6 deletions Sources/StreamDeckKit/Layout/StreamDeckDialAreaLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,25 @@ public struct StreamDeckDialAreaLayout<Dial: View>: View {
/// A handler for press events on a rotary encoder(dial).
///
/// The first parameter is the index of the dial. The second one indicates if the dial is down or not.
public typealias DialPressHandler = @MainActor (Int, Bool) -> Void
public typealias DialPressHandler = @MainActor (_ index: Int, _ isPressed: Bool) -> Void
public typealias TouchHandler = @MainActor (CGPoint) -> Void
public typealias FlingHandler = @MainActor (CGPoint, CGPoint, InputEvent.Direction) -> Void
public typealias FlingHandler = @MainActor (_ start: CGPoint, _ end: CGPoint, _ direction: InputEvent.Direction) -> Void
public typealias DialProvider = @MainActor (_ keyIndex: Int) -> Dial

@Environment(\.streamDeckViewContext) private var context

private let rotate: DialRotationHandler?
private let press: DialPressHandler?
private let touch: TouchHandler?
private let fling: FlingHandler?
@ViewBuilder private let dial: @MainActor (StreamDeckViewContext) -> Dial
@ViewBuilder private let dial: DialProvider

public init(
rotate: DialRotationHandler? = nil,
press: DialPressHandler? = nil,
touch: TouchHandler? = nil,
fling: FlingHandler? = nil,
@ViewBuilder dial: @escaping @MainActor (StreamDeckViewContext) -> Dial
@ViewBuilder dial: @escaping DialProvider
) {
self.rotate = rotate
self.press = press
Expand All @@ -72,7 +73,7 @@ public struct StreamDeckDialAreaLayout<Dial: View>: View {
press: @escaping @MainActor (Int) -> Void,
touch: TouchHandler? = nil,
fling: FlingHandler? = nil,
@ViewBuilder dial: @escaping @MainActor (StreamDeckViewContext) -> Dial
@ViewBuilder dial: @escaping DialProvider
) {
self.init(
rotate: rotate,
Expand All @@ -96,7 +97,7 @@ public struct StreamDeckDialAreaLayout<Dial: View>: View {
index: section
)

dial(dialContext)
dial(dialContext.index)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.environment(\.streamDeckViewContext, dialContext)
}
Expand Down
Loading

0 comments on commit 8bb4876

Please sign in to comment.