Compare commits
3 Commits
041a4bb911
...
21bb3131a0
| Author | SHA1 | Date | |
|---|---|---|---|
|
21bb3131a0
|
|||
|
693e4966d4
|
|||
|
37d73db4e5
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -94,5 +94,6 @@ Temporary Items
|
||||
# PowerBar specific
|
||||
PowerBar.xcarchive/
|
||||
ExportedApp/
|
||||
PowerBar.app
|
||||
PowerBar-*.dmg
|
||||
PowerBar.dmg
|
||||
ExportOptions.plist
|
||||
|
||||
20
ExportOptions.plist
Normal file
20
ExportOptions.plist
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>method</key>
|
||||
<string>development</string>
|
||||
<key>signingStyle</key>
|
||||
<string>automatic</string>
|
||||
<key>stripSwiftSymbols</key>
|
||||
<true/>
|
||||
<key>teamID</key>
|
||||
<string>W9MA4VFH3F</string>
|
||||
<key>destination</key>
|
||||
<string>export</string>
|
||||
<key>compileBitcode</key>
|
||||
<false/>
|
||||
<key>thinning</key>
|
||||
<string><none></string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -274,6 +274,7 @@
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
INFOPLIST_KEY_LSUIElement = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -306,6 +307,7 @@
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_UPCOMING_FEATURE_MEMBER_IMPORT_VISIBILITY = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
INFOPLIST_KEY_LSUIElement = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>PowerBar.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,4 +1,5 @@
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
@main
|
||||
struct PowerBarApp: App {
|
||||
@@ -25,24 +26,14 @@ struct PowerBarApp: App {
|
||||
.foregroundColor(appState.isFunctionEnabled ? .green : .gray)
|
||||
}
|
||||
}
|
||||
// 添加主窗口用于显示指引界面
|
||||
WindowGroup {
|
||||
if !hasShownGuide {
|
||||
GuideView()
|
||||
.onDisappear {
|
||||
hasShownGuide = true
|
||||
}
|
||||
}
|
||||
}
|
||||
.windowStyle(.hiddenTitleBar)
|
||||
.defaultSize(width: 400, height: 400)
|
||||
.windowResizability(.contentSize)
|
||||
}
|
||||
}
|
||||
|
||||
// 菜单内容视图
|
||||
struct MenuContent: View {
|
||||
@EnvironmentObject var appState: AppState
|
||||
// 保持对窗口的强引用,避免过早释放
|
||||
@State private var guideWindow: NSWindow?
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
@@ -136,7 +127,7 @@ struct MenuContent: View {
|
||||
set: { _ in appState.toggleLaunchAtLogin() }
|
||||
)) {
|
||||
HStack {
|
||||
Image(systemName: "power.on.circle")
|
||||
Image(systemName: "power.circle")
|
||||
.frame(width: 20)
|
||||
Text("开机自动启动")
|
||||
}
|
||||
@@ -149,12 +140,8 @@ struct MenuContent: View {
|
||||
|
||||
// 显示指引界面选项
|
||||
Button("查看使用指南") {
|
||||
// 这里需要实现显示指引界面的逻辑
|
||||
// 我们可以使用 AppStorage 来控制指引界面的显示
|
||||
UserDefaults.standard.set(false, forKey: "hasShownGuide")
|
||||
// 重启应用或打开新窗口显示指引界面
|
||||
// 由于 macOS 应用的限制,我们可以提示用户重新启动应用查看指引
|
||||
NSAlert.showAlert(title: "使用指南", message: "请重启应用以查看使用指南,或在下次启动时自动显示。")
|
||||
// 直接打开指引窗口
|
||||
openGuideWindow()
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.font(.caption)
|
||||
@@ -176,10 +163,49 @@ struct MenuContent: View {
|
||||
.frame(minWidth: 280)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(Color.white)
|
||||
.fill(Color(.windowBackgroundColor))
|
||||
.shadow(radius: 4)
|
||||
)
|
||||
}
|
||||
|
||||
// 打开指引窗口
|
||||
private func openGuideWindow() {
|
||||
// 如果窗口已存在,直接显示
|
||||
if let existingWindow = guideWindow {
|
||||
existingWindow.makeKeyAndOrderFront(nil)
|
||||
return
|
||||
}
|
||||
|
||||
// 创建新窗口
|
||||
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")
|
||||
|
||||
// 保存窗口引用
|
||||
guideWindow = window
|
||||
|
||||
// 添加窗口关闭通知监听
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: NSWindow.willCloseNotification,
|
||||
object: window,
|
||||
queue: nil
|
||||
) { _ in
|
||||
// 窗口关闭时清除引用
|
||||
guideWindow = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 扩展 NSAlert,添加一个便捷方法来显示警报
|
||||
@@ -344,7 +370,7 @@ struct GuideView: View {
|
||||
.frame(width: 400, height: 500)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(Color.white)
|
||||
.fill(Color(.windowBackgroundColor))
|
||||
)
|
||||
.shadow(radius: 10)
|
||||
}
|
||||
|
||||
83
build_and_package.sh
Executable file
83
build_and_package.sh
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
# PowerBar 打包脚本
|
||||
# 用于构建应用程序并创建DMG安装包
|
||||
|
||||
# 设置变量
|
||||
PROJECT_NAME="PowerBar"
|
||||
SCHEME="PowerBar"
|
||||
CONFIGURATION="Release"
|
||||
VERSION="1.0.0"
|
||||
|
||||
echo "=== PowerBar 打包脚本 v$VERSION ==="
|
||||
|
||||
# 1. 清理之前的构建产物和缓存
|
||||
echo "\n1. 清理之前的构建产物和缓存..."
|
||||
rm -rf "$PROJECT_NAME.app"
|
||||
rm -rf "$PROJECT_NAME-$VERSION.dmg"
|
||||
rm -rf "build"
|
||||
rm -rf "~/Library/Developer/Xcode/DerivedData/$PROJECT_NAME-*"
|
||||
rm -rf "$PROJECT_NAME.xcodeproj/xcuserdata"
|
||||
rm -rf "$PROJECT_NAME.xcodeproj/project.xcworkspace/xcuserdata"
|
||||
|
||||
# 2. 执行Xcode清理
|
||||
echo "\n2. 执行Xcode清理..."
|
||||
xcodebuild -scheme "$SCHEME" -configuration "$CONFIGURATION" clean
|
||||
|
||||
# 3. 直接构建应用程序
|
||||
echo "\n3. 构建应用程序..."
|
||||
xcodebuild -scheme "$SCHEME" -configuration "$CONFIGURATION" -derivedDataPath "build" build
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "构建失败!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. 复制应用程序到当前目录
|
||||
echo "\n4. 复制应用程序到当前目录..."
|
||||
cp -R "build/Build/Products/$CONFIGURATION/$PROJECT_NAME.app" .
|
||||
|
||||
# 5. 验证应用程序
|
||||
echo "\n5. 验证应用程序..."
|
||||
if [ -d "$PROJECT_NAME.app" ]; then
|
||||
echo "应用程序构建成功:$PROJECT_NAME.app"
|
||||
else
|
||||
echo "应用程序构建失败!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 6. 创建DMG安装包
|
||||
echo "\n6. 创建DMG安装包..."
|
||||
|
||||
# 创建临时目录用于构建DMG
|
||||
temp_dmg_dir="temp_dmg"
|
||||
rm -rf "$temp_dmg_dir"
|
||||
mkdir -p "$temp_dmg_dir"
|
||||
|
||||
# 复制应用程序到临时目录
|
||||
cp -R "$PROJECT_NAME.app" "$temp_dmg_dir/"
|
||||
|
||||
# 创建Applications快捷方式
|
||||
ln -s /Applications "$temp_dmg_dir/Applications"
|
||||
|
||||
# 创建DMG
|
||||
hdiutil create -volname "$PROJECT_NAME-$VERSION" -srcfolder "$temp_dmg_dir" -ov -format UDZO "$PROJECT_NAME-$VERSION.dmg"
|
||||
|
||||
# 7. 清理临时文件
|
||||
echo "\n7. 清理临时文件..."
|
||||
rm -rf "$temp_dmg_dir"
|
||||
rm -rf "build"
|
||||
|
||||
# 8. 验证DMG
|
||||
echo "\n8. 验证DMG..."
|
||||
if [ -f "$PROJECT_NAME-$VERSION.dmg" ]; then
|
||||
echo "DMG创建成功:$PROJECT_NAME-$VERSION.dmg"
|
||||
echo "文件大小:$(du -h "$PROJECT_NAME-$VERSION.dmg" | cut -f1)"
|
||||
else
|
||||
echo "DMG创建失败!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "\n=== 打包完成! ==="
|
||||
echo "应用程序:$PROJECT_NAME.app"
|
||||
echo "安装包:$PROJECT_NAME-$VERSION.dmg"
|
||||
Reference in New Issue
Block a user