1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-10 13:00:07 +02:00

👌 Reinstate UI busy for secure, add fake delay

This commit is contained in:
2022-12-13 23:45:19 +01:00
parent a696a9a386
commit e34dadcb9b
2 changed files with 39 additions and 31 deletions

View File

@@ -68,43 +68,45 @@ extension DomainListVC {
@objc func toggleSecure() { @objc func toggleSecure() {
if selected is ValetSite { if selected is ValetSite {
Task { await toggleSecureForSite() } Task { await toggleSecure(site: selected as! ValetSite) }
} else { }
Task { await toggleSecureForProxy() }
if selected is ValetProxy {
Task { await toggleSecure(proxy: selected as! ValetProxy) }
} }
} }
func toggleSecureForProxy() async { func toggleSecure(proxy: ValetProxy) async {
guard let proxy = selectedProxy else { return } waitAndExecute {
do {
do { // Recreate proxy as secure or unsecured proxy
// Recreate proxy as secure or unsecured proxy try await proxy.toggleSecure()
try await proxy.toggleSecure() // Send a notification about the new status (if applicable)
// Send a notification about the new status (if applicable) self.notifyAboutModifiedSecureStatus(domain: proxy.domain, secured: proxy.secured)
self.notifyAboutModifiedSecureStatus(domain: proxy.domain, secured: proxy.secured) // Reload the UI (do this last so we don't invalidate the proxy)
// Reload the UI (do this last so we don't invalidate the proxy) self.reloadSelectedRow()
self.reloadSelectedRow() } catch {
} catch { // Notify the user about a failed command
// Notify the user about a failed command let error = error as! ValetInteractionError
let error = error as! ValetInteractionError self.notifyAboutFailedSecureStatus(command: error.command)
self.notifyAboutFailedSecureStatus(command: error.command) }
} }
} }
func toggleSecureForSite() async { func toggleSecure(site: ValetSite) async {
guard let site = selectedSite else { return } waitAndExecute {
do {
do { // Instruct Valet to secure or unsecure a site
// Instruct Valet to secure or unsecure a site try await site.toggleSecure()
try await site.toggleSecure() // Send a notification about the new status (if applicable)
// Send a notification about the new status (if applicable) self.notifyAboutModifiedSecureStatus(domain: site.name, secured: site.secured)
self.notifyAboutModifiedSecureStatus(domain: site.name, secured: site.secured) // Reload the UI (do this last so we don't invalidate the site)
// Reload the UI (do this last so we don't invalidate the proxy) self.reloadSelectedRow()
self.reloadSelectedRow() } catch {
} catch { // Notify the user about a failed command
// Notify the user about a failed command let error = error as! ValetInteractionError
let error = error as! ValetInteractionError self.notifyAboutFailedSecureStatus(command: error.command)
self.notifyAboutFailedSecureStatus(command: error.command) }
} }
} }

View File

@@ -83,21 +83,27 @@ class ValetInteractor {
} }
class FakeValetInteractor: ValetInteractor { class FakeValetInteractor: ValetInteractor {
var delayTime: TimeInterval = 1.0
override func toggleSecure(proxy: ValetProxy) async throws { override func toggleSecure(proxy: ValetProxy) async throws {
await delay(seconds: delayTime)
proxy.secured = !proxy.secured proxy.secured = !proxy.secured
} }
override func toggleSecure(site: ValetSite) async throws { override func toggleSecure(site: ValetSite) async throws {
await delay(seconds: delayTime)
site.secured = !site.secured site.secured = !site.secured
} }
override func unlink(site: ValetSite) async throws { override func unlink(site: ValetSite) async throws {
await delay(seconds: delayTime)
if let scanner = ValetScanners.siteScanner as? FakeSiteScanner { if let scanner = ValetScanners.siteScanner as? FakeSiteScanner {
scanner.fakes.removeAll { $0 === site } scanner.fakes.removeAll { $0 === site }
} }
} }
override func remove(proxy: ValetProxy) async throws { override func remove(proxy: ValetProxy) async throws {
await delay(seconds: delayTime)
#warning("A fake proxy scanner needs to be added") #warning("A fake proxy scanner needs to be added")
} }
} }