native popups

This commit is contained in:
eevee
2024-04-26 00:51:32 +03:00
parent e9bd4e4e53
commit acfee7a357
6 changed files with 66 additions and 31 deletions

View File

@@ -0,0 +1,39 @@
import UIKit
import Orion
import Foundation
class PopUpHelper {
static let sharedPresenter = type(
of: Dynamic.SPTEncorePopUpPresenter
.alloc(interface: SPTEncorePopUpPresenter.self)
)
.shared()
static func showPopUp(
message: String,
buttonText: String
) {
let model = Dynamic.SPTEncorePopUpDialogModel
.alloc(interface: SPTEncorePopUpDialogModel.self)
.initWithTitle(
"EeveeSpotify",
description: message,
image: nil,
primaryButtonTitle: buttonText,
secondaryButtonTitle: nil
)
let dialog = Dynamic.SPTEncorePopUpDialog
.alloc(interface: SPTEncorePopUpDialog.self)
.`init`()
dialog.update(model)
dialog.setEventHandler({
sharedPresenter.dismissPopupWithAnimate(true, clearQueue: false, completion: nil)
})
sharedPresenter.presentPopUp(dialog)
}
}

View File

@@ -1,29 +0,0 @@
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 presentViewController(_ viewController: UIViewController) {
rootViewController.present(viewController, animated: true)
}
func showPopup(message: String, buttonText: String) {
let alert = UIAlertController(title: "EeveeSpotify", message: message, preferredStyle: .alert)
alert.overrideUserInterfaceStyle = .dark
alert.addAction(UIAlertAction(title: buttonText, style: .default))
presentViewController(alert)
}
}

View File

@@ -0,0 +1,7 @@
import Foundation
@objc protocol SPTEncorePopUpDialog {
func `init`() -> SPTEncorePopUpDialog
func update(_ popUpModel: SPTEncorePopUpDialogModel)
func setEventHandler(_ handler: @escaping () -> Void)
}

View File

@@ -0,0 +1,11 @@
import Foundation
@objc protocol SPTEncorePopUpDialogModel {
func initWithTitle(
_ title: String,
description: String,
image: Any?,
primaryButtonTitle: String,
secondaryButtonTitle: String?
) -> SPTEncorePopUpDialogModel
}

View File

@@ -0,0 +1,7 @@
import Foundation
@objc protocol SPTEncorePopUpPresenter {
static func shared() -> SPTEncorePopUpPresenter
func presentPopUp(_ popUp: SPTEncorePopUpDialog)
func dismissPopupWithAnimate(_ animate: Bool, clearQueue: Bool, completion: Any?)
}

View File

@@ -38,7 +38,7 @@ struct EeveeSpotify: Tweak {
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
WindowHelper.shared.showPopup(
PopUpHelper.showPopUp(
message: "Please log in and restart the app to get Premium.",
buttonText: "Okay!"
)
@@ -66,7 +66,7 @@ struct EeveeSpotify: Tweak {
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
WindowHelper.shared.showPopup(
PopUpHelper.showPopUp(
message: "Unable to apply tweak: \(error)",
buttonText: "OK"
)