Jelajahi Sumber

try to open closed and encrypted database on share extension initialization

cyberta 3 tahun lalu
induk
melakukan
97df676c7b
1 mengubah file dengan 8 tambahan dan 1 penghapusan
  1. 8 1
      DcShare/Controller/ShareViewController.swift

+ 8 - 1
DcShare/Controller/ShareViewController.swift

@@ -84,7 +84,14 @@ class ShareViewController: SLComposeServiceViewController {
     override func presentationAnimationDidFinish() {
         dcAccounts.logger = logger
         dcAccounts.openDatabase()
-        isAccountConfigured = dcContext.isConfigured()
+        if !dcContext.isOpen() {
+            let secret = try? KeychainManager.getDBSecret()
+            if !dcContext.open(passphrase: secret) {
+                logger.error("Failed to open database.")
+            }
+        }
+        isAccountConfigured = dcContext.isOpen() && dcContext.isConfigured()
+
         if isAccountConfigured {
             if #available(iOSApplicationExtension 13.0, *) {
                 if let intent = self.extensionContext?.intent as? INSendMessageIntent,