Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Lrdsnow committed Jun 17, 2024
1 parent 97a56de commit 438c1fd
Show file tree
Hide file tree
Showing 24 changed files with 1,333 additions and 167 deletions.
27 changes: 24 additions & 3 deletions PurePKG.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions PurePKG/Extentions/Compat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ extension View {
self
}
}
@ViewBuilder
func setAccentColor() -> some View {
if let accent = UserDefaults.standard.string(forKey: "accentColor"),
let accent_color = Color(hex: accent) {
self.accentColor(accent_color)
} else {
self
}
}
}

struct SectionC<Content: View>: View {
Expand Down Expand Up @@ -189,3 +198,82 @@ func openURL(_ url: URL) {
UIApplication.shared.open(url)
#endif
}

#if os(iOS)
extension View {
@ViewBuilder
func sheetC<Content: View>(isPresented: Binding<Bool>, @ViewBuilder content: @escaping () -> Content) -> some View {
if #available(iOS 16.0, *), UIDevice.current.userInterfaceIdiom == .phone {
self.sheet(isPresented: isPresented, content: content)
} else {
self._sheetC(isPresented: isPresented, content: content)
}
}
@ViewBuilder
func purePresentationDetents() -> some View {
if #available(iOS 16.0, *), UIDevice.current.userInterfaceIdiom == .phone {
self.presentationDetents([.height(UIApplication.shared.windows[0].safeAreaInsets.bottom > 0 ? UIScreen.main.bounds.height/4 : UIScreen.main.bounds.height/3)])
} else {
self
}
}
}

extension View {
func _sheetC<Content: View>(isPresented: Binding<Bool>, @ViewBuilder content: @escaping () -> Content) -> some View {
self.background(FallbackSheetPresenter(isPresented: isPresented, content: content))
}
}

private struct FallbackSheetPresenter<Content: View>: UIViewControllerRepresentable {
@Binding var isPresented: Bool
let content: () -> Content

func makeCoordinator() -> Coordinator {
Coordinator(isPresented: $isPresented, content: content)
}

func makeUIViewController(context: Context) -> UIViewController {
return UIViewController()
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
log("update")
if isPresented && uiViewController.presentedViewController == nil {
let hostingController = UIHostingController(rootView: content())
hostingController.modalPresentationStyle = .pageSheet
// let sheet = hostingController.sheetPresentationController {
if let sheet = (hostingController as NSObject).value(forKey: "sheetPresentationController") as? NSObject {
let height: CGFloat
if UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 0 > 0 {
height = UIScreen.main.bounds.height / 4
} else {
height = UIScreen.main.bounds.height / 3
}
// let detent = UISheetPresentationController.Detent = ._detent(withIdentifier: "custom_detent", height)
// sheet.detents = [detent]
sheet.setValue([CustomDetent(constant: height)], forKey: "detents")
}
uiViewController.present(hostingController, animated: true)
} else if !isPresented && uiViewController.presentedViewController != nil {
uiViewController.dismiss(animated: true)
}
}

class Coordinator: NSObject {
@Binding var isPresented: Bool
let content: () -> Content

init(isPresented: Binding<Bool>, content: @escaping () -> Content) {
_isPresented = isPresented
self.content = content
}

@objc func dismiss() {
log("dismissed")
isPresented = false
}
}
}

#endif
6 changes: 3 additions & 3 deletions PurePKG/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ struct PurePKGApp: App {
#if os(watchOS)
ContentViewWatchOS(tab: $tab, importedPackage: $importedPackage, showPackage: $showPackage)
.environmentObject(appData)
.accentColor(Color(hex: UserDefaults.standard.string(forKey: "accentColor") ?? "#EBC2FF"))
.setAccentColor()
#else
ContentView(tab: $tab, importedPackage: $importedPackage, showPackage: $showPackage, preview: false)
.environmentObject(appData)
.accentColor(Color(hex: UserDefaults.standard.string(forKey: "accentColor") ?? "#EBC2FF"))
.setAccentColor()
#endif
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ struct ContentView: View {
Text("Search")
}
.tag(2)
if !appData.queued.all.isEmpty {
if !appData.queued.all.isEmpty || Device().osString == "tvOS" {
QueueView()
.tabItem {
Image(systemName: "list.bullet")
Expand Down
5 changes: 5 additions & 0 deletions PurePKG/PurePKG.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
18 changes: 12 additions & 6 deletions PurePKG/Views/QueueView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ struct QueueView: View {
VStack(alignment: .leading) {
if !showLog {
List {
if appData.queued.all.isEmpty {
Text("No Queued Tweaks")
} else {
if !appData.queued.install.isEmpty {
Section(content: {
ForEach(toInstall, id: \.id) { package in
Expand Down Expand Up @@ -61,9 +64,9 @@ struct QueueView: View {
}
}, header: {
Text("Install/Upgrade").foregroundColor(.accentColor)
#if !os(iOS)
#if !os(iOS)
.padding(.leading).padding(.top)
#endif
#endif
})
}
if !appData.queued.uninstall.isEmpty {
Expand Down Expand Up @@ -97,12 +100,13 @@ struct QueueView: View {
}
}, header: {
Text("Uninstall").foregroundColor(.accentColor)
#if !os(iOS)
#if !os(iOS)
.padding(.leading).padding(.top)
#endif
#endif
})
}
}
}
} else {
Text(installLog).padding()
}
Expand All @@ -119,11 +123,13 @@ struct QueueView: View {
#endif
#if !os(macOS) && !os(watchOS)
.navigationBarItems(trailing: HStack {
if !appData.queued.all.isEmpty {
Button(action: {
editing.toggle()
}, label: {
Image(systemName: "pencil")
})
}
})
#endif
}
Expand All @@ -147,7 +153,7 @@ struct InstallQueuedButton: View {
var body: some View {
HStack {
Spacer()
if done && !showLog {
if done && !showLog && !appData.queued.all.isEmpty {
Button(action: {
showLog = true
}, label: {
Expand Down Expand Up @@ -212,7 +218,7 @@ struct InstallQueuedButton: View {
.padding()
#endif
Spacer()
}).borderedProminentButtonC().tintC(Color.accentColor.opacity(0.7))
}).borderedProminentButtonC().tintC(Color.accentColor.opacity(0.7)).disabled(appData.queued.all.isEmpty || installingQueue)
Spacer()
}
}
Expand Down
Loading

0 comments on commit 438c1fd

Please # to comment.