-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sleep prevention during file transfer
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// SleepManager.swift | ||
// NearbyShare | ||
// | ||
// Created by Mika on 15.10.23. | ||
// | ||
|
||
import Foundation | ||
import IOKit | ||
import IOKit.pwr_mgt | ||
|
||
class SleepManager{ | ||
public static let shared=SleepManager() | ||
private var assertionID: IOPMAssertionID=0 | ||
|
||
public func disableSleep(){ | ||
if(assertionID != 0){ | ||
return | ||
} | ||
|
||
IOPMAssertionCreateWithName( | ||
kIOPMAssertionTypePreventUserIdleSystemSleep as CFString, | ||
IOPMAssertionLevel(kIOPMAssertionLevelOn), | ||
"Data transfer over NearDrop" as CFString, | ||
&assertionID | ||
) | ||
} | ||
|
||
public func enableSleep(){ | ||
if(assertionID == 0 || NearbyConnectionManager.shared.getActiveConnectionsCount() != 0){ | ||
return | ||
} | ||
|
||
IOPMAssertionRelease(assertionID) | ||
assertionID = 0 | ||
} | ||
|
||
private init(){} | ||
} |