35 lines
1.2 KiB
Kotlin
35 lines
1.2 KiB
Kotlin
package service
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
object SystemSleepPreventer {
|
|
private var process: Process? = null
|
|
|
|
/**
|
|
* 맥의 절전 모드 및 디스플레이 취침을 방지하는 명령 실행
|
|
*/
|
|
fun start() {
|
|
if (process?.isAlive == true) return
|
|
|
|
try {
|
|
// -i: 시스템 절전 방지, -d: 디스플레이 취침 방지, -m: 디스크 유휴 상태 방지
|
|
val command = listOf("caffeinate", "-i", "-d", "-m")
|
|
process = ProcessBuilder(command).start()
|
|
println("☕ [System] caffeinate 실행됨: 앱이 켜져 있는 동안 절전 모드가 방지됩니다.")
|
|
} catch (e: Exception) {
|
|
println("⚠️ [System] caffeinate 실행 실패: ${e.message}")
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 앱 종료 시 프로세스 함께 종료
|
|
*/
|
|
fun stop() {
|
|
process?.destroy()
|
|
// 프로세스가 강제 종료되지 않을 경우를 대비해 0.5초 대기 후 강제 종료
|
|
if (process?.waitFor(500, TimeUnit.MILLISECONDS) == false) {
|
|
process?.destroyForcibly()
|
|
}
|
|
println("🛑 [System] caffeinate 종료됨: 시스템 절전 설정이 정상화됩니다.")
|
|
}
|
|
} |