chore: atualização geral
This commit is contained in:
@@ -101,6 +101,25 @@ struct ProjectView: View {
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.task { restoreLastProject() }
|
||||
}
|
||||
|
||||
/// Reabre o último projeto salvo em ~/.fcp-mcp-server/config.json, para o
|
||||
/// app voltar onde parou em vez de pedir o arquivo de novo a cada abertura.
|
||||
/// É aqui que a restauração precisa morar: a TranscriptionView embutida só
|
||||
/// existe depois que há um projeto carregado, então ela não consegue se
|
||||
/// restaurar sozinha. Caminhos que sumiram do disco voltam vazios do
|
||||
/// Python, e nesse caso a tela abre limpa como antes.
|
||||
private func restoreLastProject() {
|
||||
guard project == nil else { return }
|
||||
PythonBridge.call(command: "project_config") { result, _ in
|
||||
DispatchQueue.main.async {
|
||||
guard project == nil,
|
||||
let result, result["ok"] as? Bool == true,
|
||||
let file = result["file"] as? String, !file.isEmpty else { return }
|
||||
inspect(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Presents an NSOpenPanel configured to select a single file (not a
|
||||
@@ -156,6 +175,23 @@ struct ProjectView: View {
|
||||
|
||||
private func handleDrop(_ providers: [NSItemProvider]) -> Bool {
|
||||
guard let provider = providers.first else { return false }
|
||||
|
||||
// `loadObject(ofClass: URL.self)` is Foundation's own bridge for a
|
||||
// dropped file URL and handles every representation Finder/FCP may
|
||||
// hand back (NSURL via secure coding, a bookmark, a plain path).
|
||||
// The item can ALSO be manually pulled as raw `Data` — but that only
|
||||
// works if the bytes are exactly `URL.dataRepresentation`'s format
|
||||
// (a UTF-8 absolute-string encoding), which a `.fcpxmld` *bundle*
|
||||
// (a package macOS treats as a directory, not a plain file) does not
|
||||
// always arrive as: the decode silently returns nil, so the drop
|
||||
// looks like it does nothing. Try the robust path first.
|
||||
if provider.canLoadObject(ofClass: URL.self) {
|
||||
_ = provider.loadObject(ofClass: URL.self) { url, _ in
|
||||
self.handleDroppedURL(url)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
provider.loadItem(forTypeIdentifier: UTType.fileURL.identifier, options: nil) { item, _ in
|
||||
var url: URL?
|
||||
if let data = item as? Data {
|
||||
@@ -163,17 +199,21 @@ struct ProjectView: View {
|
||||
} else if let u = item as? URL {
|
||||
url = u
|
||||
}
|
||||
if let url, isAccepted(url) {
|
||||
DispatchQueue.main.async { inspect(url.path) }
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
errorMessage = "Este arquivo não parece ser um projeto do Final Cut Pro."
|
||||
}
|
||||
}
|
||||
self.handleDroppedURL(url)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private func handleDroppedURL(_ url: URL?) {
|
||||
DispatchQueue.main.async {
|
||||
if let url, isAccepted(url) {
|
||||
inspect(url.path)
|
||||
} else {
|
||||
errorMessage = "Este arquivo não parece ser um projeto do Final Cut Pro."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func isAccepted(_ url: URL) -> Bool {
|
||||
let ext = url.pathExtension.lowercased()
|
||||
return ext == "fcpxml" || ext == "fcpxmld" || ext == "xml"
|
||||
@@ -242,6 +282,8 @@ struct ProjectView: View {
|
||||
if let result, result["ok"] as? Bool == true {
|
||||
project = ProjectInfo(json: result)
|
||||
showTranscription = true
|
||||
PythonBridge.call(command: "set_project_config",
|
||||
arguments: ["file": path]) { _, _ in }
|
||||
} else {
|
||||
errorMessage = result?["error"] as? String ?? err ?? "Falha ao ler o projeto."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user