Signal file provider changes on VPN status update

This commit is contained in:
世界
2026-01-06 01:06:56 +08:00
parent 9d5e4a4e30
commit d201789720
2 changed files with 26 additions and 0 deletions
@@ -213,6 +213,7 @@ public struct CoreView: View {
guard let manager = NSFileProviderManager(for: domain) else {
throw NSError(domain: "CoreView", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to get file provider manager"])
}
try await manager.signalEnumerator(for: .workingSet)
let url = try await manager.getUserVisibleURL(for: .rootContainer)
guard let sharedURL = URL(string: "shareddocuments://\(url.path)") else {
throw NSError(domain: "CoreView", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to create shared documents URL"])
+25
View File
@@ -2,6 +2,9 @@ import Foundation
import Libbox
import NetworkExtension
import os
#if os(iOS)
import FileProvider
#endif
private let logger = Logger(category: "ExtensionProfile")
@@ -39,10 +42,32 @@ public class ExtensionProfile: ObservableObject {
self.connection = connection
self.status = connection.status
self.connectedDate = connection.connectedDate
#if os(iOS)
if #available(iOS 16.0, *) {
if connection.status == .connected || connection.status == .disconnected {
Self.signalFileProviderChanges()
}
}
#endif
}
}
}
#if os(iOS)
@available(iOS 16.0, *)
private static func signalFileProviderChanges() {
Task.detached {
guard let domain = try? await NSFileProviderManager.domains()
.first(where: { $0.identifier.rawValue == AppConfiguration.fileProviderDomainID }),
let manager = NSFileProviderManager(for: domain)
else {
return
}
try? await manager.signalEnumerator(for: .workingSet)
}
}
#endif
private func unregister() {
if let observer {
NotificationCenter.default.removeObserver(observer)