mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-05 23:02:58 +12:00
iOS: Add file picker (#747)
* iOS: Add file picker * Fix lock placement
This commit is contained in:
parent
90725252d3
commit
fec4428ebf
8 changed files with 130 additions and 11 deletions
|
@ -3,6 +3,47 @@ import SwiftUI
|
|||
import MetalKit
|
||||
import Darwin
|
||||
|
||||
var emulatorLock = NSLock()
|
||||
|
||||
class DocumentViewController: UIViewController, DocumentDelegate {
|
||||
var documentPicker: DocumentPicker!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
/// set up the document picker
|
||||
documentPicker = DocumentPicker(presentationController: self, delegate: self)
|
||||
/// When the view loads (ie user opens the app) show the file picker
|
||||
show()
|
||||
}
|
||||
|
||||
/// callback from the document picker
|
||||
func didPickDocument(document: Document?) {
|
||||
if let pickedDoc = document {
|
||||
let fileURL = pickedDoc.fileURL
|
||||
|
||||
print("Loading ROM", fileURL)
|
||||
emulatorLock.lock()
|
||||
iosLoadROM(fileURL.path(percentEncoded: false))
|
||||
emulatorLock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func show() {
|
||||
documentPicker.displayPicker()
|
||||
}
|
||||
}
|
||||
|
||||
struct DocumentView: UIViewControllerRepresentable {
|
||||
func makeUIViewController(context: Context) -> DocumentViewController {
|
||||
return DocumentViewController()
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: DocumentViewController, context: Context) {
|
||||
// No update needed
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView: UIViewRepresentable {
|
||||
@State var showFileImporter = true
|
||||
|
||||
|
@ -32,7 +73,9 @@ struct ContentView: UIViewRepresentable {
|
|||
iosCreateEmulator()
|
||||
|
||||
while (true) {
|
||||
emulatorLock.lock()
|
||||
iosRunFrame(metalLayer);
|
||||
emulatorLock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,6 +89,7 @@ struct ContentView: UIViewRepresentable {
|
|||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
DocumentView();
|
||||
ContentView();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue