Skip to content

πŸ“Ί Add screen controlΒ #11

@superturboryan

Description

@superturboryan

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

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions