Fix router address button

This commit is contained in:
Leon Böttger committed 2025-05-15 17:55:52 +02:00
1 parent c18a240ab3
commit 6ea0782565
3 files changed
+56 -29

No files matched your search

+21 -19
View File
@@ -205,16 +205,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
func openAlert(type: AlertType) {
// Create an NSWindow to host the SwiftUI view
let alertWindow = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: issueViewWidth, height: issueViewHeight),
styleMask: [.titled, .closable],
backing: .buffered,
defer: false
)
switch type {
DispatchQueue.main.async { [self] in
// Create an NSWindow to host the SwiftUI view
let alertWindow = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: issueViewWidth, height: issueViewHeight),
styleMask: [.titled, .closable],
backing: .buffered,
defer: false
)
switch type {
case .ApIsolation:
apIsolationAlertWindow = alertWindow
alertWindow.contentView = NSHostingView(rootView: ApIsolationIssueView())
@@ -224,16 +225,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
case .Firewall:
firewallAlertWindow = alertWindow
alertWindow.contentView = NSHostingView(rootView: FirewallIssueView())
}
alertWindow.title = "QuickDrop"
alertWindow.center()
alertWindow.isReleasedWhenClosed = false
alertWindow.setFrameAutosaveName(type.rawValue)
NSApp.activate(ignoringOtherApps: true)
alertWindow.makeKeyAndOrderFront(nil)
alertWindow.level = .normal
}
alertWindow.title = "QuickDrop"
alertWindow.center()
alertWindow.isReleasedWhenClosed = false
alertWindow.setFrameAutosaveName(type.rawValue)
NSApp.activate(ignoringOtherApps: true)
alertWindow.makeKeyAndOrderFront(nil)
alertWindow.level = .normal
}
+14 -8
View File
@@ -17,27 +17,33 @@ struct ApIsolationIssueView: View {
var body: some View {
IssueView(image: .router, header: "ApIsolationHeader".localized(), description: "ApIsolationDescription".localized(), actionLabel: "ApIsolationAction".localized()) {
openRouterSettingsPage()
await openRouterSettingsPage()
}
}
}
fileprivate let routerCheckQueue = DispatchQueue(label: "routerCheckQueue")
func openRouterSettingsPage() {
guard let routerIP = getDefaultGatewayIP() else {
func openRouterSettingsPage() async {
let routerIP: String? = await withCheckedContinuation { continuation in
DispatchQueue.global(qos: .userInitiated).async {
let ip = getDefaultGatewayIP()
continuation.resume(returning: ip)
}
}
guard let routerIP else {
DispatchQueue.main.async {
let alert = NSAlert()
alert.alertStyle = .critical
alert.messageText = "ApIsolationFindRouterFailedHeader".localized()
alert.informativeText = "ApIsolationFindRouterFailedDescription".localized()
alert.addButton(withTitle: "CloseAlert".localized())
let _ = alert.runModal()
alert.runModal()
}
return
}
+21 -2
View File
@@ -20,7 +20,9 @@ struct IssueView: View {
let description: String
var actionLabel: String? = nil
var action: (() -> Void)? = nil
var action: (() async -> Void)? = nil
@State var isLoading = false
var body: some View {
@@ -67,8 +69,25 @@ struct IssueView: View {
if let actionLabel = actionLabel, let action = action {
Button(actionLabel) {
action()
withAnimation {
isLoading = true
}
Task {
await action()
withAnimation {
isLoading = false
}
}
}
.opacity(isLoading ? 0 : 1)
.overlay(
ProgressView()
.opacity(isLoading ? 1 : 0)
.scaleEffect(0.7)
)
.padding(.bottom, 30)
}
}