aboutsummaryrefslogtreecommitdiff
path: root/Sources/SleepInhibitor.swift
diff options
context:
space:
mode:
authorGrégoire Duchêne <gregoire@awhk.org>2026-09-16 15:23:36 +0100
committerGrégoire Duchêne <gregoire@awhk.org>2026-09-16 15:23:36 +0100
commit3f5e77bac4cae53957eb707eb298fe34858fc335 (patch)
tree33fff16e81a1692b6dbe81067336cc93a757be05 /Sources/SleepInhibitor.swift
parent5855696b7d8d360794ae5efba4dbc90e31eaf260 (diff)
Make sleep inhibition more structuredHEADmain
Diffstat (limited to 'Sources/SleepInhibitor.swift')
-rw-r--r--Sources/SleepInhibitor.swift48
1 files changed, 0 insertions, 48 deletions
diff --git a/Sources/SleepInhibitor.swift b/Sources/SleepInhibitor.swift
deleted file mode 100644
index 0cfe895..0000000
--- a/Sources/SleepInhibitor.swift
+++ /dev/null
@@ -1,48 +0,0 @@
-import IOKit.pwr_mgt
-
-actor SleepInhibitor {
- var assertionID = IOPMAssertionID?.none
- var isInhibitingSleep: Bool { self.assertionID != nil }
-
- func create(name: String, details: String) throws {
- guard self.assertionID == nil else {
- return
- }
-
- var assertionID = IOPMAssertionID(0)
- let ioReturn = IOPMAssertionCreateWithDescription(
- kIOPMAssertionTypePreventUserIdleSystemSleep as CFString,
- name as CFString,
- details as CFString,
- nil, nil, 0, nil,
- &assertionID
- )
- guard ioReturn == kIOReturnSuccess else {
- throw SleepInhibitorError(ioReturn: ioReturn)
- }
- self.assertionID = assertionID
- }
-
- func release() throws {
- guard let assertionID = self.assertionID else {
- return
- }
-
- let ioReturn = IOPMAssertionRelease(assertionID)
- guard ioReturn == kIOReturnSuccess else {
- throw SleepInhibitorError(ioReturn: ioReturn)
- }
- self.assertionID = nil
- }
-}
-
-struct SleepInhibitorError: CustomStringConvertible, Error {
- let ioReturn: IOReturn
-
- var description: String {
- guard let cString = mach_error_string(self.ioReturn) else {
- return self.ioReturn.description
- }
- return String(cString: cString)
- }
-}