Skip to content

Commit

Permalink
Fix Error Cannot prevent display sleep!, iina#3842
Browse files Browse the repository at this point in the history
The commit in the pull request will:
- Change SleepPreventer.preventSleep to only display an alert once per
  IINA invocation
- Change Utility.showAlert to support a suppression button
- Add a button to the alert to allow the user to permanently suppress
  the alert
- Change the alert to include the error code returned by macOS

Additional text was added to the alert's message requiring localization.

This fixes how IINA reports a macOS power management failure.
The root cause of the failure is in macOS and must be fixed by Apple.
  • Loading branch information
low-batt committed Aug 23, 2022
1 parent dc5f236 commit 17ba106
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
2 changes: 1 addition & 1 deletion iina/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

"alert.fatal_error" = "Fatal error: %@ \nThe application will exit now.";
"alert.mpv_error" = "Internal error %@ (%@) when setting option %@.";
"alert.sleep" = "Cannot prevent display sleep!\nmacOS error 0x%0X8";
"alert.sleep" = "Cannot prevent display sleep! (0x%0X8)";

"alert.unsupported_audio" = "Unsupported external audio file.";
"alert.unsupported_sub" = "Unsupported external subtitle.";
Expand Down
16 changes: 1 addition & 15 deletions iina/SleepPreventer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,7 @@ class SleepPreventer: NSObject {
/// ```
/// Hopefully the quality of macOS will improve and there will not be a need to provide a UI to control this preference.
///
/// In issue [#3478](https://github.com/iina/iina/issues/3478) `IOPMAssertionCreateWithName` was
/// returning returning the error code `kIOReturnNoMemory`. At that time a`IOPMAssertionCreateWithName` failure resulted
/// in IINA crashing due to IINA not using the main thread to display a `NSAlert`. That was fixed in IINA 1.3.0.
///
/// The reason why `powerd` had run out of memory was traced to the macOS `coreaudiod` daemon creating thousands of
/// assertions. The `coreaudiod` daemon was also frequently crashing and restarting. This was traced to audio related software
/// from [Rogue Amoeba](https://rogueamoeba.com/) which includes the [Audio Capture Engine (ACE)](https://www.rogueamoeba.com/licensing/ace/)
/// driver that is installed into the macOS daemon `coreaudiod`. The user upgraded to the latest version of ACE and the
/// problem no longer reproduced.
///
/// In issue [#3842](https://github.com/iina/iina/issues/3842) the same error code, `kIOReturnNoMemory`,
/// was being returned, but a new root cause was seen. It appears at this time that Apple has introduced a regression into the
/// `powerd` daemon such that it internally generates thousands of assertions running itself out of memory. Another
/// symptom of this is the `powerd` daemon consuming 100% CPU causing the Mac's fans to run at full speed. Some of
/// the other reports from users in that issue appear to be due to the ACE driver.
/// See issues [#3842](https://github.com/iina/iina/issues/3842) and [#3478](https://github.com/iina/iina/issues/3478) for details on the macOS failure.
static func preventSleep() {
if preventedSleep {
return
Expand Down
2 changes: 1 addition & 1 deletion iina/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

"alert.fatal_error" = "Fatal error: %@ \nThe application will exit now.";
"alert.mpv_error" = "Internal error %@ (%@) when setting option %@.";
"alert.sleep" = "Cannot prevent display sleep!\nmacOS error 0x%0X8";
"alert.sleep" = "Cannot prevent display sleep! (0x%0X8)";

"alert.unsupported_audio" = "Unsupported external audio file.";
"alert.unsupported_sub" = "Unsupported external subtitle.";
Expand Down

0 comments on commit 17ba106

Please sign in to comment.