Skip to content

Commit

Permalink
Update setup usages
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 26, 2024
1 parent 1e400f1 commit 801b8f5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Library/Network/ExtensionPlatformInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
throw NSError(domain: "missing file descriptor", code: 0)
}
}

public func updateRouteOptions(_ options: (any LibboxTunOptionsProtocol)?) throws {
try runBlocking { [self] in
try await updateRouteOptions0(options)
Expand All @@ -53,7 +53,7 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc

let autoRouteUseSubRangesByDefault = await SharedPreferences.autoRouteUseSubRangesByDefault.get()
let excludeAPNs = await SharedPreferences.excludeAPNsRoute.get()

let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "127.0.0.1")
if options.getAutoRoute() {
settings.mtu = NSNumber(value: options.getMTU())
Expand Down Expand Up @@ -200,7 +200,7 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
networkSettings = settings
try await tunnel.setTunnelNetworkSettings(settings)
}

public func usePlatformAutoDetectControl() -> Bool {
false
}
Expand Down
28 changes: 15 additions & 13 deletions Library/Network/ExtensionProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ open class ExtensionProvider: NEPacketTunnelProvider {
override open func startTunnel(options _: [String: NSObject]?) async throws {
LibboxClearServiceError()

let options = LibboxSetupOptions()
options.basePath = FilePath.sharedDirectory.relativePath
options.workingPath = FilePath.workingDirectory.relativePath
options.tempPath = FilePath.cacheDirectory.relativePath
var error: NSError?
LibboxSetup(options, &error)
#if os(tvOS)
options.isTVOS = true
#endif
if let username {
var error: NSError?
LibboxSetupWithUsername(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, username, &error)
if let error {
writeFatalError("(packet-tunnel) error: setup service: \(error.localizedDescription)")
return
}
} else {
var isTVOS = false
#if os(tvOS)
isTVOS = true
#endif
LibboxSetup(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, isTVOS)
options.username = username
}
LibboxSetup(options, &error)
if let error {
writeFatalError("(packet-tunnel) error: setup service: \(error.localizedDescription)")
return
}

var error: NSError?
LibboxRedirectStderr(FilePath.cacheDirectory.appendingPathComponent("stderr.log").relativePath, &error)
if let error {
writeFatalError("(packet-tunnel) redirect stderr error: \(error.localizedDescription)")
Expand Down
7 changes: 6 additions & 1 deletion MacLibrary/ApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import UserNotifications
open class ApplicationDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
public func applicationDidFinishLaunching(_: Notification) {
NSLog("Here I stand")
LibboxSetup(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, false)
let options = LibboxSetupOptions()
options.basePath = FilePath.sharedDirectory.relativePath
options.workingPath = FilePath.workingDirectory.relativePath
options.tempPath = FilePath.cacheDirectory.relativePath
var error: NSError?
LibboxSetup(options, &error)
LibboxSetLocale(Locale.current.identifier)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.setNotificationCategories([
Expand Down
7 changes: 6 additions & 1 deletion SFI/ApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ class ApplicationDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCe

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
NSLog("Here I stand")
LibboxSetup(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, false)
let options = LibboxSetupOptions()
options.basePath = FilePath.sharedDirectory.relativePath
options.workingPath = FilePath.workingDirectory.relativePath
options.tempPath = FilePath.cacheDirectory.relativePath
var error: NSError?
LibboxSetup(options, &error)
LibboxSetLocale(Locale.current.identifier)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.setNotificationCategories([
Expand Down
8 changes: 7 additions & 1 deletion SFT/ApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import UIKit
class ApplicationDelegate: NSObject, UIApplicationDelegate {
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
NSLog("Here I stand")
LibboxSetup(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, true)
let options = LibboxSetupOptions()
options.basePath = FilePath.sharedDirectory.relativePath
options.workingPath = FilePath.workingDirectory.relativePath
options.tempPath = FilePath.cacheDirectory.relativePath
options.isTVOS = true
var error: NSError?
LibboxSetup(options, &error)
LibboxSetLocale(Locale.current.identifier)
setup()
return true
Expand Down

0 comments on commit 801b8f5

Please sign in to comment.