2026-02-04 14:52:09 +09:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit
|
2026-02-05 14:26:02 +09:00
|
|
|
import org.slf4j.LoggerFactory
|
|
|
|
|
import ch.qos.logback.classic.Level
|
|
|
|
|
import ch.qos.logback.classic.Logger
|
2026-02-04 14:52:09 +09:00
|
|
|
|
|
|
|
|
object SystemSleepPreventer {
|
|
|
|
|
private var process: Process? = null
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 맥의 절전 모드 및 디스플레이 취침을 방지하는 명령 실행
|
|
|
|
|
*/
|
|
|
|
|
fun start() {
|
2026-02-05 14:26:02 +09:00
|
|
|
val root = LoggerFactory.getLogger("Exposed") as Logger
|
|
|
|
|
root.level = Level.ERROR
|
|
|
|
|
|
2026-02-04 14:52:09 +09:00
|
|
|
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 종료됨: 시스템 절전 설정이 정상화됩니다.")
|
|
|
|
|
}
|
|
|
|
|
}
|