Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xjbeta committed Aug 9, 2023
2 parents 07fba0c + adf111f commit 0c826ab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions IINA+.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.7.4;
MARKETING_VERSION = 0.7.5;
PRODUCT_BUNDLE_IDENTIFIER = "com.xjbeta.iina-plus";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1020,7 +1020,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.7.4;
MARKETING_VERSION = 0.7.5;
PRODUCT_BUNDLE_IDENTIFIER = "com.xjbeta.iina-plus";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
6 changes: 5 additions & 1 deletion IINA+/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ class Preferences: NSObject {
return defaults(.kuaiShouCookiesDate) as? Date
}
set {
defaultsSet(newValue, forKey: .kuaiShouCookiesDate)
if let v = newValue {
defaultsSet(v, forKey: .kuaiShouCookiesDate)
} else {
prefs.removeObject(forKey: PreferenceKeys.kuaiShouCookiesDate.rawValue)
}
}
}

Expand Down
39 changes: 24 additions & 15 deletions IINA+/Utils/VideoDecoder/DouYin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,28 @@ class DouYin: NSObject, SupportSiteProtocol {
storageDic.removeAll()
deleteDouYinCookies()

var dyFinished = false

enum DYState {
case none
case checking
case finish
}

var state = DYState.none

return Promise { resolver in
dyFinishNitification = NotificationCenter.default.addObserver(forName: .finishLoadDY, object: nil, queue: .main) { _ in
guard !dyFinished else { return }
Log("Douyin dyFinished")
dyFinished = true
dyFinishNitification = NotificationCenter.default.addObserver(forName: .douyinWebcastUpdated, object: nil, queue: .main) { _ in
guard state == .none else { return }
state = .checking

if let n = self.dyFinishNitification {
NotificationCenter.default.removeObserver(n)
}

self.loadCookies().done {
state = .finish
resolver.fulfill_()
}.catch {
state = .none
resolver.reject($0)
}
}
Expand All @@ -142,7 +149,8 @@ class DouYin: NSObject, SupportSiteProtocol {
self.webViewLoadingObserver = nil

DispatchQueue.main.asyncAfter(deadline: .now() + 60) { [weak self] in
guard let self = self, !dyFinished else { return }
guard let self = self,
state != .finish else { return }

Log("DouYin Cookies timeout, Reload.")
self.webView?.load(.init(url: self.douyinEmptyURL))
Expand Down Expand Up @@ -170,12 +178,9 @@ class DouYin: NSObject, SupportSiteProtocol {
let selector = Selector(("registerSchemeForCustomProtocol:"))

if contextController.responds(to: selector) {
_ = contextController.perform(selector, with: "http")
_ = contextController.perform(selector, with: "wss")
}

if contextController.responds(to: selector) {
_ = contextController.perform(selector, with: "https")
}
URLProtocol.registerClass(DouYinURLProtocol.self)
}

Expand Down Expand Up @@ -216,13 +221,17 @@ class DouYin: NSObject, SupportSiteProtocol {
self.privateKeys[0].base64Decode(): values[0],
self.privateKeys[1].base64Decode(): values[1]
]
}.done {
}.get {
self.storageDic = $0
}.then { _ in
self.getContent(self.douyinEmptyURL.absoluteString)
}.done { info in
Log("Douyin test info \(info.title)")
Log("Douyin deinit webview")

self.webView?.stopLoading()
self.webView?.removeFromSuperview()
self.webView = nil
self.storageDic = $0
}
}

Expand Down Expand Up @@ -332,8 +341,8 @@ struct DouYinInfo: Unmarshaling, LiveInfo {
class DouYinURLProtocol: URLProtocol, URLSessionDelegate {
override class func canInit(with request: URLRequest) -> Bool {
if let str = request.url?.absoluteString,
str.starts(with: "https://mssdk.bytedance.com/websdk/v1/getInfo") {
NotificationCenter.default.post(name: .finishLoadDY, object: nil)
str.contains("webcast/im/push/v2") {
NotificationCenter.default.post(name: .douyinWebcastUpdated, object: nil)
}
return false
}
Expand Down
4 changes: 2 additions & 2 deletions IINA+/Views/Identifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ extension Notification.Name {
static let updateDanmukuFont = Notification.Name("com.xjbeta.iina+.DanmakuWindow.FontChanged")
static let loadDanmaku = Notification.Name("com.xjbeta.iina+.LoadDanmaku")

static let startLoadDY = Notification.Name("com.xjbeta.iina+.douyin.StartLoad")
static let finishLoadDY = Notification.Name("com.xjbeta.iina+.douyin.FinishLoad")

static let douyinWebcastUpdated = Notification.Name("com.xjbeta.iina+.douyin.WebcastUpdated")
}

0 comments on commit 0c826ab

Please sign in to comment.