Skip to content

πŸ“¦ Swift Package providing simplified APIs for controlling device features

License

Notifications You must be signed in to change notification settings

superturboryan/ControlKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ControlKit Light ControlKit Dark

ControlKit

ControlKit is a minimal Swift Package enabling control of media playback and device volume.

Build Status Lint Contributors

TLDR

Control the device's volume with one line:

Control.Volume.increase() // πŸ”Š πŸ†™

Installation

Add ControlKit as a dependency in your Xcode project:

  1. Go to File > Add Package Dependencies…

  2. Enter the package URL in the search bar:

https://github.com/superturboryan/ControlKit.git
  1. Choose the libraries you want to include:

Screenshot 2024-10-28 at 17 46 50

Requirements

SpotifyController requires a Spotify Client ID and Redirect URL to authorize with & control the Spotify app.

  1. Define a custom URL scheme for your app. Add a URL Type to the target's Info.plist.

  2. Create an app in the Spotify Developer Dashboard to get a client ID and register your redirect URL (scheme).

Screenshot 2024-10-29 at 17 31 24

Warning πŸ‘‡

The Spotify access token is not persisted across app launches by default.

You must provide an object conforming to DAO<String> if you want the access token to be persisted.

Usage

Control

import Control

// πŸ”Š Decrement system volume
Control.Volume.decrease()

// πŸ•΅οΈβ€β™‚οΈ Check if audio is being played (by another app)
if Control.Playback.isAudioPlaying { 
    // πŸ’ƒπŸ•Ί 
}

// ⏭️ Skip to next track (Apple Music only - use Controllers.SpotifyController for Spotify πŸ’š)
Control.Playback.AppleMusic.skipToNextTrack()

// 🫨 Vibrate
Control.Haptics.vibrate()

Controllers

// App.swift

import Controllers
import SwiftUI

@main struct YourApp: App {

    @StateObject var spotify = SpotifyController(
        config: .init(
            clientID: Secrets.clientID,
            redirectURL: "controlkit://spotify"
        )
    )
    
    var body: some Scene {
        WindowGroup {
            ContentView()
            .environmentObject(spotify)
            .onOpenURL { spotify.setAccessToken(from: $0) } // Parse access token from URL
        }
    }
    
    func skipToNextSpotifyTrack() {
        spotify.skipToNextTrack()
    }
}

// Secrets.swift πŸ”
// Don't forget to gitignore this πŸ™ˆ
enum Secrets {
    static let clientID = "<your client id>"
}

Dependencies

πŸ“š AVFAudio
πŸ“š Media Player
πŸ“¦ SpotifyiOS

Contributing

Contributions and feedback are welcome! πŸ§‘β€πŸ’»πŸ‘©β€πŸ’»

Here are a few guidelines:

  • You can open an Issue or raise a PR 🀝
  • Commit messages should contain emojis ❀️ and be signed πŸ”
  • Workflows should be green 🟒
  • main should be linear πŸŽ‹