Skip to content

Commit

Permalink
Paid tweak support
Browse files Browse the repository at this point in the history
closes #13
  • Loading branch information
Lrdsnow committed Jun 21, 2024
1 parent 8032295 commit d2bbd9a
Show file tree
Hide file tree
Showing 22 changed files with 829 additions and 721 deletions.
22 changes: 6 additions & 16 deletions PurePKG.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion PurePKG/Extentions/Compat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ private struct FallbackSheetPresenter<Content: View>: UIViewControllerRepresenta
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
log("update")
if isPresented && uiViewController.presentedViewController == nil {
let hostingController = UIHostingController(rootView: content())
hostingController.modalPresentationStyle = .pageSheet
Expand Down
2 changes: 2 additions & 0 deletions PurePKG/Extentions/ListRowExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ extension View {
self
#elseif os(watchOS)
self.listRowBackground(Color.accentColor.opacity(0.05).cornerRadius(8))
#elseif os(tvOS)
self.listRowBackground(Color.accentColor.opacity(0.05).cornerRadius(10))
#else
self.listRowBackground(Color.accentColor.opacity(0.05))
#endif
Expand Down
110 changes: 108 additions & 2 deletions PurePKG/Extentions/Popups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import Foundation
#if os(watchOS)
import WatchKit

enum dummy_kbT {
case URL
case asciiCapable
}

func showPopup(_ title: String, _ message: String) {
let action = WKAlertAction(title: "OK", style: .default) {}
if let controller = WKApplication.shared().rootInterfaceController {
Expand All @@ -30,7 +35,7 @@ func showConfirmPopup(_ title: String, _ message: String, completion: @escaping
}
}

func showTextInputPopup(_ title: String, _ placeholderText: String, completion: @escaping (String?) -> Void) {
func showTextInputPopup(_ title: String, _ placeholderText: String, _ keyboardType: dummy_kbT, completion: @escaping (String?) -> Void) {
if let controller = WKApplication.shared().rootInterfaceController {
controller.presentTextInputController(withSuggestions: [], allowedInputMode: .plain) { (results) in
if let result = results?.first as? String {
Expand All @@ -41,6 +46,36 @@ func showTextInputPopup(_ title: String, _ placeholderText: String, completion:
}
}
}

func showDoubleTextInputPopup(_ title: String, _ placeholderText1: String, _ placeholderText2: String, _ keyboardType: dummy_kbT, completion: @escaping ((String?, String?)) -> Void) {
if let controller = WKApplication.shared().rootInterfaceController {
let okAction1 = WKAlertAction(title: "OK", style: .default) {
controller.presentTextInputController(withSuggestions: nil, allowedInputMode: .plain) { result1 in
if let text1 = result1?.first as? String {
let okAction2 = WKAlertAction(title: "OK", style: .default) {
controller.presentTextInputController(withSuggestions: nil, allowedInputMode: .plain) { result2 in
if let text2 = result2?.first as? String {
completion((text1, text2))
} else {
completion((text1, nil))
}
}
}
let cancelAction2 = WKAlertAction(title: "Cancel", style: .cancel) {
completion((text1, nil))
}
controller.presentAlert(withTitle: placeholderText2, message: nil, preferredStyle: .alert, actions: [okAction2, cancelAction2])
} else {
completion((nil, nil))
}
}
}
let cancelAction1 = WKAlertAction(title: "Cancel", style: .cancel) {
completion((nil, nil))
}
controller.presentAlert(withTitle: placeholderText1, message: nil, preferredStyle: .alert, actions: [okAction1, cancelAction1])
}
}
#elseif !os(macOS)
import UIKit
import SwiftUI
Expand Down Expand Up @@ -101,6 +136,39 @@ func showTextInputPopup(_ title: String, _ placeholderText: String, _ keyboardTy
}
}

func showDoubleTextInputPopup(_ title: String, _ placeholderText1: String, _ placeholderText2: String, _ keyboardType: UIKeyboardType, completion: @escaping ((String?, String?)) -> Void) {
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .alert)

alertController.addTextField { (textField) in
textField.placeholder = placeholderText1
textField.keyboardType = keyboardType
}

alertController.addTextField { (textField) in
textField.placeholder = placeholderText2
textField.keyboardType = keyboardType
}

let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (_) in
completion((nil, nil))
}
alertController.addAction(cancelAction)

let okAction = UIAlertAction(title: "OK", style: .default) { (_) in
if let text = alertController.textFields?[0].text,
let text2 = alertController.textFields?[1].text {
completion((text, text2))
} else {
completion((nil, nil))
}
}
alertController.addAction(okAction)

if let topViewController = UIApplication.shared.windows.first?.rootViewController {
topViewController.present(alertController, animated: true, completion: nil)
}
}

#if os(iOS)
struct ImagePicker: UIViewControllerRepresentable {
@Binding var image: UIImage?
Expand Down Expand Up @@ -164,7 +232,12 @@ func showConfirmPopup(_ title: String, _ message: String, completion: @escaping
}
}

func showTextInputPopup(_ title: String, _ placeholderText: String, _ keyboardType: NSAlert.Style, completion: @escaping (String?) -> Void) {
enum dummy_kbT {
case URL
case asciiCapable
}

func showTextInputPopup(_ title: String, _ placeholderText: String, _ keyboardType: dummy_kbT, completion: @escaping (String?) -> Void) {
let alertController = NSAlert()
alertController.messageText = title

Expand All @@ -185,4 +258,37 @@ func showTextInputPopup(_ title: String, _ placeholderText: String, _ keyboardTy
completion(textField.stringValue)
}
}

func showDoubleTextInputPopup(_ title: String, _ placeholderText1: String, _ placeholderText2: String, _ keyboardType: dummy_kbT, completion: @escaping ((String?, String?)) -> Void) {
let alertController = NSAlert()
alertController.messageText = title

let textField1 = NSTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24))
textField1.placeholderString = placeholderText1
textField1.isEditable = true
textField1.stringValue = ""

let textField2 = NSTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24))
textField2.placeholderString = placeholderText2
textField2.isEditable = true
textField2.stringValue = ""

let stackView = NSStackView(frame: NSRect(x: 0, y: 0, width: 200, height: 90))
stackView.orientation = .vertical
stackView.addView(textField1, in: .center)
stackView.addView(textField2, in: .center)

alertController.accessoryView = stackView

alertController.addButton(withTitle: "Cancel")
alertController.addButton(withTitle: "OK")

let response = alertController.runModal()

if response == .alertFirstButtonReturn {
completion((nil, nil))
} else if response == .alertSecondButtonReturn {
completion((textField1.stringValue, textField2.stringValue))
}
}
#endif
16 changes: 14 additions & 2 deletions PurePKG/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import SwiftUI
@main
struct PurePKGBinary {
static func main() {
// payment api stuff
if CommandLine.arguments.count >= 2,
(CommandLine.arguments[1] == "getToken" || CommandLine.arguments[1] == "roothelper") {
exit(RootHelperMain());
}
//

log(getuid())

if (getuid() != 0) {
if #available(iOS 14.0, tvOS 14.0, *) {
PurePKGApp.main();
Expand All @@ -23,7 +32,6 @@ struct PurePKGBinary {
} else {
exit(RootHelperMain());
}

}
}

Expand Down Expand Up @@ -103,6 +111,10 @@ struct PurePKGApp: App {
.setAccentColor()
#endif
}
#if os(macOS)
.windowStyle(.titleBar)
.windowToolbarStyle(.unified)
#endif
}
}

Expand Down Expand Up @@ -237,7 +249,7 @@ struct ContentView: View {
private func startup() {
if #available(iOS 14.0, tvOS 14.0, *) {
if !preview {
log("PurePKG Running on \(Device().modelIdentifier) running iOS \(Device().pretty_version) (\(Device().build_number))")
log("PurePKG Running on \(Device().modelIdentifier) running \(Device().osString) \(Device().osString == "macOS" ? Device().build_number : "\(Device().pretty_version) (\(Device().build_number))")")
appData.installed_pkgs = RepoHandler.getInstalledTweaks(Jailbreak().path+"/Library/dpkg")
appData.repos = RepoHandler.getCachedRepos()
appData.pkgs = appData.repos.flatMap { $0.tweaks }
Expand Down
164 changes: 96 additions & 68 deletions PurePKG/Views/BrowseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,87 +36,115 @@ struct BrowseView: View {
NavigationLink(destination: TweakView(pkg: importedPackage, preview: preview), isActive: $showPackage, label: {})
}
}.appBG().navigationBarTitleC("Browse").listStyle(.plain).refreshableC { refreshRepos(appData) }
#if !os(macOS) && !os(watchOS)
#if os(macOS)
.toolbar {
refreshButton()
addRepoButton()
settingsButton()
}
#elseif !os(watchOS)
.navigationBarItems(trailing: HStack {
Button(action: {
refreshRepos(appData)
}) {
Image(systemName: "arrow.clockwise")
}
Button(action: {
#if !os(tvOS)
#if os(macOS)
let pasteboard = NSPasteboard.general
let clipboardString = pasteboard.string(forType: .string) ?? ""
#else
let clipboardString = UIPasteboard.general.string ?? ""
#endif
let urlCount = clipboardString.urlCount()
#else
let clipboardString = ""
let urlCount = 0
#endif
if urlCount > 1 {
let urls = clipboardString.extractURLs()
Task {
addBulkRepos(urls)
}
} else if urlCount == 1, let repourl = URL(string: clipboardString) {
Task {
await addRepoByURL(repourl)
}
} else {
showTextInputPopup("Add Repo", "Enter Repo URL", .URL, completion: { url in
if url != "" {
if let url = url {
if URL(string: url) != nil {
RepoHandler.addRepo(url)
} else {
showPopup("Error", "Invalid Repo URL")
}
}
}
})
}
}) {
Image(systemName: "plus")
}
NavigationLink(destination: SettingsView()) {
if #available(iOS 14.0, tvOS 14.0, *) {
Image(systemName: "gearshape.fill")
} else {
Image(systemName: "gear")
}
}
refreshButton()
addRepoButton()
settingsButton()
})
#endif
}
}

func addRepoByURL(_ url: URL) async {
let session = URLSession.shared
var request = URLRequest(url: url)
request.httpMethod = "HEAD"
struct refreshButton: View {
@EnvironmentObject var appData: AppData

do {
let (_, response) = try await session.data(from: request.url!)
let statuscode = (response as? HTTPURLResponse)?.statusCode ?? 0

if statuscode == 200 {
RepoHandler.addRepo(url.absoluteString)
var body: some View {
Button(action: {
refreshRepos(appData)
} else {
}) {
Image(systemName: "arrow.clockwise")
}
}
}

struct addRepoButton: View {
@EnvironmentObject var appData: AppData

var body: some View {
Button(action: {
#if !os(tvOS) && !os(watchOS)
#if os(macOS)
let pasteboard = NSPasteboard.general
let clipboardString = pasteboard.string(forType: .string) ?? ""
#else
let clipboardString = UIPasteboard.general.string ?? ""
#endif
let urlCount = clipboardString.urlCount()
#else
let clipboardString = ""
let urlCount = 0
#endif
if urlCount > 1 {
let urls = clipboardString.extractURLs()
Task {
addBulkRepos(urls)
}
} else if urlCount == 1, let repourl = URL(string: clipboardString) {
Task {
await addRepoByURL(repourl)
}
} else {
showTextInputPopup("Add Repo", "Enter Repo URL", .URL, completion: { url in
if url != "" {
if let url = url {
if URL(string: url) != nil {
RepoHandler.addRepo(url)
} else {
showPopup("Error", "Invalid Repo URL")
}
}
}
})
}
}) {
Image(systemName: "plus")
}
}

func addBulkRepos(_ urls: [URL]) {
for url in urls {
RepoHandler.addRepo(url.absoluteString)
}
refreshRepos(appData)
}

func addRepoByURL(_ url: URL) async {
let session = URLSession.shared
var request = URLRequest(url: url)
request.httpMethod = "HEAD"

do {
let (_, response) = try await session.data(from: request.url!)
let statuscode = (response as? HTTPURLResponse)?.statusCode ?? 0

if statuscode == 200 {
RepoHandler.addRepo(url.absoluteString)
refreshRepos(appData)
} else {
showPopup("Error", "Invalid Repo?")
}
} catch {
showPopup("Error", "Invalid Repo?")
}
} catch {
showPopup("Error", "Invalid Repo?")
}
}

func addBulkRepos(_ urls: [URL]) {
for url in urls {
RepoHandler.addRepo(url.absoluteString)
struct settingsButton: View {
var body: some View {
NavigationLink(destination: SettingsView()) {
if #available(iOS 14.0, tvOS 14.0, *) {
Image(systemName: "gearshape.fill")
} else {
Image(systemName: "gear")
}
}
}
refreshRepos(appData)
}
}
Loading

0 comments on commit d2bbd9a

Please sign in to comment.