Skip to content

Commit

Permalink
Update project dependencies, enhance app structure, and improve UI co…
Browse files Browse the repository at this point in the history
…mponents

- Updated .package.resolved to change the originHash and add the Atlantis package for enhanced development capabilities.
- Refactored Project.swift to organize dependencies into base and development categories, improving clarity and maintainability.
- Enhanced V2BarApp to initialize Atlantis in debug mode and added an AppDelegate for keyboard event handling.
- Adjusted ContentView to increase the minimum height of NotificationsView for better layout.
- Removed unnecessary task modifiers from NotificationsView and UserProfileView to streamline the code.

These changes improve the project's dependency management, app structure, and user interface consistency.
  • Loading branch information
ygsgdbd committed Dec 12, 2024
1 parent 430e2b6 commit 02a7794
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 41 deletions.
11 changes: 10 additions & 1 deletion .package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "c455e178606d6588bc598ac22db93aaaee67ad2c84b9aebbfe05ea14bfcd3614",
"originHash" : "94f901ff49878d5b5de804979da77afbb800aabc6ee89ef185a57c34110d5d40",
"pins" : [
{
"identity" : "alamofire",
Expand All @@ -10,6 +10,15 @@
"version" : "5.10.2"
}
},
{
"identity" : "atlantis",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ProxymanApp/atlantis",
"state" : {
"revision" : "7246950a6a36454ed1d7830166284f202dc14ad2",
"version" : "1.26.0"
}
},
{
"identity" : "defaults",
"kind" : "remoteSourceControl",
Expand Down
99 changes: 66 additions & 33 deletions Project.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
import ProjectDescription

// 基础依赖
let baseDependencies: [TargetDependency] = [
.package(product: "Alamofire"),
.package(product: "SwiftUIX"),
.package(product: "SwifterSwift"),
.package(product: "Defaults")
]

// 开发环境依赖
let developmentDependencies: [TargetDependency] = baseDependencies + [
.package(product: "Atlantis")
]

let baseSettings = Settings.settings(
base: [
"SWIFT_VERSION": "5.9",
"DEVELOPMENT_LANGUAGE": "zh-Hans"
],
configurations: [
.debug(name: "Debug"),
.release(name: "Release")
]
)

let baseInfoPlist: [String: Plist.Value] = [
"LSUIElement": .boolean(true),
"CFBundleDevelopmentRegion": .string("zh-Hans"),
"NSHumanReadableCopyright": .string("Copyright © 2024 ygsgdbd. All rights reserved."),
"CFBundleShortVersionString": .string("1.0.0"),
"CFBundleVersion": .string("1"),
"NSAppTransportSecurity": .dictionary([
"NSAllowsArbitraryLoads": .boolean(false)
]),
"NSNetworkingUsageDescription": .string("V2Bar 需要访问网络以获取内容")
]

// 开发环境额外的 Info.plist 配置
let developmentInfoPlist: [String: Plist.Value] = baseInfoPlist.merging([
"NSLocalNetworkUsageDescription": .string("Atlantis uses Bonjour Service to send your recorded traffic to Proxyman app."),
"NSBonjourServices": .array([
.string("_Proxyman._tcp")
])
]) { (_, new) in new }

let project = Project(
name: "V2Bar",
options: .options(
Expand All @@ -10,52 +54,41 @@ let project = Project(
.remote(url: "https://github.com/Alamofire/Alamofire", requirement: .upToNextMajor(from: "5.10.2")),
.remote(url: "https://github.com/SwiftUIX/SwiftUIX", requirement: .upToNextMajor(from: "0.2.3")),
.remote(url: "https://github.com/SwifterSwift/SwifterSwift", requirement: .upToNextMajor(from: "7.0.0")),
.remote(url: "https://github.com/sindresorhus/Defaults", requirement: .upToNextMajor(from: "9.0.0"))
.remote(url: "https://github.com/sindresorhus/Defaults", requirement: .upToNextMajor(from: "9.0.0")),
.remote(url: "https://github.com/ProxymanApp/atlantis", requirement: .upToNextMajor(from: "1.26.0"))
],
settings: .settings(
base: [
"SWIFT_VERSION": "5.9",
"DEVELOPMENT_LANGUAGE": "zh-Hans"
],
configurations: [
.debug(name: "Debug"),
.release(name: "Release")
]
),
settings: baseSettings,
targets: [
// 发布版本 Target
.target(
name: "V2Bar",
destinations: .macOS,
product: .app,
bundleId: "top.ygsgdbd.V2Bar",
deploymentTargets: .macOS("13.0"),
infoPlist: .extendingDefault(with: [
"LSUIElement": true,
"CFBundleDevelopmentRegion": "zh-Hans",
"NSHumanReadableCopyright": "Copyright © 2024 ygsgdbd. All rights reserved.",
"CFBundleShortVersionString": "1.0.0",
"CFBundleVersion": "1",

// 网络安全配置 - 允许所有 HTTPS 连接
"NSAppTransportSecurity": [
"NSAllowsArbitraryLoads": false // 只允许 HTTPS 连接
],

// 网络权限描述
"NSNetworkingUsageDescription": "V2Bar 需要访问网络以获取内容"
]),
infoPlist: .extendingDefault(with: baseInfoPlist),
sources: ["V2Bar/Sources/**"],
resources: ["V2Bar/Resources/**"],
dependencies: baseDependencies,
settings: baseSettings
),
// 开发版本 Target
.target(
name: "V2Bar-Dev",
destinations: .macOS,
product: .app,
bundleId: "top.ygsgdbd.V2Bar.dev",
deploymentTargets: .macOS("13.0"),
infoPlist: .extendingDefault(with: developmentInfoPlist),
sources: ["V2Bar/Sources/**"],
resources: ["V2Bar/Resources/**"],
dependencies: [
.package(product: "Alamofire"),
.package(product: "SwiftUIX"),
.package(product: "SwifterSwift"),
.package(product: "Defaults")
],
dependencies: developmentDependencies,
settings: .settings(
base: [
"SWIFT_VERSION": "5.9",
"DEVELOPMENT_LANGUAGE": "zh-Hans",
"SWIFT_VERSION": "5.9"
"OTHER_SWIFT_FLAGS": "-D DEBUG",
"OTHER_LDFLAGS": "$(inherited) -ObjC"
],
configurations: [
.debug(name: "Debug"),
Expand Down
2 changes: 1 addition & 1 deletion V2Bar/Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ContentView: View {
Divider()

NotificationsView()
.minHeight(280)
.minHeight(320)

Divider()

Expand Down
36 changes: 36 additions & 0 deletions V2Bar/Sources/V2BarApp.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import SwiftUI
import AppKit

#if DEBUG
import Atlantis
#endif

@main
struct V2BarApp: App {
@NSApplicationDelegateAdaptor private var appDelegate: AppDelegate

init() {
#if DEBUG
Atlantis.start()
#endif
}

var body: some Scene {
MenuBarExtra {
Expand All @@ -13,4 +25,28 @@ struct V2BarApp: App {
}
.menuBarExtraStyle(.window)
}
}

class AppDelegate: NSObject, NSApplicationDelegate {
private var keyMonitor: Any?

func applicationDidFinishLaunching(_ notification: Notification) {
// 监听键盘事件
keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in
if event.keyCode == 53 { // ESC 键
if let window = NSApplication.shared.windows.first(where: { $0.isKeyWindow }) {
window.close()
return nil // 事件已处理
}
}
return event
}
}

func applicationWillTerminate(_ notification: Notification) {
// 清理监听器
if let monitor = keyMonitor {
NSEvent.removeMonitor(monitor)
}
}
}
3 changes: 0 additions & 3 deletions V2Bar/Sources/Views/NotificationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ struct NotificationsView: View {
.padding(.vertical, 12)
}
}
.task {
await viewModel.fetchNotifications()
}
}

private var notificationsList: some View {
Expand Down
3 changes: 0 additions & 3 deletions V2Bar/Sources/Views/UserProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ struct UserProfileView: View {
.padding(.vertical, 12)
}
}
.task {
await viewModel.fetchProfile()
}
}

@ViewBuilder
Expand Down

0 comments on commit 02a7794

Please sign in to comment.