Add support for tvOS
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import ApplicationLibrary
|
||||
import Foundation
|
||||
import Libbox
|
||||
import Library
|
||||
import Network
|
||||
import UIKit
|
||||
|
||||
class ApplicationDelegate: NSObject, UIApplicationDelegate {
|
||||
private var profileServer: ProfileServer?
|
||||
|
||||
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
||||
NSLog("Here I stand")
|
||||
ServiceNotification.register()
|
||||
LibboxSetup(FilePath.sharedDirectory.relativePath, FilePath.workingDirectory.relativePath, FilePath.cacheDirectory.relativePath, false)
|
||||
Task.detached {
|
||||
do {
|
||||
try await UIProfileUpdateTask.setup()
|
||||
@@ -18,9 +22,25 @@ class ApplicationDelegate: NSObject, UIApplicationDelegate {
|
||||
Task.detached {
|
||||
await self.requestNetworkPermission()
|
||||
}
|
||||
if #available(iOS 16.0, *) {
|
||||
Task.detached {
|
||||
await self.setupProfileServer()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@available(iOS 16.0, *)
|
||||
private func setupProfileServer() {
|
||||
do {
|
||||
let profileServer = try ProfileServer()
|
||||
profileServer.start()
|
||||
self.profileServer = profileServer
|
||||
} catch {
|
||||
NSLog("setup profile server error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
private func requestNetworkPermission() {
|
||||
if UIDevice.current.userInterfaceIdiom != .phone {
|
||||
return
|
||||
|
||||
@@ -2,6 +2,16 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSApplicationServices</key>
|
||||
<dict>
|
||||
<key>Advertises</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>NSApplicationServiceIdentifier</key>
|
||||
<string>sing-box:profile</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
<key>BGTaskSchedulerPermittedIdentifiers</key>
|
||||
<array>
|
||||
<string>io.nekohasekai.sfa.update_profiles</string>
|
||||
|
||||
@@ -10,11 +10,6 @@ struct MainView: View {
|
||||
@State private var extensionProfile: ExtensionProfile?
|
||||
@State private var profileLoading = true
|
||||
@State private var logClient: LogClient!
|
||||
|
||||
@State private var serviceNotificationTitle = ""
|
||||
@State private var serviceNotificationContent = ""
|
||||
@State private var serviceNotificationPresented = false
|
||||
|
||||
@State private var importRemoteProfile: LibboxImportRemoteProfile?
|
||||
|
||||
var body: some View {
|
||||
@@ -30,23 +25,6 @@ struct MainView: View {
|
||||
ContentView()
|
||||
}
|
||||
}
|
||||
.alert(isPresented: $serviceNotificationPresented, content: {
|
||||
Alert(
|
||||
title: Text(serviceNotificationTitle),
|
||||
message: Text(serviceNotificationContent),
|
||||
dismissButton: .default(Text("Ok"))
|
||||
)
|
||||
})
|
||||
.onAppear {
|
||||
ServiceNotification.setServiceNotificationListener { notification in
|
||||
serviceNotificationTitle = notification.title
|
||||
serviceNotificationContent = notification.body
|
||||
serviceNotificationPresented = true
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
ServiceNotification.removeServiceNotificationListener()
|
||||
}
|
||||
.onChange(of: scenePhase, perform: { newValue in
|
||||
if newValue == .active {
|
||||
Task.detached {
|
||||
|
||||
Reference in New Issue
Block a user