feat: 优化应用启动和指引窗口逻辑

添加 LSUIElement 配置使应用不显示在 Dock 中
重构指引窗口显示逻辑,改为直接打开新窗口
移除自动显示的主窗口,改为按需打开
更新菜单图标和背景颜色以匹配系统风格
This commit is contained in:
2025-12-27 19:35:30 +08:00
parent 041a4bb911
commit 37d73db4e5
2 changed files with 27 additions and 21 deletions

View File

@@ -274,6 +274,7 @@
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES; SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
INFOPLIST_KEY_LSUIElement = YES;
}; };
name = Debug; name = Debug;
}; };
@@ -306,6 +307,7 @@
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES; SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
INFOPLIST_KEY_LSUIElement = YES;
}; };
name = Release; name = Release;
}; };

View File

@@ -1,4 +1,5 @@
import SwiftUI import SwiftUI
import AppKit
@main @main
struct PowerBarApp: App { struct PowerBarApp: App {
@@ -25,18 +26,6 @@ struct PowerBarApp: App {
.foregroundColor(appState.isFunctionEnabled ? .green : .gray) .foregroundColor(appState.isFunctionEnabled ? .green : .gray)
} }
} }
//
WindowGroup {
if !hasShownGuide {
GuideView()
.onDisappear {
hasShownGuide = true
}
}
}
.windowStyle(.hiddenTitleBar)
.defaultSize(width: 400, height: 400)
.windowResizability(.contentSize)
} }
} }
@@ -136,7 +125,7 @@ struct MenuContent: View {
set: { _ in appState.toggleLaunchAtLogin() } set: { _ in appState.toggleLaunchAtLogin() }
)) { )) {
HStack { HStack {
Image(systemName: "power.on.circle") Image(systemName: "power.circle")
.frame(width: 20) .frame(width: 20)
Text("开机自动启动") Text("开机自动启动")
} }
@@ -149,12 +138,8 @@ struct MenuContent: View {
// //
Button("查看使用指南") { Button("查看使用指南") {
// //
// 使 AppStorage openGuideWindow()
UserDefaults.standard.set(false, forKey: "hasShownGuide")
//
// macOS
NSAlert.showAlert(title: "使用指南", message: "请重启应用以查看使用指南,或在下次启动时自动显示。")
} }
.buttonStyle(.plain) .buttonStyle(.plain)
.font(.caption) .font(.caption)
@@ -176,10 +161,29 @@ struct MenuContent: View {
.frame(minWidth: 280) .frame(minWidth: 280)
.background( .background(
RoundedRectangle(cornerRadius: 12) RoundedRectangle(cornerRadius: 12)
.fill(Color.white) .fill(Color(.windowBackgroundColor))
.shadow(radius: 4) .shadow(radius: 4)
) )
} }
//
private func openGuideWindow() {
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 400, height: 500),
styleMask: [.titled, .closable, .resizable],
backing: .buffered,
defer: false
)
//
window.title = "PowerBar 使用指南"
window.contentView = NSHostingView(rootView: GuideView())
window.center()
window.makeKeyAndOrderFront(nil)
//
UserDefaults.standard.set(true, forKey: "hasShownGuide")
}
} }
// NSAlert便 // NSAlert便
@@ -344,7 +348,7 @@ struct GuideView: View {
.frame(width: 400, height: 500) .frame(width: 400, height: 500)
.background( .background(
RoundedRectangle(cornerRadius: 12) RoundedRectangle(cornerRadius: 12)
.fill(Color.white) .fill(Color(.windowBackgroundColor))
) )
.shadow(radius: 10) .shadow(radius: 10)
} }