-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Let's add a way to control the brightness of the device's screen.
We can also control whether it "falls asleep" with UIApplication.shared.isIdleTimerDisabled.
Rough draft:
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 {
brightness == 0
}
public static func toggleDimmedScreen() {
if isDimmed {
brightness = dimScreenValue
} else {
dimScreenValue = brightness
brightness = 0
}
}
private static var dimScreenValue: CGFloat = 0
}
}Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request