Explorar el Código

Remove desktop widgets when premium access is revoked.

Made-with: Cursor
huzaifahayat12 hace 3 meses
padre
commit
7ea689960a

+ 1 - 0
meetings_app/ViewController.swift

@@ -1581,6 +1581,7 @@ private extension ViewController {
         }
         if hadPremiumAccess && !hasPremiumAccess {
             MeetingReminderManager.shared.cancelAllReminders()
+            DesktopWidgetWindowManager.shared.removeAllInstances()
             showPaywall()
         }
     }

+ 14 - 0
meetings_app/Widgets/DesktopWidgetWindowManager.swift

@@ -57,6 +57,20 @@ final class DesktopWidgetWindowManager: ObservableObject {
         return removed.count
     }
 
+    @discardableResult
+    func removeAllInstances() -> Int {
+        let instances = loadInstances()
+        guard !instances.isEmpty else { return 0 }
+        for instance in instances {
+            if let panel = windowsByInstanceID.removeValue(forKey: instance.id) {
+                panel.close()
+            }
+        }
+        saveInstances([])
+        instancesChangeToken += 1
+        return instances.count
+    }
+
     func restore() {
         for instance in loadInstances() where windowsByInstanceID[instance.id] == nil {
             show(instance: instance)