//
// e x p o r t P o p u p V i e w C o n t r o l l e r . s w i f t
// R S w i t c h
//
// C r e a t e d b y h r b r m s t r o n 5 / 2 4 / 2 0 .
// C o p y r i g h t © 2 0 2 0 B o b R u d i s . A l l r i g h t s r e s e r v e d .
//
import Cocoa
import WebKit
// E X P O R T
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 ) " )
// C h e c k f o r " / e x p o r t / "
// I f e x p o r t , t h e n g e t b r i n g u p a S a v e P a n e l a n d t h e n d o w n l o a d t h e f i l e t o t h a t l o c a t i o n
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 ) {
download_from_studio_server ( fromRS : url . absoluteString , toFS : savePanel . url ! . absoluteString )
} else {
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 \( String ( describing : webView . url ) ) " )
}
func webView ( _ webView : WKWebView , didFinish navigation : WKNavigation ! ) {
print ( " Export DID FINISH \( String ( describing : webView . url ) ) " )
}
}