Browse Source

downloads working

master
boB Rudis 10 months ago
parent
commit
b89c16dfb0
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
4 changed files with 25 additions and 15 deletions
  1. BIN
      RSwitch.xcworkspace/xcuserdata/hrbrmstr.xcuserdatad/UserInterfaceState.xcuserstate
  2. +17
    -5
      RSwitch/Swift/Downloaders/DownloadFromRStudioServer.swift
  3. +2
    -0
      RSwitch/Swift/RStudioServerSessionWebViewController.swift
  4. +6
    -10
      RSwitch/Swift/exportPopupViewController.swift

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


+ 17
- 5
RSwitch/Swift/Downloaders/DownloadFromRStudioServer.swift View File

@ -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"
// </span><span class="c1"> pan> )
// NSWorkspace.shared.activateFileViewerSelecting([fsURL])
NSWorkspace.shared.openFile(
fsURL.deletingLastPathComponent().absoluteString, withApplication: "Finder"
)
NSWorkspace.shared.activateFileViewerSelecting([fsURL])
} catch {
NSLog("Move Error \(error)")
}


+ 2
- 0
RSwitch/Swift/RStudioServerSessionWebViewController.swift View File

@ -95,6 +95,8 @@ extension RstudioServerSessionWebViewController: WKUIDelegate {
exportWV.loadWebView(urlIn: navigationAction.request.url!.absoluteString)
NSLog("After exportWV.loadWebView")
return(exportWV.webView)


+ 6
- 10
RSwitch/Swift/exportPopupViewController.swift View File

@ -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