From 1e4e10f847763ff13aafc2d5c4fae9af3b718c78 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Sat, 28 Feb 2026 12:03:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=AE=BE=E7=BD=AE=E7=9A=84vi?= =?UTF-8?q?ew=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- punchnet/Views/Network/NetworkView.swift | 39 ++++++++++++---------- punchnet/Views/Settings/SettingsView.swift | 5 +-- punchnet/punchnetApp.swift | 12 ++++--- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/punchnet/Views/Network/NetworkView.swift b/punchnet/Views/Network/NetworkView.swift index 9888dec..3fde4d4 100644 --- a/punchnet/Views/Network/NetworkView.swift +++ b/punchnet/Views/Network/NetworkView.swift @@ -9,6 +9,7 @@ import SwiftUI struct NetworkView: View { @Environment(UserContext.self) var userContext: UserContext + @Environment(\.openWindow) private var openWindow @State private var networkModel = NetworkModel() @State private var showMode: ShowMode = .resource @@ -41,18 +42,20 @@ struct NetworkView: View { } .frame(width: 320) - // 显示设备和资源选项 - HStack { - Button { - self.showMode = .resource - } label: { - Text("资源") - } - - Button { - self.showMode = .device - } label: { - Text("设备") + if self.networkModel.connectState == .connected { + // 显示设备和资源选项 + HStack { + Button { + self.showMode = .resource + } label: { + Text("资源") + } + + Button { + self.showMode = .device + } label: { + Text("设备") + } } } Spacer() @@ -81,11 +84,13 @@ struct NetworkView: View { .padding(.top, 10) .padding(.leading, 10) .toolbar { - ToolbarItem(placement: .primaryAction) { - Button { - print("clicked") - } label: { - Image(systemName: "gearshape") + if self.networkModel.connectState == .connected { + ToolbarItem(placement: .primaryAction) { + Button { + openWindow(id: "settings") + } label: { + Image(systemName: "gearshape") + } } } } diff --git a/punchnet/Views/Settings/SettingsView.swift b/punchnet/Views/Settings/SettingsView.swift index 817941d..3f86e23 100644 --- a/punchnet/Views/Settings/SettingsView.swift +++ b/punchnet/Views/Settings/SettingsView.swift @@ -8,6 +8,7 @@ import SwiftUI struct SettingsView: View { + @State private var columnVisibility: NavigationSplitViewVisibility = .all @State private var state = SettingsState() @State private var hovering = false @State private var selectedMenu: MenuItem = .accout @@ -21,7 +22,7 @@ struct SettingsView: View { } var body: some View { - NavigationSplitView { + NavigationSplitView(columnVisibility: $columnVisibility) { List(MenuItem.allCases, id: \.self) { menu in HStack(alignment: .center) { Rectangle() @@ -46,7 +47,7 @@ struct SettingsView: View { } } .listStyle(.sidebar) - .border(Color.red) + .frame(minWidth: 180, idealWidth: 200, maxWidth: 250) } detail: { VStack(alignment: .leading, spacing: 0) { diff --git a/punchnet/punchnetApp.swift b/punchnet/punchnetApp.swift index 40245b1..e59a49d 100644 --- a/punchnet/punchnetApp.swift +++ b/punchnet/punchnetApp.swift @@ -48,10 +48,12 @@ struct punchnetApp: App { var body: some Scene { WindowGroup(id: "mainWindow") { RootView() - //NetworkDisconnctedView(state: NetworkState()) + .frame(width: 800, height: 500) .onAppear { // 获取主屏幕的尺寸 - guard let screenFrame = NSScreen.main?.frame else { return } + guard let screenFrame = NSScreen.main?.frame else { + return + } // 获取当前应用的窗口(假设只有一个窗口) NSApplication.shared.windows.forEach { window in @@ -81,10 +83,10 @@ struct punchnetApp: App { .windowResizability(.contentSize) .windowToolbarStyle(.unified) - Window("", id: "abortPunchnet") { - AbortView() - .frame(minWidth: 300, maxWidth: 300, minHeight: 500, maxHeight: 500) + Window("设置", id: "settings") { + SettingsView() } + .defaultSize(width: 800, height: 500) MenuBarExtra("punchnet", image: "logo_32") { VStack {