Skip to content

codingiran/SystemExtensionKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


logo

Modern Swift Wrapper for SystemExtensions API


SwiftPM Compatible Cocoapods Compatible macOS Versions Supported MIT License

SystemExtensionKit

A modern Swift wrapper for Apple's SystemExtensions framework that provides async/await support and simplified APIs for managing system extensions on macOS.

Features

  • πŸ”„ Async/await support - Modern Swift concurrency
  • πŸ“± Simple API - Easy-to-use methods for common tasks
  • πŸ›‘οΈ Error handling - Comprehensive error types and descriptions
  • πŸ“Š Progress tracking - Real-time status updates
  • 🎯 Swift 5.10+ - Built for modern Swift
  • πŸ“¦ SwiftPM - Multiple installation options

Requirements

  • macOS 10.15+
  • Swift 5.10+
  • Xcode 14.0+

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/codingiran/SystemExtensionKit.git", from: "2.1.0")
]

Quick Start

Basic Usage

import SystemExtensionKit

// Activate system extension
do {
    try await SystemExtension.activeSystemExtension()
    print("Extension activated successfully")
} catch {
    print("Failed to activate: \(error.localizedDescription)")
}

// Check extension status
let status = await SystemExtension.checkSystemExtensionStatus()
switch status {
case .installed:
    print("Extension is installed and running")
case .waitingApproval:
    print("Extension needs user approval")
case .notInstalled:
    print("Extension is not installed")
case .unknown:
    print("Status unknown (macOS < 12.0)")
}

// Deactivate system extension
do {
    try await SystemExtension.deactiveSystemExtension()
    print("Extension deactivated successfully")
} catch {
    print("Failed to deactivate: \(error.localizedDescription)")
}

Progress Monitoring

class ExtensionManager: SystemExtensionRequestUpdating {
    
    func setupExtension() {
        // Set progress updater
        SystemExtension.requestUpdater = self
        
        Task {
            do {
                try await SystemExtension.activeSystemExtension()
            } catch {
                print("Extension activation failed: \(error)")
            }
        }
    }
    
    // MARK: - SystemExtensionRequestUpdating
    
    func systemExtensionRequest(_ request: SystemExtensionRequest, updateProgress progress: SystemExtensionRequest.Progress) {
        switch progress {
        case .submitting:
            print("Submitting extension request...")
        case .needsUserApproval:
            print("User approval required")
        case .completed:
            print("Extension request completed")
        case .willCompleteAfterReboot:
            print("Restart required to complete")
        case .failed(let error):
            print("Request failed: \(error.localizedDescription)")
        case .replacingExtension(let existing, let new):
            print("Replacing version \(existing) with \(new)")
        case .cancelExtension(let existing, let new):
            print("Canceling replacement of \(existing) with \(new)")
        }
    }
}

Advanced Usage

// Force update extension
try await SystemExtension.activeSystemExtension(forceUpdate: true)

// Get extension properties (macOS 12.0+)
if #available(macOS 12.0, *) {
    if let properties = try await SystemExtension.enabledSystemExtensionProperty() {
        print("Bundle ID: \(properties.bundleIdentifier)")
        print("Version: \(properties.bundleVersion)")
        print("Awaiting approval: \(properties.isAwaitingUserApproval)")
    }
}

Error Handling

SystemExtensionKit provides comprehensive error types:

do {
    try await SystemExtension.activeSystemExtension()
} catch SystemExtensionKit.ExtensionError.extensionNotExist {
    print("No system extension found in app bundle")
} catch SystemExtensionKit.ExtensionError.extensionNeedReboot {
    print("System restart required")
} catch SystemExtensionKit.ExtensionError.extensionSystemUnsupport {
    print("System version not supported")
} catch {
    print("Other error: \(error.localizedDescription)")
}

License

SystemExtensionKit is available under the MIT license. See the LICENSE file for more info.

About

macOS platform utils for SystemExtension

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages