Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
Fix screenshot crash with long video title, iina#3334
Browse files Browse the repository at this point in the history
This commit will:

- Change the method  MPVController.handleEvent to raise an alert if
    screenshot generation failed
- Change the method  Utility.getLatestScreenshot to guard against an empty
    screenshot directory

This commit adds new text for the alert that will require localization.
  • Loading branch information
low-batt authored and CarterLi committed Jan 19, 2022
1 parent 905c40d commit 83e3591
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions iina/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@

"alert.playlist.error_deleting" = "Error deleting: %@";

"alert.screenshot.error_taking" = "Cannot take a screenshot!";

"alert.sub.no_selected" = "Please select a downloaded subtitle first.";
"alert.sub_lang_not_set" = "Please set preferred subtitle languages in preferences before using OpenSubtitles. English(eng) will be used this time.";
"alert.sub.cannot_save_passwd" = "Cannot save your password to Keychain: %@";
Expand Down
12 changes: 12 additions & 0 deletions iina/MPVController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,18 @@ class MPVController: NSObject {
case MPV_EVENT_COMMAND_REPLY:
let reply = event.pointee.reply_userdata
if reply == MPVController.UserData.screenshot {
let code = event.pointee.error
guard 0 <= code else {
let error = String.init(cString: mpv_error_string(code))
Logger.log("Cannot take a screenshot, mpv API error: \(error), Return value: \(code)", level: .error)
// Unfortunately the mpv API does not provide any details on the failure. The error
// code returned maps to "error running command", so all the alert can report is
// that we cannot take a screenshot.
DispatchQueue.main.async {
Utility.showAlert("screenshot.error_taking")
}
return
}
player.screenshotCallback()
}

Expand Down
2 changes: 1 addition & 1 deletion iina/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class Utility {
guard let contents = try? FileManager.default.contentsOfDirectory(
at: folder,
includingPropertiesForKeys: [.creationDateKey],
options: .skipsSubdirectoryDescendants) else { return nil }
options: .skipsSubdirectoryDescendants), !contents.isEmpty else { return nil }

var latestDate = Date.distantPast
var latestFile: URL = contents[0]
Expand Down
2 changes: 2 additions & 0 deletions iina/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@

"alert.playlist.error_deleting" = "Error deleting: %@";

"alert.screenshot.error_taking" = "Cannot take a screenshot!";

"alert.sub.no_selected" = "Please select a downloaded subtitle first.";
"alert.sub_lang_not_set" = "Please set preferred subtitle languages in preferences before using OpenSubtitles. English(eng) will be used this time.";
"alert.sub.cannot_save_passwd" = "Cannot save your password to Keychain: %@";
Expand Down

0 comments on commit 83e3591

Please sign in to comment.