Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Sources/Control/Screen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Screen.swift
// ControlKit
//

import UIKit

public extension Control {

/// 🔆 Control the device's screen's brightness.
@MainActor
enum Screen {

public static var isKeptAwake: Bool {
get {
UIApplication.shared.isIdleTimerDisabled
}
set {
UIApplication.shared.isIdleTimerDisabled = newValue
}
}

public static var brightness: CGFloat {
get {
UIScreen.main.brightness
}
set {
UIScreen.main.brightness = min(max(newValue, 0.0), 1.0)
}
}

public static var isDimmed: Bool {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Add documentation

get {
brightness == 0
}
set {
if newValue {
dimScreenValue = brightness
brightness = 0
} else {
brightness = dimScreenValue
}
}
}

private static var dimScreenValue: CGFloat = 0
}
}