Skip to content
Permalink
Browse files

Merge pull request #2378 from iina/swift-5

Update for Swift 5
  • Loading branch information...
alejx committed May 21, 2019
2 parents 985fc87 + e9e49d1 commit 0595aba5b426910f7b6106755c31405ae2d604fd
Showing with 373 additions and 320 deletions.
  1. +1 −1 .travis.yml
  2. +2 −2 Podfile
  3. +12 −11 Podfile.lock
  4. BIN deps/lib/libSDL2-2.0.0.dylib
  5. BIN deps/lib/libarchive.13.dylib
  6. BIN deps/lib/libass.9.dylib
  7. BIN deps/lib/libavcodec.58.35.100.dylib
  8. BIN deps/lib/libavcodec.58.dylib
  9. BIN deps/lib/libavcodec.58.dylib
  10. +0 −1 deps/lib/libavcodec.dylib
  11. BIN deps/lib/libavdevice.58.5.100.dylib
  12. BIN deps/lib/libavdevice.58.dylib
  13. BIN deps/lib/libavdevice.58.dylib
  14. +0 −1 deps/lib/libavdevice.dylib
  15. BIN deps/lib/libavfilter.7.40.101.dylib
  16. BIN deps/lib/libavfilter.7.dylib
  17. BIN deps/lib/libavfilter.7.dylib
  18. +0 −1 deps/lib/libavfilter.dylib
  19. BIN deps/lib/libavformat.58.20.100.dylib
  20. BIN deps/lib/libavformat.58.dylib
  21. BIN deps/lib/libavformat.58.dylib
  22. +0 −1 deps/lib/libavformat.dylib
  23. BIN deps/lib/libavresample.4.0.0.dylib
  24. BIN deps/lib/libavresample.4.dylib
  25. BIN deps/lib/libavresample.4.dylib
  26. +0 −1 deps/lib/libavresample.dylib
  27. BIN deps/lib/libavutil.56.22.100.dylib
  28. BIN deps/lib/libavutil.56.dylib
  29. BIN deps/lib/libavutil.56.dylib
  30. +0 −1 deps/lib/libavutil.dylib
  31. BIN deps/lib/libbluray.2.dylib
  32. BIN deps/lib/libcrypto.1.0.0.dylib
  33. BIN deps/lib/libdvdcss.2.dylib
  34. BIN deps/lib/libdvdnav.4.dylib
  35. BIN deps/lib/libdvdread.4.dylib
  36. BIN deps/lib/libffi.6.dylib
  37. BIN deps/lib/libfontconfig.1.dylib
  38. BIN deps/lib/libfreetype.6.dylib
  39. BIN deps/lib/libfribidi.0.dylib
  40. BIN deps/lib/libgif.7.dylib
  41. BIN deps/lib/libglib-2.0.0.dylib
  42. BIN deps/lib/libgmp.10.dylib
  43. BIN deps/lib/libgnutls.30.dylib
  44. BIN deps/lib/libgraphite2.3.dylib
  45. BIN deps/lib/libharfbuzz.0.dylib
  46. BIN deps/lib/libhogweed.4.dylib
  47. BIN deps/lib/libintl.8.dylib
  48. BIN deps/lib/libjpeg.9.dylib
  49. BIN deps/lib/liblcms2.2.dylib
  50. BIN deps/lib/liblept.5.dylib
  51. BIN deps/lib/liblua.5.1.dylib
  52. BIN deps/lib/liblzma.5.dylib
  53. BIN deps/lib/libmp3lame.0.dylib
  54. +0 −1 deps/lib/libmpv.1.101.0.dylib
  55. BIN deps/lib/libmpv.1.dylib
  56. BIN deps/lib/libmpv.1.dylib
  57. BIN deps/lib/libmpv.dylib
  58. BIN deps/lib/libnettle.6.dylib
  59. BIN deps/lib/libogg.0.dylib
  60. BIN deps/lib/libopenjp2.7.dylib
  61. BIN deps/lib/libopus.0.dylib
  62. BIN deps/lib/libp11-kit.0.dylib
  63. BIN deps/lib/libpcre.1.dylib
  64. BIN deps/lib/libpng16.16.dylib
  65. BIN deps/lib/libpostproc.55.3.100.dylib
  66. BIN deps/lib/libpostproc.55.dylib
  67. BIN deps/lib/libpostproc.55.dylib
  68. +0 −1 deps/lib/libpostproc.dylib
  69. BIN deps/lib/librtmp.1.dylib
  70. BIN deps/lib/librubberband.2.dylib
  71. BIN deps/lib/libsnappy.1.dylib
  72. BIN deps/lib/libsoxr.0.dylib
  73. BIN deps/lib/libspeex.1.dylib
  74. BIN deps/lib/libssl.1.0.0.dylib
  75. BIN deps/lib/libswresample.3.3.100.dylib
  76. BIN deps/lib/libswresample.3.dylib
  77. BIN deps/lib/libswresample.3.dylib
  78. +0 −1 deps/lib/libswresample.dylib
  79. BIN deps/lib/libswscale.5.3.100.dylib
  80. BIN deps/lib/libswscale.5.dylib
  81. BIN deps/lib/libswscale.5.dylib
  82. +0 −1 deps/lib/libswscale.dylib
  83. BIN deps/lib/libtasn1.6.dylib
  84. BIN deps/lib/libtesseract.4.dylib
  85. BIN deps/lib/libtheoradec.1.dylib
  86. BIN deps/lib/libtheoraenc.1.dylib
  87. BIN deps/lib/libtiff.5.dylib
  88. BIN deps/lib/libuchardet.0.dylib
  89. BIN deps/lib/libunistring.2.dylib
  90. BIN deps/lib/libvorbis.0.dylib
  91. BIN deps/lib/libvorbisenc.2.dylib
  92. BIN deps/lib/libwebp.7.dylib
  93. +1 −1 iina-cli/main.swift
  94. +298 −242 iina.xcodeproj/project.pbxproj
  95. +1 −1 iina/AutoFileMatcher.swift
  96. +1 −1 iina/CacheManager.swift
  97. +15 −6 iina/Extensions.swift
  98. +3 −3 iina/FileGroup.swift
  99. +1 −1 iina/HistoryController.swift
  100. +1 −1 iina/KeyMapping.swift
  101. +4 −4 iina/MainWindowController.swift
  102. +4 −4 iina/OpenSubSubtitle.swift
  103. +1 −1 iina/PlayerCore.swift
  104. +1 −1 iina/PlaylistViewController.swift
  105. +2 −2 iina/PrefKeyBindingViewController.swift
  106. +1 −1 iina/PrefOSCToolbarSettingsSheetController.swift
  107. +1 −1 iina/PreferenceWindowController.swift
  108. +3 −3 iina/QuickSettingViewController.swift
  109. +16 −23 iina/ThumbnailCache.swift
  110. +4 −0 iina/Utility.swift
@@ -1,5 +1,5 @@
language: swift
osx_image: xcode10.1
osx_image: xcode10.2

before_install:
- gem install cocoapods
@@ -5,10 +5,10 @@ target 'iina' do
use_frameworks!

# Pods for iina
pod 'Just', :git => 'https://github.com/JustHTTP/Just.git'
pod 'Just', :git => 'https://github.com/iina/Just', :branch => 'swift-5'
pod 'PromiseKit'
pod 'GzipSwift'
pod 'GRMustache.swift', :git => 'https://github.com/iina/GRMustache.swift.git'
pod 'GRMustache.swift', :git => 'https://github.com/iina/GRMustache.swift'
pod 'Sparkle'

# target 'iinaTests' do
@@ -9,12 +9,12 @@ PODS:
- PromiseKit/CorePromise (6.8.3)
- PromiseKit/Foundation (6.8.3):
- PromiseKit/CorePromise
- Sparkle (1.21.2)
- Sparkle (1.21.3)

DEPENDENCIES:
- GRMustache.swift (from `https://github.com/iina/GRMustache.swift.git`)
- GRMustache.swift (from `https://github.com/iina/GRMustache.swift`)
- GzipSwift
- Just (from `https://github.com/JustHTTP/Just.git`)
- Just (from `https://github.com/iina/Just`, branch `swift-5`)
- PromiseKit
- Sparkle

@@ -26,25 +26,26 @@ SPEC REPOS:

EXTERNAL SOURCES:
GRMustache.swift:
:git: https://github.com/iina/GRMustache.swift.git
:git: https://github.com/iina/GRMustache.swift
Just:
:git: https://github.com/JustHTTP/Just.git
:branch: swift-5
:git: https://github.com/iina/Just

CHECKOUT OPTIONS:
GRMustache.swift:
:commit: 3e6778e4b8a134e3f96d04d6c15c7213bd7d9935
:git: https://github.com/iina/GRMustache.swift.git
:commit: a46e65d00b4753449b90465be813bbdb1a9ffc9d
:git: https://github.com/iina/GRMustache.swift
Just:
:commit: b314be4ac8652b66182cfbd4a9893dfcb3808bbf
:git: https://github.com/JustHTTP/Just.git
:commit: d0ae3f9bc2d6bf247b19217764a096bbac55f007
:git: https://github.com/iina/Just

SPEC CHECKSUMS:
GRMustache.swift: 53405b02c374520f9193cf41bfa677f03a6d70aa
GzipSwift: df1636fa095bd8f21d98db14e7393ecc9e230fed
Just: 60c0995e04718eb621a07abef45ce6883c562f2b
PromiseKit: 94c6e781838c5bf4717677d0d882b0e7250c80fc
Sparkle: 1678d4707e7665960c7d1b43aca125e6392d11c4
Sparkle: 3f75576db8b0265adef36c43249d747f22d0b708

PODFILE CHECKSUM: c149e2f5a370325310fa22313fe8c514d0967750
PODFILE CHECKSUM: 4969f0d73fe5d871a1a1853ad7807a345443e71a

COCOAPODS: 1.6.1
Binary file not shown.
BIN -760 Bytes (100%) deps/lib/libarchive.13.dylib
Binary file not shown.
BIN -4.06 KB (98%) deps/lib/libass.9.dylib
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

BIN +4.16 KB (100%) deps/lib/libbluray.2.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +40 Bytes (100%) deps/lib/libfontconfig.1.dylib
Binary file not shown.
BIN +5.04 KB (100%) deps/lib/libfreetype.6.dylib
Binary file not shown.
BIN -8 Bytes (100%) deps/lib/libfribidi.0.dylib
Binary file not shown.
Binary file not shown.
BIN +322 KB (130%) deps/lib/libglib-2.0.0.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +0 Bytes (100%) deps/lib/libgraphite2.3.dylib
Binary file not shown.
BIN +111 KB (110%) deps/lib/libharfbuzz.0.dylib
Binary file not shown.
Binary file not shown.
BIN +0 Bytes (100%) deps/lib/libintl.8.dylib
Binary file not shown.
BIN +3.55 KB (100%) deps/lib/libjpeg.9.dylib
Binary file not shown.
BIN -168 Bytes (100%) deps/lib/liblcms2.2.dylib
Binary file not shown.
Binary file not shown.
BIN -88 Bytes (100%) deps/lib/liblua.5.1.dylib
Binary file not shown.
BIN +0 Bytes (100%) deps/lib/liblzma.5.dylib
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.
BIN -4.06 MB deps/lib/libmpv.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN -3.87 KB (99%) deps/lib/libpcre.1.dylib
Binary file not shown.
BIN +3.92 KB (100%) deps/lib/libpng16.16.dylib
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
BIN -8 Bytes (100%) deps/lib/libsnappy.1.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN -4.34 KB (97%) deps/lib/libuchardet.0.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -90,7 +90,7 @@ if (!userSpecifiedStdin) {
isStdin = stdin.hasBytesAvailable
}

if let dashIndex = userArgs.index(of: "--") {
if let dashIndex = userArgs.firstIndex(of: "--") {
userArgs.remove(at: dashIndex)
for i in dashIndex..<userArgs.count {
let arg = userArgs[i]

Large diffs are not rendered by default.

@@ -263,7 +263,7 @@ class AutoFileMatcher {
}
try matchedSubs
.filter { $0.priorityStringOccurances > minOccurances } // eliminate false positives in filenames
.compactMap { player.info.matchedSubs[video.path]!.index(of: $0.url) } // get index
.compactMap { player.info.matchedSubs[video.path]!.firstIndex(of: $0.url) } // get index
.forEach { // move the sub with index to first
try checkTicket()
Logger.log("Move \(player.info.matchedSubs[video.path]![$0]) to front", level: .verbose, subsystem: subsystem)
@@ -45,7 +45,7 @@ class CacheManager {
guard let contents = cacheFolderContents()?.sorted(by: { url1, url2 in
let date1 = (try? url1.resourceValues(forKeys: [.contentAccessDateKey]).contentAccessDate) ?? Date.distantPast
let date2 = (try? url2.resourceValues(forKeys: [.contentAccessDateKey]).contentAccessDate) ?? Date.distantPast
return date1!.compare(date2!) == .orderedAscending
return date1.compare(date2) == .orderedAscending
}) else { return }

// delete old cache
@@ -350,15 +350,16 @@ extension Data {
}

var chksum64: UInt64 {
get {
let count64 = self.count / MemoryLayout<UInt64>.size
return self.withUnsafeBytes{ (ptr: UnsafePointer<UInt64>) -> UInt64 in
let bufferPtr = UnsafeBufferPointer(start: ptr, count: count64)
return bufferPtr.reduce(UInt64(0), &+)
}
return withUnsafeBytes {
$0.bindMemory(to: UInt64.self).reduce(0, &+)
}
}

init<T>(bytesOf thing: T) {
var copyOfThing = thing // Hopefully CoW?
self.init(bytes: &copyOfThing, count: MemoryLayout.size(ofValue: thing))
}

func saveToFolder(_ url: URL, filename: String) -> URL? {
let fileUrl = url.appendingPathComponent(filename)
do {
@@ -371,6 +372,14 @@ extension Data {
}
}

extension FileHandle {
func read<T>(type: T.Type /* To prevent unintended specializations */) -> T {
return readData(ofLength: MemoryLayout<T>.size).withUnsafeBytes {
$0.bindMemory(to: T.self).first!
}
}
}

extension String {
var md5: String {
get {
@@ -65,10 +65,10 @@ class FileInfo: Hashable {
self.nameInSeries = String(name)
}

var hashValue: Int {
return path.hashValue
func hash(into hasher: inout Hasher) {
hasher.combine(path)
}

static func == (lhs: FileInfo, rhs: FileInfo) -> Bool {
return lhs.path == rhs.path
}
@@ -36,7 +36,7 @@ class HistoryController: NSObject {

func add(_ url: URL, duration: Double) {
guard Preference.bool(for: .recordPlaybackHistory) else { return }
if let existingItem = history.first(where: { $0.mpvMd5 == url.path.md5 }), let index = history.index(of: existingItem) {
if let existingItem = history.first(where: { $0.mpvMd5 == url.path.md5 }), let index = history.firstIndex(of: existingItem) {
history.remove(at: index)
}
history.insert(PlaybackHistory(url: url, duration: duration), at: 0)
@@ -124,7 +124,7 @@ class KeyMapping: NSObject {
continue
}
// remove inline comment
if let sharpIndex = line.index(of: "#") {
if let sharpIndex = line.firstIndex(of: "#") {
line = String(line[...line.index(before: sharpIndex)])
}
// split
@@ -674,7 +674,7 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
pipOverlayView.isHidden = true
rightLabel.mode = Preference.bool(for: .showRemainingTime) ? .remaining : .duration

osdProgressBarWidthConstraint = NSLayoutConstraint(item: osdAccessoryProgress, attribute: .width, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 150)
osdProgressBarWidthConstraint = NSLayoutConstraint(item: osdAccessoryProgress as Any, attribute: .width, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 150)

// add user default observers
observedPrefKeys.forEach { key in
@@ -865,7 +865,7 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
fragControlViewMiddleButtons1Constraint.constant = 24
fragControlViewMiddleButtons2Constraint.constant = 24
oscFloatingLeadingTrailingConstraint = NSLayoutConstraint.constraints(withVisualFormat: "H:|-(>=10)-[v]-(>=10)-|",
options: [], metrics: nil, views: ["v": controlBarFloating])
options: [], metrics: nil, views: ["v": controlBarFloating as Any])
NSLayoutConstraint.activate(oscFloatingLeadingTrailingConstraint!)
} else {
fragControlViewMiddleButtons1Constraint.constant = 16
@@ -1424,7 +1424,7 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
additionalInfoView.isHidden = true
isMouseInSlider = false

if let index = fadeableViews.index(of: additionalInfoView) {
if let index = fadeableViews.firstIndex(of: additionalInfoView) {
fadeableViews.remove(at: index)
}

@@ -1908,7 +1908,7 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
}

private func removeTitlebarViewFromFadeableViews() {
if let index = (self.fadeableViews.index { $0 === titleBarView }) {
if let index = (self.fadeableViews.firstIndex { $0 === titleBarView }) {
self.fadeableViews.remove(at: index)
}
}
@@ -228,7 +228,7 @@ class OpenSubSupport {
func requestIMDB(_ fileURL: URL) -> Promise<String> {
return Promise { resolver in
let filename = fileURL.lastPathComponent
xmlRpc.call("GuessMovieFromString", [token, [filename]]) { status in
xmlRpc.call("GuessMovieFromString", [token as Any, [filename]]) { status in
switch status {
case .ok(let response):
do {
@@ -254,7 +254,7 @@ class OpenSubSupport {
let limit = 100
var requestInfo = info
requestInfo["sublanguageid"] = self.language
xmlRpc.call("SearchSubtitles", [token, [requestInfo], ["limit": limit]]) { status in
xmlRpc.call("SearchSubtitles", [token as Any, [requestInfo], ["limit": limit]]) { status in
switch status {
case .ok(let response):
guard self.checkStatus(response) else { resolver.reject(OpenSubError.wrongResponseFormat); return }
@@ -263,7 +263,7 @@ class OpenSubSupport {
return
}
var result: [OpenSubSubtitle] = []
for (index, subData) in pData!.enumerated() {
for (index, subData) in pData.enumerated() {
let sub = OpenSubSubtitle(index: index,
filename: subData["SubFileName"] as! String,
langID: subData["SubLanguageID"] as! String,
@@ -317,7 +317,7 @@ class OpenSubSupport {
}

@objc private func sendHeartbeat() {
xmlRpc.call("NoOperation", [token]) { result in
xmlRpc.call("NoOperation", [token as Any]) { result in
switch result {
case .ok(let value):
// 406 No session
@@ -622,7 +622,7 @@ class PlayerCore: NSObject {
}

func setVideoRotate(_ degree: Int) {
if AppData.rotations.index(of: degree)! >= 0 {
if AppData.rotations.firstIndex(of: degree)! >= 0 {
mpv.setInt(MPVOption.Video.videoRotate, degree)
info.rotation = degree
}
@@ -807,7 +807,7 @@ class SubPopoverViewController: NSViewController, NSTableViewDelegate, NSTableVi
@IBAction func wrongSubBtnAction(_ sender: AnyObject) {
player.info.matchedSubs[filePath]?.removeAll()
tableView.reloadData()
if let row = player.info.playlist.index(where: { $0.filename == filePath }) {
if let row = player.info.playlist.firstIndex(where: { $0.filename == filePath }) {
playlistTableView.reloadData(forRowIndexes: IndexSet(integer: row), columnIndexes: IndexSet(integersIn: 0...1))
}
}
@@ -108,7 +108,7 @@ class PrefKeyBindingViewController: NSViewController, PreferenceWindowEmbeddable
}

private func confTableSelectRow(withTitle title: String) {
if let index = userConfigNames.index(of: title) {
if let index = userConfigNames.firstIndex(of: title) {
confTableView.selectRowIndexes(IndexSet(integer: index), byExtendingSelection: false)
}
}
@@ -266,7 +266,7 @@ class PrefKeyBindingViewController: NSViewController, PreferenceWindowEmbeddable
userConfigs.removeValue(forKey: currentConfName)
Preference.set(userConfigs, for: Preference.Key.inputConfigs)
// load
if let index = userConfigNames.index(of: currentConfName) {
if let index = userConfigNames.firstIndex(of: currentConfName) {
userConfigNames.remove(at: index)
}
confTableView.reloadData()
@@ -156,7 +156,7 @@ class PrefOSCToolbarCurrentItemsView: NSStackView, NSDraggingSource {
func draggingSession(_ session: NSDraggingSession, willBeginAt screenPoint: NSPoint) {
if let itemBeingDragged = itemBeingDragged {
// remove the dragged view and insert a placeholder at its position.
let index = views.index(of: itemBeingDragged)!
let index = views.firstIndex(of: itemBeingDragged)!
removeView(itemBeingDragged)
Utility.quickConstraints(["H:[v(24)]", "V:[v(24)]"], ["v": placeholderView])
insertView(placeholderView, at: index, in: .trailing)
@@ -287,7 +287,7 @@ class PreferenceWindowController: NSWindowController {
}
let title = (sectionTitleLabel as! NSTextField).stringValue
var labels = findLabels(in: section)
labels.remove(at: labels.index(of: title)!)
labels.remove(at: labels.firstIndex(of: title)!)
return (title, labels)
}

@@ -177,17 +177,17 @@ class QuickSettingViewController: NSViewController, NSTableViewDataSource, NSTab
}

private func updateVideoTabControl() {
if let index = AppData.aspectsInPanel.index(of: player.info.unsureAspect) {
if let index = AppData.aspectsInPanel.firstIndex(of: player.info.unsureAspect) {
aspectSegment.selectedSegment = index
} else {
aspectSegment.selectedSegment = -1
}
if let index = AppData.cropsInPanel.index(of: player.info.unsureCrop) {
if let index = AppData.cropsInPanel.firstIndex(of: player.info.unsureCrop) {
cropSegment.selectedSegment = index
} else {
cropSegment.selectedSegment = -1
}
rotateSegment.selectSegment(withTag: AppData.rotations.index(of: player.info.rotation) ?? -1)
rotateSegment.selectSegment(withTag: AppData.rotations.firstIndex(of: player.info.rotation) ?? -1)