mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-05-13 03:30:40 +00:00
37 lines
1.3 KiB
Swift
37 lines
1.3 KiB
Swift
![]() |
//
|
||
|
// CaffeinePlatformChannel.swift
|
||
|
// Runner
|
||
|
//
|
||
|
// Created by Vadim Turko on 2025-05-11.
|
||
|
//
|
||
|
import Flutter
|
||
|
|
||
|
public class CaffeinePlatformChannel: NSObject {
|
||
|
let methodChannel: FlutterMethodChannel
|
||
|
|
||
|
init(binaryMessenger: FlutterBinaryMessenger) {
|
||
|
self.methodChannel = FlutterMethodChannel(
|
||
|
name: "com.vodemn.lightmeter.CaffeinePlatformChannel.MethodChannel",
|
||
|
binaryMessenger: binaryMessenger
|
||
|
)
|
||
|
super.init()
|
||
|
methodChannel.setMethodCallHandler({
|
||
|
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
|
||
|
switch call.method {
|
||
|
case "isKeepScreenOn":
|
||
|
result(UIApplication.shared.isIdleTimerDisabled)
|
||
|
case "setKeepScreenOn":
|
||
|
guard let keepOn = call.arguments as? Bool else {
|
||
|
result(FlutterError(code: "invalid arguments", message: "Argument should be of type Bool for 'setKeepScreenOn' call", details: nil))
|
||
|
return
|
||
|
}
|
||
|
UIApplication.shared.isIdleTimerDisabled = keepOn
|
||
|
result(true)
|
||
|
default:
|
||
|
result(FlutterMethodNotImplemented)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
}
|
||
|
}
|