Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation URL #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions ApplicationLibrary/Views/Setting/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,52 @@ public struct SettingView: View {
Task {
do {
if let result = try await SystemExtension.install(forceUpdate: true) {
if result == .willCompleteAfterReboot {
alert = Alert(errorMessage: "Need reboot")
switch result {
case .completed:
alert = Alert(
title: Text("Update"),
message: Text("System Extension updated."),
dismissButton: .default(Text("Ok")) {}
)
case .willCompleteAfterReboot:
alert = Alert(
title: Text("Update"),
message: Text("Reboot required."),
dismissButton: .default(Text("Ok")) {}
)
}
}
} catch {
alert = Alert(error)
}
}
}
Button {
Task {
do {
if let result = try await SystemExtension.uninstall() {
switch result {
case .completed:
alert = Alert(
title: Text("Uninstall"),
message: Text("System Extension removed."),
dismissButton: .default(Text("Ok")) {}
)
case .willCompleteAfterReboot:
alert = Alert(
title: Text("Uninstall"),
message: Text("Reboot required."),
dismissButton: .default(Text("Ok")) {}
)
}
}
} catch {
alert = Alert(error)
}
}
} label: {
Text("Uninstall System Extension").foregroundColor(.red)
}
}.frame(maxWidth: .infinity, alignment: .trailing)
}
#endif
Expand Down
25 changes: 21 additions & 4 deletions Library/Network/SystemExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
private var properties: [OSSystemExtensionProperties]?
private var error: Error?

private init(forceUpdate: Bool = false, inBackground: Bool = false) {
private init(_ forceUpdate: Bool = false, _ inBackground: Bool = false) {
self.forceUpdate = forceUpdate
self.inBackground = inBackground
}
Expand Down Expand Up @@ -53,7 +53,7 @@
semaphore.signal()
}

public func submitAndWait() throws -> OSSystemExtensionRequest.Result? {
public func activation() throws -> OSSystemExtensionRequest.Result? {
let request = OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: FilePath.packageName + ".system", queue: .main)
request.delegate = self
OSSystemExtensionManager.shared.submitRequest(request)
Expand All @@ -64,6 +64,17 @@
return result
}

public func deactivation() throws -> OSSystemExtensionRequest.Result? {
let request = OSSystemExtensionRequest.deactivationRequest(forExtensionWithIdentifier: FilePath.packageName + ".system", queue: .main)
request.delegate = self
OSSystemExtensionManager.shared.submitRequest(request)
semaphore.wait()
if let error {
throw error
}
return result
}

public func getProperties() throws -> [OSSystemExtensionProperties] {
let request = OSSystemExtensionRequest.propertiesRequest(forExtensionWithIdentifier: FilePath.packageName + ".system", queue: .main)
request.delegate = self
Expand Down Expand Up @@ -100,9 +111,15 @@
return false
}

public static func install(forceUpdate: Bool = false, inBackground _: Bool = false) async throws -> OSSystemExtensionRequest.Result? {
public static func install(forceUpdate: Bool = false, inBackground: Bool = false) async throws -> OSSystemExtensionRequest.Result? {
try await Task.detached {
try SystemExtension(forceUpdate, inBackground).activation()
}.result.get()
}

public static func uninstall() async throws -> OSSystemExtensionRequest.Result? {
try await Task.detached {
try SystemExtension(forceUpdate: forceUpdate).submitAndWait()
try SystemExtension().deactivation()
}.result.get()
}
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Experimental iOS/macOS/tvOS client for sing-box, the universal proxy platform.

## Documentation

[SFI](https://sing-box.sagernet.org/installation/clients/sfi/) | [SFM](https://sing-box.sagernet.org/installation/clients/sfm/)
[sing-box for Apple platforms](https://sing-box.sagernet.org/clients/apple/)

## License

Expand All @@ -23,4 +23,4 @@ GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
```
```