Skip to content

Commit

Permalink
优化列表
Browse files Browse the repository at this point in the history
  • Loading branch information
nookery committed Dec 26, 2023
1 parent dad5439 commit 8bcc73f
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 43 deletions.
4 changes: 4 additions & 0 deletions TravelMode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0B19F0C52B3AB6AB002D8FAC /* AppLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B19F0C42B3AB6AB002D8FAC /* AppLine.swift */; };
0B1C33FC2B39C1E7004A5E36 /* SmartApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1C33FB2B39C1E7004A5E36 /* SmartApp.swift */; };
0B1C33FE2B39C2AA004A5E36 /* Toolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1C33FD2B39C2AA004A5E36 /* Toolbar.swift */; };
0B1D14982B3A63A3005A3D65 /* BackgroundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1D14972B3A63A3005A3D65 /* BackgroundView.swift */; };
Expand Down Expand Up @@ -63,6 +64,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0B19F0C42B3AB6AB002D8FAC /* AppLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLine.swift; sourceTree = "<group>"; };
0B1C33FB2B39C1E7004A5E36 /* SmartApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartApp.swift; sourceTree = "<group>"; };
0B1C33FD2B39C2AA004A5E36 /* Toolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toolbar.swift; sourceTree = "<group>"; };
0B1D14972B3A63A3005A3D65 /* BackgroundView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -184,6 +186,7 @@
children = (
0B5B1CA92B385BF30002421E /* ContentView.swift */,
0B3399372B39277B005CC627 /* EventList.swift */,
0B19F0C42B3AB6AB002D8FAC /* AppLine.swift */,
0B40CE412B39646100DC6771 /* AppList.swift */,
0B1C33FD2B39C2AA004A5E36 /* Toolbar.swift */,
0B1D14A32B3A9ED0005A3D65 /* DatabaseView.swift */,
Expand Down Expand Up @@ -382,6 +385,7 @@
files = (
0B33993A2B392B20005CC627 /* FilterStatus.swift in Sources */,
0B1C33FC2B39C1E7004A5E36 /* SmartApp.swift in Sources */,
0B19F0C52B3AB6AB002D8FAC /* AppLine.swift in Sources */,
0B33992D2B3911F1005CC627 /* FirewallEvent.swift in Sources */,
0B408A2C2B395A77000E77DB /* NEFilterFlowExt.swift in Sources */,
C4B1415C227BBC0200B26560 /* IPCConnection.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions TravelMode/Bootstrap/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct RootView<Content>: View where Content: View {
.environmentObject(Channel())
.environmentObject(EventManager())
.modelContainer(DBConfig.container)
.frame(minWidth: 500, minHeight: 200)
}
}

Expand Down
62 changes: 62 additions & 0 deletions TravelMode/View/AppLine.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import SwiftUI

struct AppLine: View {
var app: SmartApp

@State private var hovering: Bool = false

private var background: some View {
ZStack {
if hovering {
BackgroundView.type1.opacity(0.4)
} else {
if !AppSetting.shouldAllow(app.id) {
Color.red.opacity(0.1)
}
}
}
}

var body: some View {
HStack {
app.icon.frame(width: 40, height: 40)

VStack(alignment: .leading) {
Text(app.name)
HStack(alignment: .top) {
Text("\(app.events.count)").font(.callout)
Text(app.id)
}
}

Spacer()

if hovering {
if AppSetting.shouldAllow(app.id) {
Button("禁止") {
AppSetting.setDeny(app.id)
}
} else {
Button("允许") {
AppSetting.setAllow(app.id)
}
}
}
}
.padding(.vertical, 5)
.padding(.horizontal, 10)
.background(background)
.scaleEffect(hovering ? 1 : 1)
.onHover(perform: { hovering in
self.hovering = hovering
})
.frame(height: 50)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}

#Preview {
RootView {
ContentView()
}
}
37 changes: 7 additions & 30 deletions TravelMode/View/AppList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,17 @@ struct AppList: View {
}

var body: some View {
VStack {
Table(appsVisible, columns: {
TableColumn("名称") { smartApp in
HStack {
smartApp.icon.frame(width: 33)
smartApp.nameView
}
}
TableColumn("ID", value: \.id)
TableColumn("事件") { app in
Text("\(app.events.count)")
}
TableColumn("操作") { i in
if AppSetting.shouldAllow(i.id) {
HStack {
Image("dot_green").scaleEffect(0.5)
Button("禁止") {
AppSetting.setDeny(i.id)
}
}
} else {
HStack {
Image("dot_red").scaleEffect(0.5)
Button("允许") {
AppSetting.setAllow(i.id)
}
}
}
ScrollView {
VStack(spacing: 0) {
ForEach(appsVisible) { app in
AppLine(app: app)
Divider()
}
})
}
}
.background(Color.white.opacity(0.95))
.onAppear {
apps = SmartApp.appList

onNewEvent()
}
}
Expand Down
4 changes: 2 additions & 2 deletions TravelMode/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ struct ContentView: View {
@EnvironmentObject private var channel: Channel

var body: some View {
VStack {
VStack(spacing: 0) {
VSplitView {
AppList()
if app.logVisible {
EventList().shadow(radius: 10)
}
}
}
.background(BackgroundView.forest)
.background(BackgroundView.type2A)
.onAppear {
channel.viewWillAppear()
EventManager().onFilterStatusChanged({
Expand Down
22 changes: 12 additions & 10 deletions TravelMode/View/Toolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ struct Toolbar: View {

var body: some View {
HStack {
Button("数据库") {
app.databaseVisible.toggle()
}
.popover(isPresented: $app.databaseVisible, arrowEdge: .bottom) {
DatabaseView()
.frame(width: 500, height: 500)
.background(BackgroundView.type1)
.cornerRadius(10)
}
// Button("数据库") {
// app.databaseVisible.toggle()
// }
// .popover(isPresented: $app.databaseVisible, arrowEdge: .bottom) {
// DatabaseView()
// .frame(width: 500, height: 500)
// .background(BackgroundView.type1)
// .cornerRadius(10)
// }

if app.logVisible {
Button("隐藏日志") {
Expand Down Expand Up @@ -51,5 +51,7 @@ struct Toolbar: View {
}

#Preview {
Toolbar()
RootView {
ContentView()
}
}
2 changes: 1 addition & 1 deletion TravelMode/ViewModel/AppManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AppManager: ObservableObject {
@Published var status: FilterStatus = .indeterminate
@Published var events: [FirewallEvent] = []
@Published var logVisible: Bool = false
@Published var databaseVisible: Bool = false
@Published var dbVisible: Bool = false

func appendEvent(_ e: FirewallEvent) {
self.events.append(e)
Expand Down

0 comments on commit 8bcc73f

Please sign in to comment.