mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-17 22:03:41 +00:00
Remove extension WebView data during uninstall
This commit is contained in:
1 parent
c47b735fc4
commit
d642ae5018
25 files changed
+609
-19
No files matched your search
+39
@@ -32,4 +32,43 @@ final class GopeedProfiles {
|
||||
proxyURLs[identifier] = proxyURL
|
||||
result(true)
|
||||
}
|
||||
static func remove(arguments: NSDictionary?, result: @escaping FlutterResult) {
|
||||
guard let identifier = arguments?["gopeedProfileId"] as? String,
|
||||
let uuid = UUID(uuidString: identifier) else {
|
||||
result(FlutterError(code: "INVALID_REQUEST", message: "Invalid WebView profile identifier", details: nil))
|
||||
return
|
||||
}
|
||||
guard #available(macOS 14.0, iOS 17.0, *) else {
|
||||
// Named stores could not have been created on these OS versions.
|
||||
result(true)
|
||||
return
|
||||
}
|
||||
// Deleting a named store alone can leave in-process cookie caches.
|
||||
// Clear every website data type before releasing/removing the store.
|
||||
let store = stores[identifier] ?? WKWebsiteDataStore(forIdentifier: uuid)
|
||||
store.removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), modifiedSince: Date.distantPast) {
|
||||
stores.removeValue(forKey: identifier)
|
||||
proxyURLs.removeValue(forKey: identifier)
|
||||
removeStore(uuid, attempts: 100, result: result)
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 14.0, iOS 17.0, *)
|
||||
private static func removeStore(_ uuid: UUID, attempts: Int, result: @escaping FlutterResult) {
|
||||
WKWebsiteDataStore.remove(forIdentifier: uuid) { error in
|
||||
if error != nil && attempts > 1 {
|
||||
// Network-process references can outlive platform-view disposal.
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
removeStore(uuid, attempts: attempts - 1, result: result)
|
||||
}
|
||||
return
|
||||
}
|
||||
if let error = error {
|
||||
result(FlutterError(code: "PROFILE_REMOVE_FAILED", message: error.localizedDescription, details: nil))
|
||||
} else {
|
||||
result(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -22,6 +22,10 @@ public class MyCookieManager: ChannelDelegate {
|
||||
|
||||
public override func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
let arguments = call.arguments as? NSDictionary
|
||||
if call.method == "gopeed.removeProfile" {
|
||||
GopeedProfiles.remove(arguments: arguments, result: result)
|
||||
return
|
||||
}
|
||||
if call.method == "gopeed.prepareProfile" {
|
||||
GopeedProfiles.prepare(arguments: arguments, result: result)
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user