Skip to content

Commit

Permalink
Merge pull request #138 from blackgold9/sv/clear-cache
Browse files Browse the repository at this point in the history
Clear cache on refresh
  • Loading branch information
robbiet480 committed Sep 5, 2018
2 parents 41afe43 + 59ba5f8 commit 6949f05
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions HomeAssistant/Views/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,23 @@ class WebViewController: UIViewController, WKNavigationDelegate, WKUIDelegate, C
}

@objc func refreshWebView(_ sender: UIBarButtonItem) {
if self.webView.isLoading {
self.webView.stopLoading()
} else if let connectionInfo = Current.settingsStore.connectionInfo {
self.webView.load(URLRequest(url: connectionInfo.activeURL))
let redirectOrReload = {
if self.webView.isLoading {
self.webView.stopLoading()
} else if let connectionInfo = Current.settingsStore.connectionInfo {
self.webView.load(URLRequest(url: connectionInfo.activeURL))
} else {
self.webView.reload()
}
}

let websiteDataTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache])
let date = Date(timeIntervalSince1970: 0)
if let typeSet = websiteDataTypes as? Set<String> {
WKWebsiteDataStore.default().removeData(ofTypes: typeSet, modifiedSince: date,
completionHandler: redirectOrReload)
} else {
self.webView.reload()
redirectOrReload()
}
}

Expand Down

0 comments on commit 6949f05

Please sign in to comment.