mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-24 23:36:05 +00:00
Fix router address button
This commit is contained in:
1 parent
c18a240ab3
commit
6ea0782565
3 files changed
+56
-29
No files matched your search
+21
-19
@@ -205,16 +205,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
|||||||
|
|
||||||
|
|
||||||
func openAlert(type: AlertType) {
|
func openAlert(type: AlertType) {
|
||||||
|
DispatchQueue.main.async { [self] in
|
||||||
// Create an NSWindow to host the SwiftUI view
|
|
||||||
let alertWindow = NSWindow(
|
// Create an NSWindow to host the SwiftUI view
|
||||||
contentRect: NSRect(x: 0, y: 0, width: issueViewWidth, height: issueViewHeight),
|
let alertWindow = NSWindow(
|
||||||
styleMask: [.titled, .closable],
|
contentRect: NSRect(x: 0, y: 0, width: issueViewWidth, height: issueViewHeight),
|
||||||
backing: .buffered,
|
styleMask: [.titled, .closable],
|
||||||
defer: false
|
backing: .buffered,
|
||||||
)
|
defer: false
|
||||||
|
)
|
||||||
switch type {
|
|
||||||
|
switch type {
|
||||||
case .ApIsolation:
|
case .ApIsolation:
|
||||||
apIsolationAlertWindow = alertWindow
|
apIsolationAlertWindow = alertWindow
|
||||||
alertWindow.contentView = NSHostingView(rootView: ApIsolationIssueView())
|
alertWindow.contentView = NSHostingView(rootView: ApIsolationIssueView())
|
||||||
@@ -224,16 +225,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
|
|||||||
case .Firewall:
|
case .Firewall:
|
||||||
firewallAlertWindow = alertWindow
|
firewallAlertWindow = alertWindow
|
||||||
alertWindow.contentView = NSHostingView(rootView: FirewallIssueView())
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,27 +17,33 @@ struct ApIsolationIssueView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
||||||
IssueView(image: .router, header: "ApIsolationHeader".localized(), description: "ApIsolationDescription".localized(), actionLabel: "ApIsolationAction".localized()) {
|
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 {
|
DispatchQueue.main.async {
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
alert.alertStyle = .critical
|
alert.alertStyle = .critical
|
||||||
|
|
||||||
alert.messageText = "ApIsolationFindRouterFailedHeader".localized()
|
alert.messageText = "ApIsolationFindRouterFailedHeader".localized()
|
||||||
alert.informativeText = "ApIsolationFindRouterFailedDescription".localized()
|
alert.informativeText = "ApIsolationFindRouterFailedDescription".localized()
|
||||||
|
|
||||||
alert.addButton(withTitle: "CloseAlert".localized())
|
alert.addButton(withTitle: "CloseAlert".localized())
|
||||||
|
|
||||||
let _ = alert.runModal()
|
alert.runModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ struct IssueView: View {
|
|||||||
let description: String
|
let description: String
|
||||||
|
|
||||||
var actionLabel: String? = nil
|
var actionLabel: String? = nil
|
||||||
var action: (() -> Void)? = nil
|
var action: (() async -> Void)? = nil
|
||||||
|
|
||||||
|
@State var isLoading = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
||||||
@@ -67,8 +69,25 @@ struct IssueView: View {
|
|||||||
|
|
||||||
if let actionLabel = actionLabel, let action = action {
|
if let actionLabel = actionLabel, let action = action {
|
||||||
Button(actionLabel) {
|
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)
|
.padding(.bottom, 30)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user