popups about server-sided features

This commit is contained in:
eevee
2024-04-26 23:58:28 +03:00
parent a330623a06
commit d942b4630c
4 changed files with 103 additions and 0 deletions

View File

@@ -3,6 +3,8 @@ import Orion
import Foundation
class PopUpHelper {
private static var isPopUpShowing = false
static let sharedPresenter = type(
of: Dynamic.SPTEncorePopUpPresenter
@@ -15,6 +17,10 @@ class PopUpHelper {
buttonText: String
) {
if isPopUpShowing {
return
}
let model = Dynamic.SPTEncorePopUpDialogModel
.alloc(interface: SPTEncorePopUpDialogModel.self)
.initWithTitle(
@@ -32,8 +38,10 @@ class PopUpHelper {
dialog.update(model)
dialog.setEventHandler({
sharedPresenter.dismissPopupWithAnimate(true, clearQueue: false, completion: nil)
isPopUpShowing.toggle()
})
sharedPresenter.presentPopUp(dialog)
isPopUpShowing.toggle()
}
}

View File

@@ -0,0 +1,26 @@
import UIKit
import Foundation
class WindowHelper {
static let shared = WindowHelper()
let window: UIWindow
let rootViewController: UIViewController
private init() {
self.window = UIApplication.shared.windows.first!
self.rootViewController = window.rootViewController!
}
func viewController(for view: UIView) -> UIViewController? {
var responder: UIResponder? = view
while let nextResponder = responder?.next {
if let viewController = nextResponder as? UIViewController {
return viewController
}
responder = nextResponder
}
return nil
}
}

View File

@@ -0,0 +1,10 @@
import Foundation
extension String {
static func ~= (lhs: String, rhs: String) -> Bool {
guard let regex = try? NSRegularExpression(pattern: rhs) else { return false }
let range = NSRange(location: 0, length: lhs.utf16.count)
return regex.firstMatch(in: lhs, options: [], range: range) != nil
}
}

View File

@@ -0,0 +1,59 @@
import Orion
import UIKit
class StreamQualitySettingsSectionHook: ClassHook<NSObject> {
static let targetName = "StreamQualitySettingsSection"
func shouldResetSelection() -> Bool {
PopUpHelper.showPopUp(
message: "Very high audio quality is server-sided and is not available with this tweak.",
buttonText: "OK"
)
return true
}
}
//
func showOfflineModePopUp() {
PopUpHelper.showPopUp(
message: "Native playlist downloading is server-sided and is not available with this tweak. You can download podcast episodes though.",
buttonText: "OK"
)
}
class FTPDownloadActionHook: ClassHook<NSObject> {
static let targetName = "ListUXPlatform_FreeTierPlaylistImpl.FTPDownloadAction"
func execute(_ idk: Any) {
showOfflineModePopUp()
}
}
class UIButtonHook: ClassHook<UIButton> {
func setHighlighted(_ highlighted: Bool) {
if highlighted {
if let identifier = target.accessibilityIdentifier, identifier.contains("DownloadButton") {
let vcDescription = String(describing: WindowHelper.shared.viewController(for: target))
if !(vcDescription ~= "Podcast|CreativeWorkPlatform") {
target.removeTarget(nil, action: nil, for: .allEvents)
showOfflineModePopUp()
return
}
}
}
orig.setHighlighted(highlighted)
}
}