mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00

https://forums.ankiweb.net/t/recent-anki-updates-bundle-id-change-disabling-app-nap-macos-anki-connect/65550
25 lines
No EOL
696 B
Swift
25 lines
No EOL
696 B
Swift
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import Foundation
|
|
|
|
private var currentActivity: NSObjectProtocol?
|
|
|
|
@_cdecl("disable_appnap")
|
|
public func disableAppNap() {
|
|
// No-op if already assigned
|
|
guard currentActivity == nil else { return }
|
|
|
|
currentActivity = ProcessInfo.processInfo.beginActivity(
|
|
options: .userInitiatedAllowingIdleSystemSleep,
|
|
reason: "AppNap is disabled"
|
|
)
|
|
}
|
|
|
|
@_cdecl("enable_appnap")
|
|
public func enableAppNap() {
|
|
guard let activity = currentActivity else { return }
|
|
|
|
ProcessInfo.processInfo.endActivity(activity)
|
|
currentActivity = nil
|
|
} |