boB Rudis
4 years ago
15 changed files with 323 additions and 29 deletions
Binary file not shown.
@ -0,0 +1,51 @@ |
|||||
|
// |
||||
|
// DownloadFromRStudioServer.swift |
||||
|
// RSwitch |
||||
|
// |
||||
|
// Created by hrbrmstr on 8/24/19. |
||||
|
// Copyright © 2019 Bob Rudis. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import Foundation |
||||
|
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)! |
||||
|
|
||||
|
let task = URLSession.shared.downloadTask(with: rsURL) { |
||||
|
localURL, urlResponse, error in |
||||
|
|
||||
|
if (error != nil) { |
||||
|
|
||||
|
NSLog("dler \(String(describing: error))") |
||||
|
|
||||
|
} else { |
||||
|
|
||||
|
if let localURL = localURL { |
||||
|
|
||||
|
NSLog("We've got the data"); |
||||
|
|
||||
|
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]) |
||||
|
} catch { |
||||
|
NSLog("Move Error \(error)") |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
task.resume() |
||||
|
} |
||||
|
|
@ -0,0 +1,22 @@ |
|||||
|
// |
||||
|
// ExportWebViewController.swift |
||||
|
// RSwitch |
||||
|
// |
||||
|
// Created by hrbrmstr on 5/24/20. |
||||
|
// Copyright © 2020 Bob Rudis. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import Cocoa |
||||
|
|
||||
|
class ExportWebViewController: NSWindowController { |
||||
|
|
||||
|
override func windowDidLoad() { |
||||
|
|
||||
|
shouldCascadeWindows = false |
||||
|
window?.setFrameAutosaveName(window!.title) |
||||
|
|
||||
|
super.windowDidLoad() |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
// |
||||
|
// urls.swift |
||||
|
// RSwitch |
||||
|
// |
||||
|
// Created by hrbrmstr on 5/24/20. |
||||
|
// Copyright © 2020 Bob Rudis. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import Foundation |
||||
|
import Cocoa |
||||
|
import WebKit |
||||
|
|
||||
|
extension URL { |
||||
|
var queryParameters: QueryParameters { return QueryParameters(url: self) } |
||||
|
} |
||||
|
|
||||
|
class QueryParameters { |
||||
|
let queryItems: [URLQueryItem] |
||||
|
init(url: URL?) { |
||||
|
queryItems = URLComponents(string: url?.absoluteString ?? "")?.queryItems ?? [] |
||||
|
print(queryItems) |
||||
|
} |
||||
|
subscript(name: String) -> String? { |
||||
|
return queryItems.first(where: { $0.name == name })?.value |
||||
|
} |
||||
|
} |
@ -0,0 +1,104 @@ |
|||||
|
// |
||||
|
// exportPopupViewController.swift |
||||
|
// RSwitch |
||||
|
// |
||||
|
// Created by hrbrmstr on 5/24/20. |
||||
|
// Copyright © 2020 Bob Rudis. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import Cocoa |
||||
|
import WebKit |
||||
|
|
||||
|
// EXPORT |
||||
|
|
||||
|
class exportPopupViewController: NSViewController { |
||||
|
|
||||
|
var webView: WKWebView! |
||||
|
var urlPath: String = "" |
||||
|
|
||||
|
open override func viewDidLoad() { |
||||
|
super.viewDidLoad() |
||||
|
} |
||||
|
|
||||
|
func setupWebView(configuration: WKWebViewConfiguration) { |
||||
|
|
||||
|
webView = WKWebView(frame: view.bounds, configuration: configuration) |
||||
|
webView.autoresizingMask = [.width, .height] |
||||
|
webView.uiDelegate = self |
||||
|
webView.navigationDelegate = self |
||||
|
|
||||
|
view.addSubview(webView) |
||||
|
|
||||
|
} |
||||
|
|
||||
|
func loadWebView(urlIn: String) { |
||||
|
|
||||
|
urlPath = urlIn |
||||
|
|
||||
|
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) |
||||
|
|
||||
|
if (url.path.starts(with: "/export")) { |
||||
|
|
||||
|
NSLog(" Name: " + url.queryParameters["name"]!) |
||||
|
|
||||
|
let savePanel = NSSavePanel() |
||||
|
|
||||
|
savePanel.canCreateDirectories = true |
||||
|
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() |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
override func viewDidAppear() { |
||||
|
super.viewDidAppear() |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
extension exportPopupViewController: WKUIDelegate { |
||||
|
|
||||
|
func webViewDidClose(_ webView: WKWebView) { |
||||
|
self.view.window?.close() |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
extension exportPopupViewController: WKNavigationDelegate { |
||||
|
|
||||
|
open func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { |
||||
|
print("Export DID START") |
||||
|
} |
||||
|
|
||||
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { |
||||
|
print("Export DID FINISH") |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
Before Width: | Height: | Size: 204 KiB After Width: | Height: | Size: 346 KiB |
Loading…
Reference in new issue