Skip to content

Commit

Permalink
👷 CI: Merge dev by GitOK
Browse files Browse the repository at this point in the history
  • Loading branch information
nookery committed Dec 19, 2024
2 parents 4693996 + 60de2ad commit bc93891
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 28 deletions.
12 changes: 8 additions & 4 deletions TravelMode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
0B1D14982B3A63A3005A3D65 /* BackgroundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1D14972B3A63A3005A3D65 /* BackgroundView.swift */; };
0B1D149C2B3A69F1005A3D65 /* DateExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1D149B2B3A69F1005A3D65 /* DateExt.swift */; };
0B1D149F2B3A78EC005A3D65 /* AppSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1D149E2B3A78EC005A3D65 /* AppSetting.swift */; };
0B1D14A22B3A99AC005A3D65 /* DBConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1D14A12B3A99AC005A3D65 /* DBConfig.swift */; };
0B1D14A22B3A99AC005A3D65 /* AppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1D14A12B3A99AC005A3D65 /* AppConfig.swift */; };
0B1D14A42B3A9ED0005A3D65 /* DatabaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1D14A32B3A9ED0005A3D65 /* DatabaseView.swift */; };
0B1D14A72B3AA062005A3D65 /* DebugCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B1D14A62B3AA062005A3D65 /* DebugCommand.swift */; };
0B2551722B3FBFBE0005096C /* AppListSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2551712B3FBFBE0005096C /* AppListSample.swift */; };
Expand Down Expand Up @@ -50,6 +50,7 @@
C4B1415C227BBC0200B26560 /* IPCConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B1415A227A396500B26560 /* IPCConnection.swift */; };
C4B45DBD2273A0020050C59B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C4B45DBC2273A0020050C59B /* Assets.xcassets */; };
C4B45DDE2273A3450050C59B /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C4B45DDD2273A3450050C59B /* NetworkExtension.framework */; };
F589B5BD2D13A10700C7E449 /* OSExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = F589B5BC2D13A10300C7E449 /* OSExt.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -86,7 +87,7 @@
0B1D14972B3A63A3005A3D65 /* BackgroundView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundView.swift; sourceTree = "<group>"; };
0B1D149B2B3A69F1005A3D65 /* DateExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateExt.swift; sourceTree = "<group>"; };
0B1D149E2B3A78EC005A3D65 /* AppSetting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSetting.swift; sourceTree = "<group>"; };
0B1D14A12B3A99AC005A3D65 /* DBConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBConfig.swift; sourceTree = "<group>"; };
0B1D14A12B3A99AC005A3D65 /* AppConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppConfig.swift; sourceTree = "<group>"; };
0B1D14A32B3A9ED0005A3D65 /* DatabaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseView.swift; sourceTree = "<group>"; };
0B1D14A62B3AA062005A3D65 /* DebugCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugCommand.swift; sourceTree = "<group>"; };
0B2551712B3FBFBE0005096C /* AppListSample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppListSample.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -118,6 +119,7 @@
C4B45DC22273A0020050C59B /* Signing.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Signing.entitlements; sourceTree = "<group>"; };
C4B45DDD2273A3450050C59B /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; };
C4E0DBB42273BEA0005B02F4 /* FilterDataProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterDataProvider.swift; sourceTree = "<group>"; };
F589B5BC2D13A10300C7E449 /* OSExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSExt.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -173,8 +175,9 @@
0B1D14A02B3A999E005A3D65 /* Config */ = {
isa = PBXGroup;
children = (
0B1D14A12B3A99AC005A3D65 /* DBConfig.swift */,
0B1D14A12B3A99AC005A3D65 /* AppConfig.swift */,
0B09F6842B3E51F900B90A59 /* ExtConfig.swift */,
F589B5BC2D13A10300C7E449 /* OSExt.swift */,
);
path = Config;
sourceTree = "<group>";
Expand Down Expand Up @@ -450,7 +453,7 @@
0B33992D2B3911F1005CC627 /* FirewallEvent.swift in Sources */,
0B408A2C2B395A77000E77DB /* NEFilterFlowExt.swift in Sources */,
C4B1415C227BBC0200B26560 /* IPCConnection.swift in Sources */,
0B1D14A22B3A99AC005A3D65 /* DBConfig.swift in Sources */,
0B1D14A22B3A99AC005A3D65 /* AppConfig.swift in Sources */,
0B3399262B3907F6005CC627 /* ContentView.swift in Sources */,
0B2551742B3FD3C30005096C /* DisplayType.swift in Sources */,
0B2551722B3FBFBE0005096C /* AppListSample.swift in Sources */,
Expand All @@ -463,6 +466,7 @@
0B09F6852B3E51F900B90A59 /* ExtConfig.swift in Sources */,
0B1D149F2B3A78EC005A3D65 /* AppSetting.swift in Sources */,
0B3399332B391619005CC627 /* RootView.swift in Sources */,
F589B5BD2D13A10700C7E449 /* OSExt.swift in Sources */,
0B33992A2B390D44005CC627 /* EventManager.swift in Sources */,
0B1C33FE2B39C2AA004A5E36 /* Toolbar.swift in Sources */,
0B408A302B39612B000E77DB /* AppHelper.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion TravelMode/Bootstrap/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct RootView<Content>: View where Content: View {
.environmentObject(appManager)
.environmentObject(channel)
.environmentObject(eventManager)
.modelContainer(DBConfig.container)
.modelContainer(AppConfig.container)
.environmentObject(m)
.frame(minWidth: 500, minHeight: 200)
.toast(isPresenting: $m.showToast, alert: {
Expand Down
2 changes: 1 addition & 1 deletion TravelMode/Commands/DebugCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct DebugCommands: Commands {

CommandMenu("调试") {
Button("打开数据文件夹") {
let folderPath = DBConfig.databaseURL.deletingLastPathComponent()
let folderPath = AppConfig.databaseURL.deletingLastPathComponent()

NSWorkspace.shared.open(folderPath)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwiftData
import SwiftUI
import WebKit

struct DBConfig {
struct AppConfig {
static private var fileManager = FileManager.default
static var dbFileName = "db.sqlite"
static var label = "com.yueyi.TravelMode"
Expand All @@ -16,7 +16,7 @@ struct DBConfig {
}

static var databaseFolder: URL {
DBConfig.databaseURL.deletingLastPathComponent()
AppConfig.databaseURL.deletingLastPathComponent()
}

static var databaseURL: URL {
Expand Down
2 changes: 1 addition & 1 deletion TravelMode/Config/ExtConfig.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

struct ExtConfig {
extension AppConfig {
// Get the Bundle of the system extension.
static var extensionBundle: Bundle = {
let extensionsDirectoryURL = URL(fileURLWithPath: "Contents/Library/SystemExtensions", relativeTo: Bundle.main.bundleURL)
Expand Down
14 changes: 14 additions & 0 deletions TravelMode/Config/OSExt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation
import SwiftUI

extension AppConfig {
static var osVersion: Int {
ProcessInfo.processInfo.operatingSystemVersion.majorVersion
}
}

#Preview("APP") {
RootView {
ContentView()
}.frame(width: 700)
}
15 changes: 7 additions & 8 deletions TravelMode/Entity/SmartApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ struct SmartApp: Identifiable {
self.id = id
self.name = name
if let i = icon {
self.icon = Image(nsImage: i).resizable()
self.icon = AnyView(Image(nsImage: i).resizable())
}
}

init(id: String, name: String, icon: Image? = nil) {
init(id: String, name: String, icon: some View) {
self.id = id
self.name = name
self.icon = nil
if let i = icon {
self.icon = i.resizable()
}
self.icon = AnyView(icon)
}

var id: String
var name: String
var icon: Image? = nil
var icon: AnyView? = nil
var events: [FirewallEvent] = []
var nameView: some View {
Text(name)
Expand Down Expand Up @@ -78,5 +75,7 @@ struct SmartApp: Identifiable {
#Preview("APP") {
RootView(content: {
ContentView()
}).frame(width: 700)
})
.frame(width: 700)
.frame(height: 800)
}
8 changes: 4 additions & 4 deletions TravelMode/Model/AppSetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class AppSetting {
}

static func create(_ id:String, allowed: Bool = true) {
let context = ModelContext(DBConfig.container)
let context = ModelContext(AppConfig.container)
context.insert(AppSetting(appId: id, allowed: allowed))
do {
try context.save()
Expand All @@ -25,7 +25,7 @@ final class AppSetting {
}

static func find(_ id:String) -> AppSetting? {
let context = ModelContext(DBConfig.container)
let context = ModelContext(AppConfig.container)
let predicate = #Predicate<AppSetting> { item in
item.appId == id
}
Expand Down Expand Up @@ -61,7 +61,7 @@ final class AppSetting {
}

static func setDeny(_ id: String) {
let context = ModelContext(DBConfig.container)
let context = ModelContext(AppConfig.container)

let setting = find(id)
if let s = setting {
Expand All @@ -78,7 +78,7 @@ final class AppSetting {
}

static func setAllow(_ id: String) {
let context = ModelContext(DBConfig.container)
let context = ModelContext(AppConfig.container)

let setting = find(id)
if let s = setting {
Expand Down
2 changes: 1 addition & 1 deletion TravelMode/Providers/ChannelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ChannelProvider: NSObject, ObservableObject, SuperLog {
private var ipc = IPCConnection.shared
private var filterManager = NEFilterManager.shared()
private var extensionManager = OSSystemExtensionManager.shared
private var extensionBundle = ExtConfig.extensionBundle
private var extensionBundle = AppConfig.extensionBundle

@Published var error: Error?

Expand Down
36 changes: 32 additions & 4 deletions TravelMode/View/AppListSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,38 @@ import SwiftUI

struct AppListSample: View {
private var apps: [SmartApp] {
[SmartApp(id: "DNS", name: "DNS服务", icon: Image("DNS"))] +
Array(1...100).map({
SmartApp(id: "app-\($0)", name: "APP-\($0)", icon: Image("Unknown"))
})
[
SmartApp(id: "com.apple.Safari", name: "Safari浏览器", icon: Text("🌐")),
SmartApp(id: "com.apple.Maps", name: "地图", icon: Text("🗺️")),
SmartApp(id: "com.apple.MobileSMS", name: "信息", icon: Text("💬")),
SmartApp(id: "com.apple.Mail", name: "邮件", icon: Text("📧")),
SmartApp(id: "com.apple.Photos", name: "照片", icon: Text("🖼️")),
SmartApp(id: "com.apple.iCal", name: "日历", icon: Text("📅")),
SmartApp(id: "com.apple.Notes", name: "备忘录", icon: Text("📝")),
SmartApp(id: "com.apple.reminders", name: "提醒事项", icon: Text("")),
SmartApp(id: "com.apple.Weather", name: "天气", icon: Text("🌤️")),
SmartApp(id: "com.apple.Clock", name: "时钟", icon: Text("🕐")),
SmartApp(id: "com.apple.systempreferences", name: "设置", icon: Text("⚙️")),
SmartApp(id: "com.apple.AppStore", name: "App Store", icon: Text("🏪")),
SmartApp(id: "com.apple.Health", name: "健康", icon: Text("❤️")),
SmartApp(id: "com.apple.Wallet", name: "钱包", icon: Text("👛")),
SmartApp(id: "com.apple.stocks", name: "股市", icon: Text("📈")),
SmartApp(id: "com.apple.Calculator", name: "计算器", icon: Text("🧮")),
SmartApp(id: "com.apple.camera", name: "相机", icon: Text("📸")),
SmartApp(id: "com.apple.FaceTime", name: "FaceTime", icon: Text("📱")),
SmartApp(id: "com.apple.iBooks", name: "图书", icon: Text("📚")),
SmartApp(id: "com.apple.podcasts", name: "播客", icon: Text("🎙️")),
SmartApp(id: "com.apple.Music", name: "音乐", icon: Text("🎵")),
SmartApp(id: "com.apple.TV", name: "电视", icon: Text("📺")),
SmartApp(id: "com.apple.finder", name: "访达", icon: Text("📁")),
SmartApp(id: "com.apple.Home", name: "家庭", icon: Text("🏠")),
SmartApp(id: "com.apple.VoiceMemos", name: "语音备忘录", icon: Text("🎤")),
SmartApp(id: "com.apple.shortcuts", name: "快捷指令", icon: Text("⚡️")),
SmartApp(id: "com.apple.translate", name: "翻译", icon: Text("🌍")),
SmartApp(id: "com.apple.findmy", name: "查找", icon: Text("🔍")),
SmartApp(id: "com.apple.AddressBook", name: "通讯录", icon: Text("👥")),
SmartApp(id: "com.apple.measure", name: "测距仪", icon: Text("📏"))
]
}

var body: some View {
Expand Down
21 changes: 19 additions & 2 deletions TravelMode/View/WelcomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,26 @@ struct WelcomeView: View {
Text("安装系统扩展以继续")
.font(.headline)
.padding(.top, 20)

Text("操作系统版本 \(AppConfig.osVersion)")
.padding(.top, 20)
}.padding(30).background(BackgroundView.type2).cornerRadius(16)
case .needApproval:
Text("请在系统设置中允许运行").font(.title)
Image("NeedApproval").resizable().scaledToFit()
if AppConfig.osVersion < 15 {
Text("请在系统设置中允许运行").font(.title)
Image("NeedApproval").resizable().scaledToFit()
} else {
VStack {
BtnInstall()
Text("安装系统扩展以继续")
.font(.headline)
.padding(.top, 20)

Text("操作系统版本 \(AppConfig.osVersion)")
.padding(.top, 20)
}.padding(30).background(BackgroundView.type2).cornerRadius(16)
}

case .waitingForApproval:
Text("点击“允许”以安装扩展").font(.title)
Image("Ask")
Expand All @@ -46,4 +62,5 @@ struct WelcomeView: View {
RootView {
ContentView()
}
.frame(height: 800)
}

0 comments on commit bc93891

Please sign in to comment.