Skip to content

Commit

Permalink
oops lol
Browse files Browse the repository at this point in the history
  • Loading branch information
Lrdsnow committed Jun 18, 2024
1 parent f519732 commit 8032295
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 66 deletions.
4 changes: 4 additions & 0 deletions PurePKG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
653AB88D2BCF416500E3A215 /* TweakDepitionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653AB88C2BCF416500E3A215 /* TweakDepitionView.swift */; };
653AB8952BCF433B00E3A215 /* InstalledView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653AB8942BCF433B00E3A215 /* InstalledView.swift */; };
653AB8972BCF434A00E3A215 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 653AB8962BCF434A00E3A215 /* SearchView.swift */; };
655D8EE02C2201D9006A1773 /* macOS.m in Sources */ = {isa = PBXBuildFile; fileRef = 655D8EDF2C2201D8006A1773 /* macOS.m */; };
6575F92C2BD1BFD400D84BC1 /* QueueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6575F92B2BD1BFD400D84BC1 /* QueueView.swift */; };
65839EF62BCE480F00068B7A /* BrowseRows.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65839EF52BCE480F00068B7A /* BrowseRows.swift */; };
65839EF82BCE485B00068B7A /* TweaksListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65839EF72BCE485B00068B7A /* TweaksListView.swift */; };
Expand Down Expand Up @@ -59,6 +60,7 @@
653AB88C2BCF416500E3A215 /* TweakDepitionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TweakDepitionView.swift; sourceTree = "<group>"; };
653AB8942BCF433B00E3A215 /* InstalledView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstalledView.swift; sourceTree = "<group>"; };
653AB8962BCF434A00E3A215 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; };
655D8EDF2C2201D8006A1773 /* macOS.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = macOS.m; sourceTree = "<group>"; };
6562738E2BD58DFF00EA2828 /* curl.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = curl.xcframework; path = ../../../../Downloads/curl.xcframework; sourceTree = "<group>"; };
656273952BD58E5B00EA2828 /* curl.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = curl.framework; path = ../../../../Downloads/Carthage/Build/iOS/curl.framework; sourceTree = "<group>"; };
6562739F2BD5965500EA2828 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -137,6 +139,7 @@
65C1A52F2C16D9B500431468 /* CBackend */ = {
isa = PBXGroup;
children = (
655D8EDF2C2201D8006A1773 /* macOS.m */,
65D4B33A2C20A11400246E01 /* Compat.m */,
65D8E57A2C1F51FC006AFA97 /* Compat.h */,
65D8E5772C1E71CE006AFA97 /* PaymentAPI_tvOS.h */,
Expand Down Expand Up @@ -374,6 +377,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
655D8EE02C2201D9006A1773 /* macOS.m in Sources */,
65C1A5562C16D9B500431468 /* PaymentAPI.swift in Sources */,
65839EFA2BCE486B00068B7A /* RepoView.swift in Sources */,
65C1A5572C16D9B500431468 /* RepoHandler_RootHelper.swift in Sources */,
Expand Down
24 changes: 23 additions & 1 deletion PurePKG/Extentions/Compat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ extension NSColor {
return NSColor.labelColor
}
}
extension NSCoder {
static func cgSize(for key: String) -> CGSize {
let components = key.trimmingCharacters(in: CharacterSet(charactersIn: "{}")).components(separatedBy: ",")
guard components.count == 2,
let width = Double(components[0].trimmingCharacters(in: .whitespacesAndNewlines)),
let height = Double(components[1].trimmingCharacters(in: .whitespacesAndNewlines)) else {
return CGSize(width: 0.0, height: 0.0)
}
return CGSize(width: width, height: height)
}
}
#elseif os(watchOS)
extension UIColor {
static var secondaryLabel: UIColor {
Expand Down Expand Up @@ -199,7 +210,18 @@ func openURL(_ url: URL) {
#endif
}

#if os(iOS)
#if !os(iOS)
extension View {
@ViewBuilder
func sheetC<Content: View>(isPresented: Binding<Bool>, @ViewBuilder content: @escaping () -> Content) -> some View {
self.sheet(isPresented: isPresented, content: content)
}
@ViewBuilder
func purePresentationDetents() -> some View {
self
}
}
#else
extension View {
@ViewBuilder
func sheetC<Content: View>(isPresented: Binding<Bool>, @ViewBuilder content: @escaping () -> Content) -> some View {
Expand Down
2 changes: 1 addition & 1 deletion PurePKG/Views/SubViews/TweakDepitionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct TweakDepictionView: View {
// useBottomMargin - Boolean - Add spacing below the header. - Optional
let useBottomMargin = json["useBottomMargin"] as? Bool ?? false
// title - String - The title of the header. - Required
if let title = json["title"] as? String {
if let title = json["title"] as? String ?? json["text"] as? String {
ret = AnyView(
HStack {
if alignment == 2 || alignment == 1 {
Expand Down
5 changes: 4 additions & 1 deletion PurePKG/Views/TweakView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ struct TweakView: View {
if #available(iOS 14.0, tvOS 14.0, *) {
if let url = pkg.depiction,
!preview {
TweakDepictionView(url: url, banner: $banner, reqVer: $reqVer).padding(.horizontal).frame(maxWidth: UIScreen.main.bounds.width, maxHeight: .infinity)
TweakDepictionView(url: url, banner: $banner, reqVer: $reqVer).padding(.horizontal)
#if canImport(UIKit)
.frame(maxWidth: UIScreen.main.bounds.width, maxHeight: .infinity)
#endif
}
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions RootHelper/spawnStuff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import Foundation

@discardableResult
func spawnRootHelper(args: [String]) -> (Int, String, String) {
#if os(macOS)
var status: Int32 = 0
var stdoutStr: NSString?
var stderrStr: NSString?
spawnRootHelper_macOS(args, &status, &stdoutStr, &stderrStr)
return (Int(status), String(stdoutStr ?? ""), String(stderrStr ?? ""))
#else
#if targetEnvironment(simulator)
return (0, "", "")
#else
Expand Down Expand Up @@ -151,6 +158,7 @@ func spawnRootHelper(args: [String]) -> (Int, String, String) {

return (Int(status), stdoutStr, stderrStr);
#endif
#endif
}

@discardableResult
Expand Down
2 changes: 2 additions & 0 deletions Shared/CBackend/Compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

#import <Foundation/Foundation.h>
#if !TARGET_OS_MAC
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -21,3 +22,4 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END
#endif
2 changes: 2 additions & 0 deletions Shared/CBackend/Compat.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import "Compat.h"

#if !TARGET_OS_MAC
@implementation CustomDetent

+ (instancetype)customDetentWithConstant:(CGFloat)constant {
Expand All @@ -15,3 +16,4 @@ + (instancetype)customDetentWithConstant:(CGFloat)constant {
}

@end
#endif
2 changes: 1 addition & 1 deletion Shared/CBackend/PaymentAPI_tvOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//

#import "PaymentAPI_tvOS.h"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

#if TARGET_OS_TV
#import <UIKit/UIKit.h>

static UIColor *kTextColor() {
if (@available(tvOS 13, *)) {
Expand Down
4 changes: 3 additions & 1 deletion Shared/CBackend/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ int custom_posix_spawnattr_setflags(posix_spawnattr_t *, short) asm("_posix_spaw
int custom_posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t) asm("_posix_spawnattr_setpgroup");
int custom_posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict, const sigset_t * __restrict) asm("_posix_spawnattr_setsigmask");


#if TARGET_OS_MAC
void spawnRootHelper_macOS(NSArray<NSString *> *args, int *status, NSString **output, NSString **errorMessage);
#endif

#endif /* bridge_h */
75 changes: 75 additions & 0 deletions Shared/CBackend/macOS.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// macOS.m
// PurePKG
//
// Created by Lrdsnow on 6/18/24.
//

#import <Foundation/Foundation.h>

#if TARGET_OS_MAC
#import <Security/Authorization.h>

static void handleError(NSError *error, int *status, NSString **errorMessage) {
if (error) {
*status = (int)error.code;
*errorMessage = error.localizedDescription;
}
}

NS_ASSUME_NONNULL_BEGIN
extern void spawnRootHelper_macOS(NSArray<NSString *> *args, int *status, NSString **output, NSString **errorMessage) {
AuthorizationItem authItem = { kAuthorizationRightExecute, 0, NULL, 0 };
AuthorizationRights authRights = { 1, &authItem };
AuthorizationFlags authFlags = kAuthorizationFlagDefaults;
AuthorizationRef authRef = NULL;

OSStatus statusCreate = AuthorizationCreate(&authRights, kAuthorizationEmptyEnvironment, authFlags, &authRef);
if (statusCreate != errAuthorizationSuccess || !authRef) {
*status = (int)statusCreate;
*errorMessage = @"Authorization failed";
return;
}

NSString *executablePath = [[NSBundle mainBundle] executablePath];
if (!executablePath) {
*status = 1;
*errorMessage = @"Failed to get the executable path";
return;
}

NSMutableArray<NSString *> *argsReal = [NSMutableArray arrayWithObject:executablePath];
[argsReal addObjectsFromArray:args];

int argc = (int)argsReal.count;
const char **argv = (const char **)malloc(sizeof(char *) * argc);

for (int i = 0; i < argc; i++) {
argv[i] = [argsReal[i] UTF8String];
}

FILE *pipe = NULL;
AuthorizationFlags executeFlags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights | kAuthorizationFlagPreAuthorize;

OSStatus statusExecute = AuthorizationExecuteWithPrivileges(authRef, executablePath.UTF8String, executeFlags, (char *const * _Nonnull)argv, &pipe);
free(argv);

if (statusExecute != errAuthorizationSuccess) {
*status = (int)statusExecute;
*errorMessage = @"AuthorizationExecuteWithPrivileges failed";
AuthorizationFree(authRef, kAuthorizationFlagDefaults);
return;
}

NSFileHandle *fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileno(pipe) closeOnDealloc:YES];
NSData *data = [fileHandle readDataToEndOfFile];
[fileHandle closeFile];

*output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

AuthorizationFree(authRef, kAuthorizationFlagDefaults);
*status = 0;
*errorMessage = @"";
}
NS_ASSUME_NONNULL_END
#endif
6 changes: 6 additions & 0 deletions Shared/PaymentAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//

import Foundation
#if canImport(UIKit)
import UIKit
#endif
import AuthenticationServices
import SwiftUI

Expand Down Expand Up @@ -221,7 +223,11 @@ class PaymentAPI_WebAuthenticationCoordinator: NSObject, ASWebAuthenticationPres
}

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
#if canImport(UIKit)
return UIApplication.shared.windows.first { $0.isKeyWindow } ?? ASPresentationAnchor()
#else
return ASPresentationAnchor()
#endif
}
}
#endif
64 changes: 3 additions & 61 deletions docs/depiction.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,9 @@
"useBoldText": true
},
{
"appleTV": {
"class": "DepictionScreenshotsView",
"itemCornerRadius": 6,
"itemSize": "{346, 160}",
"screenshots": [
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722a57c005d8f9998d94"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722b57c005d8f999918c"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722c57c005d8f999919d"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722e57c005d8f999919f"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722f57c005d8f99991a1"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc723057c005d8f99991a3"
}
]
},
"class": "DepictionScreenshotsView",
"itemCornerRadius": 6,
"itemSize": "{160, 346}",
"screenshots": [
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722a57c005d8f9998d94"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722b57c005d8f999918c"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722c57c005d8f999919d"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722e57c005d8f999919f"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc722f57c005d8f99991a1"
},
{
"accessibilityText": "Screenshot",
"url": "https://media.havoc.app/61fc723057c005d8f99991a3"
}
]
}
"class":"DepictionLabelView",
"text": "Warning: There are probably a lot of bugs at the moment, if you encounter one please create an issue on github for it."
}
]
}
]
Expand Down

0 comments on commit 8032295

Please sign in to comment.