From d201789720f10a400688ab7360fc76da33bdbe64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 6 Jan 2026 01:05:37 +0800 Subject: [PATCH] Signal file provider changes on VPN status update --- .../Views/Setting/CoreView.swift | 1 + Library/Network/ExtensionProfile.swift | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ApplicationLibrary/Views/Setting/CoreView.swift b/ApplicationLibrary/Views/Setting/CoreView.swift index 74875a0..d59652c 100644 --- a/ApplicationLibrary/Views/Setting/CoreView.swift +++ b/ApplicationLibrary/Views/Setting/CoreView.swift @@ -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"]) diff --git a/Library/Network/ExtensionProfile.swift b/Library/Network/ExtensionProfile.swift index 66b43f6..20a72d9 100644 --- a/Library/Network/ExtensionProfile.swift +++ b/Library/Network/ExtensionProfile.swift @@ -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)