Skip to content
Permalink
Browse files

Update to Swift 5

  • Loading branch information...
saagarjha committed Jan 31, 2019
1 parent 6ea359c commit f0bcd1208a65f1d6cfff06415679c984a9dd5681
@@ -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
@@ -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]
@@ -2036,17 +2036,18 @@
TargetAttributes = {
49542972216C34950058F680 = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
};
84EB1ED51D2F51D3004FA5A1 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 67CQ77V27R;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
E3DE8DC91FD8166A0021921C = {
CreatedOnToolsVersion = 9.1;
DevelopmentTeam = 67CQ77V27R;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
};
};
@@ -2056,6 +2057,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
Base,
en,
"zh-Hans",
@@ -3211,7 +3213,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -3236,7 +3238,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
@@ -3385,7 +3387,7 @@
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "iina/iina-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -3423,7 +3425,7 @@
SKIP_INSTALL = NO;
SWIFT_OBJC_BRIDGING_HEADER = "iina/iina-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
@@ -3445,7 +3447,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES;
SWIFT_FORCE_STATIC_LINK_STDLIB = NO;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -3467,7 +3469,7 @@
SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES;
SWIFT_FORCE_STATIC_LINK_STDLIB = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
@@ -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)
}

@@ -1907,7 +1907,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)
deinterlaceCheckBtn.state = player.info.deinterlace ? .on : .off
let speed = player.mpv.getDouble(MPVOption.PlaybackControl.speed)
customSpeedTextField.doubleValue = speed

0 comments on commit f0bcd12

Please sign in to comment.
You can’t perform that action at this time.