Skip to content

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:
- Extend URL with a new optional computed property, creationDate
- Change the method Utility.getLatestScreenshot to use the array max method
  to find the latest screenshot file
  • Loading branch information
low-batt committed Nov 7, 2022
1 parent 3d8f842 commit 0a8c454
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 4 additions & 0 deletions iina/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ extension NSMenuItem {


extension URL {
var creationDate: Date? {
(try? resourceValues(forKeys: [.creationDateKey]))?.creationDate
}

var isExistingDirectory: Bool {
return (try? self.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false
}
Expand Down
13 changes: 2 additions & 11 deletions iina/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -503,17 +503,8 @@ class Utility {
at: folder,
includingPropertiesForKeys: [.creationDateKey],
options: .skipsSubdirectoryDescendants),
var latestFile = contents.first else { return nil }

var latestDate = Date.distantPast

for file in contents {
if let date = try? file.resourceValues(forKeys: [.creationDateKey]).creationDate, date > latestDate {
latestDate = date
latestFile = file
}
}
return latestFile
!contents.isEmpty else { return nil }
return contents.max { a, b in a.creationDate! < b.creationDate! }
}

/// Make sure the block is executed on the main thread. Be careful since it uses `sync`. Keep the block mininal.
Expand Down

0 comments on commit 0a8c454

Please sign in to comment.