Skip to content

Commit

Permalink
popups about server-sided features
Browse files Browse the repository at this point in the history
  • Loading branch information
whoeevee committed Apr 26, 2024
1 parent a330623 commit d942b46
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/EeveeSpotify/Helpers/PopUpHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Orion
import Foundation

class PopUpHelper {

private static var isPopUpShowing = false

static let sharedPresenter = type(
of: Dynamic.SPTEncorePopUpPresenter
Expand All @@ -15,6 +17,10 @@ class PopUpHelper {
buttonText: String
) {

if isPopUpShowing {
return
}

let model = Dynamic.SPTEncorePopUpDialogModel
.alloc(interface: SPTEncorePopUpDialogModel.self)
.initWithTitle(
Expand All @@ -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()
}
}
26 changes: 26 additions & 0 deletions Sources/EeveeSpotify/Helpers/WindowHelper.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
10 changes: 10 additions & 0 deletions Sources/EeveeSpotify/Models/Extensions/String+Extension.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
59 changes: 59 additions & 0 deletions Sources/EeveeSpotify/ServerSidedReminder.x.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit d942b46

Please sign in to comment.