Skip to content

Commit

Permalink
Update "data last opened" attribute on file start (#3707)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhc70000 committed May 5, 2022
1 parent faa58ac commit 5af1a7e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions iina/PlayerCore.swift
Expand Up @@ -1052,6 +1052,23 @@ class PlayerCore: NSObject {
URL(fileURLWithPath: path)
info.isNetworkResource = !info.currentURL!.isFileURL

// set "date last opened" attribute
if let url = info.currentURL, url.isFileURL {
// the required data is a timespec struct
var ts = timespec()
let time = Date().timeIntervalSince1970
ts.tv_sec = Int(time)
ts.tv_nsec = Int(time.truncatingRemainder(dividingBy: 1) * 1_000_000_000)
let data = Data(bytesOf: ts)
// set the attribute; the key is undocumented
let name = "com.apple.lastuseddate#PS"
url.withUnsafeFileSystemRepresentation { fileSystemPath in
let _ = data.withUnsafeBytes {
setxattr(fileSystemPath, name, $0.baseAddress, data.count, 0, 0)
}
}
}

if #available(OSX 10.13, *), RemoteCommandController.useSystemMediaControl {
NowPlayingInfoManager.updateInfo(state: .playing, withTitle: true)
}
Expand Down

0 comments on commit 5af1a7e

Please sign in to comment.