diff --git a/RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/UserInterfaceState.xcuserstate b/RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/UserInterfaceState.xcuserstate index 2df703c..702d7e8 100644 Binary files a/RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/UserInterfaceState.xcuserstate and b/RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/RSwitch/Swift/Downloaders/DownloadFromRStudioServer.swift b/RSwitch/Swift/Downloaders/DownloadFromRStudioServer.swift index 62c39ea..100ff48 100644 --- a/RSwitch/Swift/Downloaders/DownloadFromRStudioServer.swift +++ b/RSwitch/Swift/Downloaders/DownloadFromRStudioServer.swift @@ -12,9 +12,21 @@ import Cocoa func download_from_studio_server(fromRS : String, toFS : String) { NSLog("download from rstudio server") - + let rsURL = URL(string: fromRS)! let fsURL = URL(string: toFS)! + + if (FileManager.default.fileExists(atPath: fsURL.path)) { + + NSLog("Deleting old file") + do { + try FileManager.default.removeItem(at: fsURL) + } catch { + NSLog("error deleting old file") + } + + } + let task = URLSession.shared.downloadTask(with: rsURL) { localURL, urlResponse, error in @@ -32,10 +44,10 @@ func download_from_studio_server(fromRS : String, toFS : String) { do { NSLog("Trying to move the data from \(localURL) to \(fsURL)"); try FileManager.default.moveItem(at: localURL, to: fsURL) -// NSWorkspace.shared.openFile( -// fsURL.deletingLastPathComponent().absoluteString, withApplication: "Finder" -// ) -// NSWorkspace.shared.activateFileViewerSelecting([fsURL]) + NSWorkspace.shared.openFile( + fsURL.deletingLastPathComponent().absoluteString, withApplication: "Finder" + ) + NSWorkspace.shared.activateFileViewerSelecting([fsURL]) } catch { NSLog("Move Error \(error)") } diff --git a/RSwitch/Swift/RStudioServerSessionWebViewController.swift b/RSwitch/Swift/RStudioServerSessionWebViewController.swift index a0e945e..5d674f6 100644 --- a/RSwitch/Swift/RStudioServerSessionWebViewController.swift +++ b/RSwitch/Swift/RStudioServerSessionWebViewController.swift @@ -95,6 +95,8 @@ extension RstudioServerSessionWebViewController: WKUIDelegate { exportWV.loadWebView(urlIn: navigationAction.request.url!.absoluteString) + NSLog("After exportWV.loadWebView") + return(exportWV.webView) diff --git a/RSwitch/Swift/exportPopupViewController.swift b/RSwitch/Swift/exportPopupViewController.swift index b7605b7..0982e4b 100644 --- a/RSwitch/Swift/exportPopupViewController.swift +++ b/RSwitch/Swift/exportPopupViewController.swift @@ -35,14 +35,14 @@ class exportPopupViewController: NSViewController { urlPath = urlIn - NSLog("loadWebView: " + urlPath) + NSLog("loadWebView: \(urlPath)") // Check for "/export/" // If export, then get bring up a Save Panel and then download the file to that location if let url = URL(string: urlPath) { - NSLog("URL path: " + url.path) + NSLog("URL path: \(url.path)") if (url.path.starts(with: "/export")) { @@ -54,15 +54,11 @@ class exportPopupViewController: NSViewController { savePanel.nameFieldStringValue = url.queryParameters["name"]! savePanel.beginSheetModal(for:self.view.window!) { (response) in if (response == NSApplication.ModalResponse.OK) { - //completionHandler([savePanel.url!]) - NSLog("SP OK RESP") - NSLog("From here " + url.absoluteString) - NSLog("To here " + savePanel.url!.absoluteString) - + download_from_studio_server(fromRS: url.absoluteString, toFS: savePanel.url!.absoluteString) } else { - //completionHandler(nil) + NSLog("Don't do anything!") } savePanel.close() @@ -93,11 +89,11 @@ extension exportPopupViewController: WKUIDelegate { extension exportPopupViewController: WKNavigationDelegate { open func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { - print("Export DID START") + print("Export DID START \(String(describing: webView.url))") } func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { - print("Export DID FINISH") + print("Export DID FINISH \(String(describing: webView.url))") } }