Skip to content

Commit

Permalink
remove stopServer(), will happen at dealloc anyway; add notification …
Browse files Browse the repository at this point in the history
…center listeners to send view status to webview socket
  • Loading branch information
samuraisam committed Mar 27, 2017
1 parent dca092b commit 237e13e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions BreadWallet/BRWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ import WebKit
"loaded": didLoad,
]
}
var indexUrl: URL {
return URL(string: "http://127.0.0.1:\(server.port)\(mountPoint)")!
}

init(bundleName name: String, mountPoint mp: String = "/") {
wkProcessPool = WKProcessPool()
Expand All @@ -63,10 +66,6 @@ import WebKit
fatalError("init(coder:) has not been implemented")
}

deinit {
stopServer()
}

override open func loadView() {
didLoad = false

Expand All @@ -79,7 +78,6 @@ import WebKit
config.allowsPictureInPictureMediaPlayback = false
}

let indexUrl = URL(string: "http://127.0.0.1:\(server.port)\(mountPoint)")!
let request = URLRequest(url: indexUrl)

view = UIView(frame: CGRect.zero)
Expand All @@ -91,6 +89,15 @@ import WebKit
_ = webView?.load(request)
webView?.autoresizingMask = [.flexibleHeight, .flexibleWidth]
view.addSubview(webView!)

NotificationCenter.default.addObserver(forName: .UIApplicationDidBecomeActive, object: nil, queue: OperationQueue.main) { (_) in
self.didAppear = true
self.sendToAllSockets(data: self.webViewInfo)
}
NotificationCenter.default.addObserver(forName: .UIApplicationWillResignActive, object: nil, queue: OperationQueue.main) { (_) in
self.didAppear = false
self.sendToAllSockets(data: self.webViewInfo)
}
}

override open func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -148,14 +155,7 @@ import WebKit
print("\n\n\nSERVER ERROR! \(e)\n\n\n")
}
}

open func stopServer() {
if server.isStarted {
server.stop()
server.resetMiddleware()
}
}


fileprivate func setupIntegrations() {
// proxy api for signing and verification
let apiProxy = BRAPIProxy(mountAt: "/_api", client: BRAPIClient.sharedClient)
Expand Down Expand Up @@ -222,7 +222,8 @@ import WebKit
}

open func refresh() {
_ = webView?.reload()
let request = URLRequest(url: indexUrl)
_ = webView?.load(request)
}

// MARK: - navigation delegate
Expand Down

0 comments on commit 237e13e

Please sign in to comment.