diff --git a/Pomelo/ContentView.swift b/Pomelo/ContentView.swift index c6f8a9e..e22d501 100644 --- a/Pomelo/ContentView.swift +++ b/Pomelo/ContentView.swift @@ -18,6 +18,7 @@ struct ContentView: View { @AppStorage("useTrollStore") var useTrollStore: Bool = false @AppStorage("showMetalHUD") var showMetalHUD: Bool = false @AppStorage("canShowMetalHUD") var canShowMetalHUD: Bool = false + @AppStorage("HideMenuButton") private var HideMenuButton: Bool = true @State var core = Core(games: [], root: FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]) var body: some View { //NavView(core: $core) // pain and suffering diff --git a/Pomelo/Emulation/EmulationHandlers/SudachiEmulationHandler.swift b/Pomelo/Emulation/EmulationHandlers/SudachiEmulationHandler.swift index 6dd7d47..225d5f2 100644 --- a/Pomelo/Emulation/EmulationHandlers/SudachiEmulationHandler.swift +++ b/Pomelo/Emulation/EmulationHandlers/SudachiEmulationHandler.swift @@ -38,7 +38,10 @@ class SudachiEmulationViewModel: ObservableObject { iscustom = ((sudachiGame?.fileURL.startAccessingSecurityScopedResource()) != nil) - DispatchQueue.global(qos: .userInitiated).async { [self] in + print(sudachiGame) + + print("is outside url? \(iscustom ? "Yes" : "no")") + DispatchQueue.global(qos: .userInteractive).async { [self] in if let sudachiGame = self.sudachiGame { if sudachiGame.fileURL == URL(string: "BootMii") { @@ -61,12 +64,7 @@ class SudachiEmulationViewModel: ObservableObject { private func step() { while true { - if !isPaused { - sudachi.step() - } else { - print("pased") - } - + sudachi.step() } } diff --git a/Pomelo/Emulation/EmulationViews/SudachiEmulationView.swift b/Pomelo/Emulation/EmulationViews/SudachiEmulationView.swift index bf4f5c0..3908ed3 100644 --- a/Pomelo/Emulation/EmulationViews/SudachiEmulationView.swift +++ b/Pomelo/Emulation/EmulationViews/SudachiEmulationView.swift @@ -26,6 +26,7 @@ struct SudachiEmulationView: View { @State private var timer: Timer? @Environment(\.scenePhase) var scenePhase @AppStorage("isairplay") private var isairplay: Bool = true + @AppStorage("HideMenuButton") private var HideMenuButton: Bool = true let documentsDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] @Environment(\.presentationMode) var presentationMode @@ -43,70 +44,71 @@ struct SudachiEmulationView: View { ControllerView() - - VStack { - HStack { - Spacer() - Menu { - Button { - if let metalView = mtkview { - print("button pressed") - - let lastDrawableDisplayed = metalView.currentDrawable?.texture - - if let imageRef = lastDrawableDisplayed?.toImage() { - let uiImage: UIImage = UIImage.init(cgImage: imageRef) + if !HideMenuButton { + VStack { + HStack { + Spacer() + Menu { + Button { + if let metalView = mtkview { + print("button pressed") - if let pngData = uiImage.pngData() { - // Define the path to save the PNG file - if let game = self.game { - let fileURL = documentsDir.appendingPathComponent("screenshots/\(game.title)-(\(Date())).png") - print(Date()) - do { - // Write the PNG data to the file - try pngData.write(to: fileURL) - print("Image saved to: \(fileURL.path)") - } catch { - print("Error saving PNG: \(error)") + let lastDrawableDisplayed = metalView.currentDrawable?.texture + + if let imageRef = lastDrawableDisplayed?.toImage() { + let uiImage: UIImage = UIImage.init(cgImage: imageRef) + + if let pngData = uiImage.pngData() { + // Define the path to save the PNG file + if let game = self.game { + let fileURL = documentsDir.appendingPathComponent("screenshots/\(game.title)-(\(Date())).png") + print(Date()) + do { + // Write the PNG data to the file + try pngData.write(to: fileURL) + print("Image saved to: \(fileURL.path)") + } catch { + print("Error saving PNG: \(error)") + } + } else { + let fileURL = documentsDir.appendingPathComponent("screenshots/Home_Menu-(\(Date())).png") + + do { + // Write the PNG data to the file + try pngData.write(to: fileURL) + print("Image saved to: \(fileURL.path)") + } catch { + print("Error saving PNG: \(error)") + } } } else { - let fileURL = documentsDir.appendingPathComponent("screenshots/Home_Menu-(\(Date())).png") - - do { - // Write the PNG data to the file - try pngData.write(to: fileURL) - print("Image saved to: \(fileURL.path)") - } catch { - print("Error saving PNG: \(error)") - } + print("Failed to convert UIImage to PNG data") } - } else { - print("Failed to convert UIImage to PNG data") } } + } label: { + Text("Take Screenshot") + .font(.title) + .padding() } + + Button { + viewModel.customButtonTapped() + + presentationMode.wrappedValue.dismiss() + } label: { + Text("Exit (Unstable)") + } + } label: { - Text("Take Screenshot") - .font(.title) - .padding() + Image(systemName: "ellipsis.circle.fill") + .resizable() + .frame(width: 45, height: 45) + .foregroundColor(Color.gray) } - - Button { - viewModel.customButtonTapped() - - presentationMode.wrappedValue.dismiss() - } label: { - Text("Exit (Unstable)") - } - - } label: { - Image(systemName: "ellipsis.circle.fill") - .resizable() - .frame(width: 45, height: 45) - .foregroundColor(Color.gray) } + Spacer() } - Spacer() } } .overlay( diff --git a/Pomelo/LibraryViews/Menu/BottomMenuView.swift b/Pomelo/LibraryViews/Menu/BottomMenuView.swift index 28c1e5a..f749b93 100644 --- a/Pomelo/LibraryViews/Menu/BottomMenuView.swift +++ b/Pomelo/LibraryViews/Menu/BottomMenuView.swift @@ -12,11 +12,28 @@ import Sudachi struct BottomMenuView: View { @Binding var core: Core @State var isImporting: Bool = false + @State var isSelecting: Bool = false + + @State var urlgame: PomeloGame? + + @State var startgame = false + + var body: some View { HStack(spacing: 40) { + NavigationLink( + destination: urlgame != nil ? AnyView(SudachiEmulationView(game: urlgame!)) : AnyView(EmptyView()), + // destination: SudachiEmulationView(game: urlgame), + isActive: $startgame, + label: { + EmptyView() // Keeps the link hidden + } + ) + .hidden() + Button { - if let url = URL(string: "messages://") { // Replace appScheme with the actual URL scheme of the app + if let url = URL(string: "messages://") { if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:]) { (success) in if success { @@ -51,8 +68,19 @@ struct BottomMenuView: View { .foregroundColor(Color.init(uiColor: .darkGray)) } - Button { - isImporting = true + Menu { + Button { + isImporting = true + } label: { + Text("Import Files") + } + + Button { + isSelecting = true + isImporting.toggle() + } label: { + Text("Open Game (without importing)") + } } label: { Circle() .overlay { @@ -63,6 +91,7 @@ struct BottomMenuView: View { .frame(width: 50, height: 50) .foregroundColor(Color.init(uiColor: .darkGray)) } + NavigationLink(destination: SettingsView(core: core)) { @@ -89,52 +118,86 @@ struct BottomMenuView: View { } } .padding(.bottom, 20) + .fileImporter(isPresented: $isImporting, allowedContentTypes: [.zip, .item]) { result in switch result { case .success(let url): - let directory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] - if url.lastPathComponent.hasSuffix(".zip") { - core.AddFirmware(at: url) + if isSelecting { + startGame(url: url) + isSelecting = false + } else { + addGame(url: url) } - - if core.supportedFileTypes.contains(url.pathExtension.lowercased()) { - let fileManager = FileManager.default - let has = url.startAccessingSecurityScopedResource() - do { - // Move the file - try fileManager.copyItem(at: url, to: directory.appendingPathComponent("roms").appendingPathComponent(url.lastPathComponent)) - } catch { - print("Error moving file: \(error.localizedDescription)") - } - - if has { - url.stopAccessingSecurityScopedResource() - } - } - - if url.lastPathComponent.hasSuffix(".keys") { - let fileManager = FileManager.default - let has = url.startAccessingSecurityScopedResource() - do { - // Move the file - try fileManager.copyItem(at: url, to: directory.appendingPathComponent("keys").appendingPathComponent(url.lastPathComponent)) - } catch { - print("Error moving file: \(error.localizedDescription)") - } - - if has { - url.stopAccessingSecurityScopedResource() - } - - let sudachi = Sudachi.shared - - sudachi.refreshKeys() - } - - core.refreshcore(core: &core) case .failure(let err): print(err) } } } + + func startGame(url: URL) { + if core.supportedFileTypes.contains(url.pathExtension.lowercased()) { + let bool = url.startAccessingSecurityScopedResource() + + defer { + if bool { + url.stopAccessingSecurityScopedResource() + + startgame = true + } + } + let sudachi = Sudachi.shared + + let info = sudachi.information(for: url) + + let game = PomeloGame(programid: Int(info.programID), ishomebrew: info.isHomebrew, developer: info.developer, fileURL: url, imageData: info.iconData, title: info.title) + + + urlgame = game + print(game) + + } + } + + func addGame(url: URL) { + let directory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] + if url.lastPathComponent.hasSuffix(".zip") { + core.AddFirmware(at: url) + } + + if core.supportedFileTypes.contains(url.pathExtension.lowercased()) { + let fileManager = FileManager.default + let has = url.startAccessingSecurityScopedResource() + do { + // Move the file + try fileManager.copyItem(at: url, to: directory.appendingPathComponent("roms").appendingPathComponent(url.lastPathComponent)) + } catch { + print("Error moving file: \(error.localizedDescription)") + } + + if has { + url.stopAccessingSecurityScopedResource() + } + } + + if url.lastPathComponent.hasSuffix(".keys") { + let fileManager = FileManager.default + let has = url.startAccessingSecurityScopedResource() + do { + // Move the file + try fileManager.copyItem(at: url, to: directory.appendingPathComponent("keys").appendingPathComponent(url.lastPathComponent)) + } catch { + print("Error moving file: \(error.localizedDescription)") + } + + if has { + url.stopAccessingSecurityScopedResource() + } + + let sudachi = Sudachi.shared + + sudachi.refreshKeys() + } + + core.refreshcore(core: &core) + } } diff --git a/Pomelo/Pomelo.entitlements b/Pomelo/Pomelo.entitlements index 1525dcf..99f4716 100644 --- a/Pomelo/Pomelo.entitlements +++ b/Pomelo/Pomelo.entitlements @@ -2,21 +2,7 @@ - com.apple.developer.applesignin - - Default - - com.apple.developer.kernel.extended-virtual-addressing - - com.apple.developer.kernel.increased-debugging-memory-limit - com.apple.developer.kernel.increased-memory-limit - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - - com.apple.security.network.client - diff --git a/Pomelo/PomeloDebug.entitlements b/Pomelo/PomeloDebug.entitlements index 1525dcf..99f4716 100644 --- a/Pomelo/PomeloDebug.entitlements +++ b/Pomelo/PomeloDebug.entitlements @@ -2,21 +2,7 @@ - com.apple.developer.applesignin - - Default - - com.apple.developer.kernel.extended-virtual-addressing - - com.apple.developer.kernel.increased-debugging-memory-limit - com.apple.developer.kernel.increased-memory-limit - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - - com.apple.security.network.client - diff --git a/Pomelo/SettingsViews/AdvancedSettings/AdvancedSettingsView.swift b/Pomelo/SettingsViews/AdvancedSettings/AdvancedSettingsView.swift index 4f02686..8a1bf7a 100644 --- a/Pomelo/SettingsViews/AdvancedSettings/AdvancedSettingsView.swift +++ b/Pomelo/SettingsViews/AdvancedSettings/AdvancedSettingsView.swift @@ -58,6 +58,7 @@ struct AdvancedSettingsView: View { .padding(.bottom) .font(.footnote) .foregroundColor(.gray) + if canShowMetalHUD {// (Int(UIDevice.current.systemVersion) ?? 0 >= 16) || canShowMetalHUD { Rectangle() .fill(Color(uiColor: UIColor.secondarySystemBackground)) diff --git a/Pomelo/SettingsViews/SettingsView.swift b/Pomelo/SettingsViews/SettingsView.swift index fb58bca..260136e 100644 --- a/Pomelo/SettingsViews/SettingsView.swift +++ b/Pomelo/SettingsViews/SettingsView.swift @@ -119,7 +119,7 @@ struct SettingsView: View { .frame(width: .infinity, height: 50) // Set the desired dimensions .overlay() { HStack { - Text("Advanced Settings") + Text("App Settings") .foregroundColor(.primary) .padding() Spacer() @@ -128,31 +128,6 @@ struct SettingsView: View { } .padding() - if isshown { - Rectangle() - .fill(Color(uiColor: UIColor.secondarySystemBackground)) // Set the fill color (optional) - .cornerRadius(10) // Apply rounded corners - .frame(width: .infinity, height: 50) // Set the desired dimensions - .overlay() { - HStack(alignment: .center) { - SignInApple() - .frame(width: 200, height: 50) - .foregroundColor(Color(uiColor: UIColor.secondarySystemBackground)) - } - .onAppear { - ASAuthorizationAppleIDProvider().getCredentialState(forUserID: deviceOwnerID ?? "0") { state, error in - if state != .authorized { - isshown = true - UserDefaults.standard.set(nil, forKey: "deviceOwnerName") - UserDefaults.standard.set(nil, forKey: "deviceOwnerID") - } else { - isshown = false - } - } - } - } - .padding() - } NavigationLink(destination: AppIconSwitcherView()) {