From 3a62a7ac8faef73ddf67fa51948b6acda3638669 Mon Sep 17 00:00:00 2001 From: eevee Date: Mon, 22 Apr 2024 21:00:13 +0300 Subject: [PATCH] popups and reapplying --- .../{ => Helpers}/BundleHelper.swift | 0 .../EeveeSpotify/Helpers/WindowHelper.swift | 29 +++++++++++++++++++ Sources/EeveeSpotify/Tweak.x.swift | 24 +++++++++++++++ 3 files changed, 53 insertions(+) rename Sources/EeveeSpotify/{ => Helpers}/BundleHelper.swift (100%) create mode 100644 Sources/EeveeSpotify/Helpers/WindowHelper.swift diff --git a/Sources/EeveeSpotify/BundleHelper.swift b/Sources/EeveeSpotify/Helpers/BundleHelper.swift similarity index 100% rename from Sources/EeveeSpotify/BundleHelper.swift rename to Sources/EeveeSpotify/Helpers/BundleHelper.swift diff --git a/Sources/EeveeSpotify/Helpers/WindowHelper.swift b/Sources/EeveeSpotify/Helpers/WindowHelper.swift new file mode 100644 index 0000000..60f8163 --- /dev/null +++ b/Sources/EeveeSpotify/Helpers/WindowHelper.swift @@ -0,0 +1,29 @@ +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) + } +} diff --git a/Sources/EeveeSpotify/Tweak.x.swift b/Sources/EeveeSpotify/Tweak.x.swift index fdcbb6b..2ddf895 100644 --- a/Sources/EeveeSpotify/Tweak.x.swift +++ b/Sources/EeveeSpotify/Tweak.x.swift @@ -34,6 +34,20 @@ struct EeveeSpotify: Tweak { .appendingPathComponent("PersistentCache") .appendingPathComponent("offline.bnk") + if !FileManager.default.fileExists(atPath: filePath.path) { + + DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { + + WindowHelper.shared.showPopup( + message: "Please log in and restart the app to get Premium.", + buttonText: "Okay!" + ) + } + + NSLog("[EeveeSpotify] Not activating due to nonexistent file: \(filePath)") + return + } + let fileData = try Data(contentsOf: filePath) let usernameLength = Int(fileData[8]) @@ -46,6 +60,16 @@ struct EeveeSpotify: Tweak { try blankData.write(to: filePath) NSLog("[EeveeSpotify] Successfully applied") + + Timer.scheduledTimer(withTimeInterval: 20, repeats: true) { _ in + do { + try blankData.write(to: filePath) + NSLog("[EeveeSpotify] Successfully reapplied") + } + catch { + NSLog("[EeveeSpotify] Unable to reapply (write data): \(error)") + } + } } catch {