Skip to content

Commit

Permalink
Clear cache when refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
blackgold9 committed Sep 3, 2018
1 parent 7c0cbbd commit 49672af
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions HomeAssistant/Views/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,24 @@ 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))
} else {
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: {
self.webView.reload()
})
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 {
redirectOrReload()
}
}

func openSettingsWithError(error: Error) {
Expand Down

0 comments on commit 49672af

Please sign in to comment.