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 15c92a6 + 9b34fca commit d59bd87
Show file tree
Hide file tree
Showing 24 changed files with 596 additions and 123 deletions.
7 changes: 5 additions & 2 deletions Extension/FilterDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class FilterDataProvider: NEFilterDataProvider {
private var ipc = IPCConnection.shared

override func startFilter(completionHandler: @escaping (Error?) -> Void) {
ipc.providerSay("startFilter")
ipc.providerSay("startFilter 🚛")
let filterSettings = NEFilterSettings(rules: [], defaultAction: .filterData)

apply(filterSettings) { error in
Expand All @@ -17,11 +17,14 @@ class FilterDataProvider: NEFilterDataProvider {
}

override func stopFilter(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
ipc.providerSay("stopFilter")
ipc.providerSay("stopFilter 📢 with reason -> \(reason)")

completionHandler()
}

override func handleNewFlow(_ flow: NEFilterFlow) -> NEFilterNewFlowVerdict {
ipc.providerSay("handleNewFlow")

// Ask the app to prompt the user
// WWDC2019视频中说,这是一个异步的过程
let prompted = ipc.promptUser(flow: flow) { allow in
Expand Down
7 changes: 4 additions & 3 deletions Extension/IPCConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class IPCConnection: NSObject, SuperLog {
return
}

os_log("\(self.t)IPC.register")
os_log("\(self.t)IPC.register 🛫")

let machServiceName = extensionMachServiceName(from: bundle)
let newConnection = NSXPCConnection(machServiceName: machServiceName, options: [])
Expand All @@ -79,15 +79,15 @@ class IPCConnection: NSObject, SuperLog {
newConnection.resume()

guard let providerProxy = newConnection.remoteObjectProxyWithErrorHandler({ registerError in
os_log("Failed to register with the provider: %@", registerError.localizedDescription)
os_log(.error, "Failed to register with the provider: %@", registerError.localizedDescription)
self.currentConnection?.invalidate()
self.currentConnection = nil
completionHandler(false)
}) as? ProviderCommunication else {
fatalError("Failed to create a remote object proxy for the provider")
}

os_log("\(self.t)providerProxy.register")
os_log("\(self.t)providerProxy.register 🛫")
providerProxy.register(completionHandler)
}

Expand All @@ -97,6 +97,7 @@ class IPCConnection: NSObject, SuperLog {
*/
func promptUser(flow: NEFilterFlow, responseHandler:@escaping (Bool) -> Void) -> Bool {
os_log("IPC.promptUser")

guard let connection = currentConnection else {
os_log("Cannot prompt user because the app isn't registered")
return false
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ macOS 连网控制。

<a href="https://cofficlab.github.io/products/travelmode" target="_blank">产品介绍</a>

<a href="https://apps.apple.com/cn/app/travelmode/id6474899051?mt=12" target="_blank">App Store(iOS&macOS)</a>
<a href="https://apps.apple.com/cn/app/travelmode/id6474899051?mt=12" target="_blank">App Store(iOS&macOS)</a>

## 开发

在运行前,有脚本将构建后的APP移动到Application目录下。
42 changes: 41 additions & 1 deletion TravelMode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
F5E3D9CD2D13A86600D9C9D3 /* TileMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9CC2D13A86600D9C9D3 /* TileMessage.swift */; };
F5E3D9CF2D13A89B00D9C9D3 /* PluginProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9CE2D13A89B00D9C9D3 /* PluginProvider.swift */; };
F5E3D9D12D13A8D800D9C9D3 /* StatusBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9D02D13A8D800D9C9D3 /* StatusBar.swift */; };
F5E3D9D32D13BC2400D9C9D3 /* ApprovalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9D22D13BC2400D9C9D3 /* ApprovalView.swift */; };
F5E3D9D52D13BE2C00D9C9D3 /* RunningView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9D42D13BE2C00D9C9D3 /* RunningView.swift */; };
F5E3D9D72D13BEFB00D9C9D3 /* StopView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9D62D13BEFB00D9C9D3 /* StopView.swift */; };
F5E3D9D92D13BFA400D9C9D3 /* BtnStart.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9D82D13BFA400D9C9D3 /* BtnStart.swift */; };
F5E3D9DB2D13C01E00D9C9D3 /* BtnStop.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9DA2D13C01E00D9C9D3 /* BtnStop.swift */; };
F5E3D9DD2D13C34100D9C9D3 /* DisabledView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9DC2D13C34100D9C9D3 /* DisabledView.swift */; };
F5E3D9DF2D13CA7C00D9C9D3 /* UnkownView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9DE2D13CA7C00D9C9D3 /* UnkownView.swift */; };
F5E3D9E22D13D7AD00D9C9D3 /* ExtensionNotReady.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5E3D9E12D13D7AD00D9C9D3 /* ExtensionNotReady.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -130,6 +138,14 @@
F5E3D9CC2D13A86600D9C9D3 /* TileMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileMessage.swift; sourceTree = "<group>"; };
F5E3D9CE2D13A89B00D9C9D3 /* PluginProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginProvider.swift; sourceTree = "<group>"; };
F5E3D9D02D13A8D800D9C9D3 /* StatusBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBar.swift; sourceTree = "<group>"; };
F5E3D9D22D13BC2400D9C9D3 /* ApprovalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApprovalView.swift; sourceTree = "<group>"; };
F5E3D9D42D13BE2C00D9C9D3 /* RunningView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunningView.swift; sourceTree = "<group>"; };
F5E3D9D62D13BEFB00D9C9D3 /* StopView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StopView.swift; sourceTree = "<group>"; };
F5E3D9D82D13BFA400D9C9D3 /* BtnStart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BtnStart.swift; sourceTree = "<group>"; };
F5E3D9DA2D13C01E00D9C9D3 /* BtnStop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BtnStop.swift; sourceTree = "<group>"; };
F5E3D9DC2D13C34100D9C9D3 /* DisabledView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisabledView.swift; sourceTree = "<group>"; };
F5E3D9DE2D13CA7C00D9C9D3 /* UnkownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnkownView.swift; sourceTree = "<group>"; };
F5E3D9E12D13D7AD00D9C9D3 /* ExtensionNotReady.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionNotReady.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -169,6 +185,8 @@
0B09F68C2B3EAD6400B90A59 /* Buttons */ = {
isa = PBXGroup;
children = (
F5E3D9DA2D13C01E00D9C9D3 /* BtnStop.swift */,
F5E3D9D82D13BFA400D9C9D3 /* BtnStart.swift */,
0B09F68D2B3EAD7400B90A59 /* BtnInstall.swift */,
);
path = Buttons;
Expand Down Expand Up @@ -231,15 +249,16 @@
0B3399342B3916B2005CC627 /* View */ = {
isa = PBXGroup;
children = (
F5E3D9E02D13D72800D9C9D3 /* State */,
0B19F0C42B3AB6AB002D8FAC /* AppLine.swift */,
0B40CE412B39646100DC6771 /* AppList.swift */,
0B2551712B3FBFBE0005096C /* AppListSample.swift */,
0B09F68C2B3EAD6400B90A59 /* Buttons */,
0B5B1CA92B385BF30002421E /* ContentView.swift */,
0B1D14A32B3A9ED0005A3D65 /* DatabaseView.swift */,
0B3399372B39277B005CC627 /* EventList.swift */,
F589B5BE2D13A4AA00C7E449 /* InstallView.swift */,
F5E3D9D02D13A8D800D9C9D3 /* StatusBar.swift */,
F5E3D9D62D13BEFB00D9C9D3 /* StopView.swift */,
0B1C33FD2B39C2AA004A5E36 /* Toolbar.swift */,
0B81F59A2B3D008C00F65A4B /* WelcomeView.swift */,
);
Expand Down Expand Up @@ -360,6 +379,19 @@
path = SmartMessage;
sourceTree = "<group>";
};
F5E3D9E02D13D72800D9C9D3 /* State */ = {
isa = PBXGroup;
children = (
F5E3D9E12D13D7AD00D9C9D3 /* ExtensionNotReady.swift */,
F5E3D9DE2D13CA7C00D9C9D3 /* UnkownView.swift */,
F5E3D9DC2D13C34100D9C9D3 /* DisabledView.swift */,
F589B5BE2D13A4AA00C7E449 /* InstallView.swift */,
F5E3D9D42D13BE2C00D9C9D3 /* RunningView.swift */,
F5E3D9D22D13BC2400D9C9D3 /* ApprovalView.swift */,
);
path = State;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -477,16 +509,20 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F5E3D9D72D13BEFB00D9C9D3 /* StopView.swift in Sources */,
0B33993A2B392B20005CC627 /* FilterStatus.swift in Sources */,
F5E3D9D52D13BE2C00D9C9D3 /* RunningView.swift in Sources */,
0B1C33FC2B39C1E7004A5E36 /* SmartApp.swift in Sources */,
0B09F68F2B3EAD8900B90A59 /* BtnInstall.swift in Sources */,
0B19F0C52B3AB6AB002D8FAC /* AppLine.swift in Sources */,
0B33992D2B3911F1005CC627 /* FirewallEvent.swift in Sources */,
0B408A2C2B395A77000E77DB /* NEFilterFlowExt.swift in Sources */,
F5E3D9D32D13BC2400D9C9D3 /* ApprovalView.swift in Sources */,
C4B1415C227BBC0200B26560 /* IPCConnection.swift in Sources */,
0B1D14A22B3A99AC005A3D65 /* AppConfig.swift in Sources */,
0B3399262B3907F6005CC627 /* ContentView.swift in Sources */,
F5E3D9D12D13A8D800D9C9D3 /* StatusBar.swift in Sources */,
F5E3D9DD2D13C34100D9C9D3 /* DisabledView.swift in Sources */,
0B2551742B3FD3C30005096C /* DisplayType.swift in Sources */,
0B2551722B3FBFBE0005096C /* AppListSample.swift in Sources */,
F589B5BF2D13A4AA00C7E449 /* InstallView.swift in Sources */,
Expand All @@ -498,19 +534,23 @@
F5E3D9CF2D13A89B00D9C9D3 /* PluginProvider.swift in Sources */,
0B09F6922B3EB84100B90A59 /* Location.swift in Sources */,
0B09F6852B3E51F900B90A59 /* ExtConfig.swift in Sources */,
F5E3D9DB2D13C01E00D9C9D3 /* BtnStop.swift in Sources */,
0B1D149F2B3A78EC005A3D65 /* AppSetting.swift in Sources */,
0B3399332B391619005CC627 /* RootView.swift in Sources */,
F589B5BD2D13A10700C7E449 /* OSExt.swift in Sources */,
F5E3D9DF2D13CA7C00D9C9D3 /* UnkownView.swift in Sources */,
F5E3D9CD2D13A86600D9C9D3 /* TileMessage.swift in Sources */,
0B33992A2B390D44005CC627 /* EventManager.swift in Sources */,
0B1C33FE2B39C2AA004A5E36 /* Toolbar.swift in Sources */,
0B408A302B39612B000E77DB /* AppHelper.swift in Sources */,
F5E3D9E22D13D7AD00D9C9D3 /* ExtensionNotReady.swift in Sources */,
0B3399272B3907F8005CC627 /* ChannelProvider.swift in Sources */,
0B1D14A72B3AA062005A3D65 /* DebugCommand.swift in Sources */,
0B81F59B2B3D008C00F65A4B /* WelcomeView.swift in Sources */,
0B3399382B39277B005CC627 /* EventList.swift in Sources */,
0B40CE422B39646100DC6771 /* AppList.swift in Sources */,
0B737BB72D12F2AF00712ABA /* SuperEvent.swift in Sources */,
F5E3D9D92D13BFA400D9C9D3 /* BtnStart.swift in Sources */,
F5E3D9C92D13A84500D9C9D3 /* MessageTable.swift in Sources */,
0B3399302B3914EF005CC627 /* AppManager.swift in Sources */,
0B737BB22D12F22500712ABA /* MessageProvider.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?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">
<array/>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@
</ActionContent>
</ExecutionAction>
</PreActions>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<PathRunnable
runnableDebuggingMode = "0"
FilePath = "/Applications/TavelMode.app">
</PathRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C4B45DB422739FFF0050C59B"
BuildableName = "TavelMode.app"
BlueprintName = "TavelMode"
ReferencedContainer = "container:TravelMode.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</MacroExpansion>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "F1D6D06B-DB25-411C-9C25-BCEBE6F7CD9D"
type = "1"
version = "2.0">
</Bucket>
21 changes: 21 additions & 0 deletions TravelMode/Assets.xcassets/NeedApproval-15.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "截屏2024-12-19 10.32.16.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions TravelMode/Bootstrap/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct RootView<Content>: View, SuperLog, SuperEvent where Content: View {
.onReceive(nc.publisher(for: .didStop), perform: onDidStop)
.onReceive(nc.publisher(for: .configurationChanged), perform: onConfigurationChanged)
.onReceive(nc.publisher(for: .needApproval), perform: onNeedApproval)
.onReceive(nc.publisher(for: .willRegisterWithProvider), perform: onWillRegisterWithProvider)
.onReceive(nc.publisher(for: .didRegisterWithProvider), perform: onDidRegisterWithProvider)
}
}

Expand Down Expand Up @@ -90,6 +92,14 @@ extension RootView {
self.m.append("需要用户批准")
}

func onWillRegisterWithProvider(_ n: Notification) {
self.m.append("将要注册系统扩展")
}

func onDidRegisterWithProvider(_ n: Notification) {
self.m.append("注册系统扩展成功")
}

func onDidFailWithError(_ n: Notification) {
guard let error = n.userInfo?["error"] as? Error else {
self.m.append("安装系统扩展失败: 未知错误")
Expand Down
6 changes: 6 additions & 0 deletions TravelMode/Entity/FilterStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ enum FilterStatus {
case notInstalled
case needApproval
case waitingForApproval
case disabled
case extensionNotReady
case error(Error)

var description: String {
Expand All @@ -23,6 +25,10 @@ enum FilterStatus {
"待授权"
case .waitingForApproval:
"请在弹出的对话框中点击“允许”"
case .disabled:
"disabled"
case .extensionNotReady:
"extensionNotReady"
case .error(let error):
"错误: \(error.localizedDescription)"
}
Expand Down
5 changes: 4 additions & 1 deletion TravelMode/Model/AppSetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import Foundation
import SwiftData
import SwiftUI
import OSLog
import MagicKit

@Model
final class AppSetting {
final class AppSetting: SuperLog {
@Transient let emoji = "🦆"

@Attribute(.unique)
var appId: String
var allowed: Bool
Expand Down
Loading

0 comments on commit d59bd87

Please sign in to comment.