From 70d297943374fc4391b46cad2613dd488dad7276 Mon Sep 17 00:00:00 2001 From: dsnallfot <72826201+dsnallfot@users.noreply.github.com> Date: Mon, 4 Mar 2024 19:29:53 +0100 Subject: [PATCH 1/5] Clear app browser cache when refreshing Nightscout view by swiping down - All changed settings reverts to default NS config vars - Any changes made in nightscout code is imediately visible after reloaded (dont need to wait for ios to purge cache or reinstall loop follow to see changes) --- .../ViewControllers/NightScoutViewController.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/LoopFollow/ViewControllers/NightScoutViewController.swift b/LoopFollow/ViewControllers/NightScoutViewController.swift index 8a78abf8..08ade495 100644 --- a/LoopFollow/ViewControllers/NightScoutViewController.swift +++ b/LoopFollow/ViewControllers/NightScoutViewController.swift @@ -43,12 +43,22 @@ class NightscoutViewController: UIViewController { self.webView.uiDelegate = self } - + @objc func reloadWebView(_ sender: UIRefreshControl) { + clearWebCache() // Clear web cache when reloading page by swiping down webView.reload() sender.endRefreshing() } + // New code to Clear web cache + func clearWebCache() { + let dataStore = WKWebsiteDataStore.default() + let date = Date(timeIntervalSince1970: 0) + dataStore.removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), modifiedSince: date) { + print("Web cache cleared.") + } + } + // this handles target=_blank links by opening them in the same view func webView(webView: WKWebView!, createWebViewWithConfiguration configuration: WKWebViewConfiguration!, forNavigationAction navigationAction: WKNavigationAction!, windowFeatures: WKWindowFeatures!) -> WKWebView! { if let frame = navigationAction.targetFrame, From 16f2d41a3a3f132322cc2249edf99a9cd4ca6b2d Mon Sep 17 00:00:00 2001 From: dsnallfot <72826201+dsnallfot@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:07:50 +0100 Subject: [PATCH 2/5] Add yes/no alert (DO you want to clear cache) when refreshing NS webview --- .../NightScoutViewController.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/LoopFollow/ViewControllers/NightScoutViewController.swift b/LoopFollow/ViewControllers/NightScoutViewController.swift index 08ade495..048d1bcb 100644 --- a/LoopFollow/ViewControllers/NightScoutViewController.swift +++ b/LoopFollow/ViewControllers/NightScoutViewController.swift @@ -45,12 +45,23 @@ class NightscoutViewController: UIViewController { } @objc func reloadWebView(_ sender: UIRefreshControl) { - clearWebCache() // Clear web cache when reloading page by swiping down - webView.reload() - sender.endRefreshing() + let alertController = UIAlertController(title: "Clear Web Cache", message: "Do you want to clear the web cache?\nNote: All Nightscout settings will be reverted to defaults!", preferredStyle: .alert) + + alertController.addAction(UIAlertAction(title: "Yes", style: .destructive) { _ in + self.clearWebCache() + self.webView.reload() + sender.endRefreshing() + }) + + alertController.addAction(UIAlertAction(title: "No", style: .cancel) { _ in + self.webView.reload() + sender.endRefreshing() + }) + + present(alertController, animated: true, completion: nil) } - // New code to Clear web cache + // New code to clear web cache func clearWebCache() { let dataStore = WKWebsiteDataStore.default() let date = Date(timeIntervalSince1970: 0) From 021151cbdf0c654f05470f7c99fc125e47acc6b0 Mon Sep 17 00:00:00 2001 From: Marion Barker Date: Wed, 6 Mar 2024 11:28:06 -0800 Subject: [PATCH 3/5] keep cookies in clearWebCache --- LoopFollow/ViewControllers/NightScoutViewController.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/LoopFollow/ViewControllers/NightScoutViewController.swift b/LoopFollow/ViewControllers/NightScoutViewController.swift index 048d1bcb..8fa01bee 100644 --- a/LoopFollow/ViewControllers/NightScoutViewController.swift +++ b/LoopFollow/ViewControllers/NightScoutViewController.swift @@ -64,11 +64,12 @@ class NightscoutViewController: UIViewController { // New code to clear web cache func clearWebCache() { let dataStore = WKWebsiteDataStore.default() + let cacheTypes = Set([WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache]) let date = Date(timeIntervalSince1970: 0) - dataStore.removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), modifiedSince: date) { - print("Web cache cleared.") + dataStore.removeData(ofTypes: cacheTypes, modifiedSince: date) { + print(“Web cache cleared.“) } - } + } // this handles target=_blank links by opening them in the same view func webView(webView: WKWebView!, createWebViewWithConfiguration configuration: WKWebViewConfiguration!, forNavigationAction navigationAction: WKNavigationAction!, windowFeatures: WKWindowFeatures!) -> WKWebView! { From 1f320e78985b484058e4ec56ddb1459cb33a1a0f Mon Sep 17 00:00:00 2001 From: Marion Barker Date: Wed, 6 Mar 2024 11:37:01 -0800 Subject: [PATCH 4/5] fix inadvertent smart quotes --- LoopFollow/ViewControllers/NightScoutViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LoopFollow/ViewControllers/NightScoutViewController.swift b/LoopFollow/ViewControllers/NightScoutViewController.swift index 8fa01bee..ee04ffa7 100644 --- a/LoopFollow/ViewControllers/NightScoutViewController.swift +++ b/LoopFollow/ViewControllers/NightScoutViewController.swift @@ -67,7 +67,7 @@ class NightscoutViewController: UIViewController { let cacheTypes = Set([WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache]) let date = Date(timeIntervalSince1970: 0) dataStore.removeData(ofTypes: cacheTypes, modifiedSince: date) { - print(“Web cache cleared.“) + print("Web cache cleared.") } } From 652470c618c0cbe949fe721abc5b5329b9dde604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Wed, 6 Mar 2024 20:44:07 +0100 Subject: [PATCH 5/5] Remove dialog --- .../NightScoutViewController.swift | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/LoopFollow/ViewControllers/NightScoutViewController.swift b/LoopFollow/ViewControllers/NightScoutViewController.swift index ee04ffa7..19144f5f 100644 --- a/LoopFollow/ViewControllers/NightScoutViewController.swift +++ b/LoopFollow/ViewControllers/NightScoutViewController.swift @@ -45,20 +45,9 @@ class NightscoutViewController: UIViewController { } @objc func reloadWebView(_ sender: UIRefreshControl) { - let alertController = UIAlertController(title: "Clear Web Cache", message: "Do you want to clear the web cache?\nNote: All Nightscout settings will be reverted to defaults!", preferredStyle: .alert) - - alertController.addAction(UIAlertAction(title: "Yes", style: .destructive) { _ in - self.clearWebCache() - self.webView.reload() - sender.endRefreshing() - }) - - alertController.addAction(UIAlertAction(title: "No", style: .cancel) { _ in - self.webView.reload() - sender.endRefreshing() - }) - - present(alertController, animated: true, completion: nil) + self.clearWebCache() + self.webView.reload() + sender.endRefreshing() } // New code to clear web cache