Browse Source

downloads working

master
boB Rudis 4 years ago
parent
commit
b89c16dfb0
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. BIN
      RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/UserInterfaceState.xcuserstate
  2. 22
      RSwitch/Swift/Downloaders/DownloadFromRStudioServer.swift
  3. 2
      RSwitch/Swift/RStudioServerSessionWebViewController.swift
  4. 16
      RSwitch/Swift/exportPopupViewController.swift

BIN
RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/UserInterfaceState.xcuserstate

Binary file not shown.

22
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)")
}

2
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)

16
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))")
}
}

Loading…
Cancel
Save