B. Petersen пре 5 година
родитељ
комит
a8e90d6943
2 измењених фајлова са 21 додато и 38 уклоњено
  1. 9 8
      DcCore/DcCore/DC/Wrapper.swift
  2. 12 30
      deltachat-ios/AppDelegate.swift

+ 9 - 8
DcCore/DcCore/DC/Wrapper.swift

@@ -190,19 +190,20 @@ public class DcContext {
         contextPointer = nil
         contextPointer = nil
     }
     }
 
 
-    public func performImap() {
+    public func maybeStartIo() {
+        if dc_is_io_running(contextPointer) == 0 {
+            dc_start_io(contextPointer)
+        }
     }
     }
 
 
-    public func performMoveBox() {
+    public func maybeStopIo() {
+        if dc_is_io_running(contextPointer) != 0 {
+            dc_stop_io(contextPointer)
+        }
     }
     }
 
 
     public func performSmtpJobs() {
     public func performSmtpJobs() {
-    }
-    
-    public func performSmtp() {
-    }
-
-    public func performSentbox() {
+        // TODO-ASYNC: call the new direct-send function
     }
     }
 
 
     public func setStockTranslation(id: Int32, localizationKey: String) {
     public func setStockTranslation(id: Int32, localizationKey: String) {

+ 12 - 30
deltachat-ios/AppDelegate.swift

@@ -141,6 +141,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dcContext.openDatabase(dbFile: databaseLocation)
         dcContext.openDatabase(dbFile: databaseLocation)
     }
     }
 
 
+    func closeDatabase() {
+        state = .stopped
+        dcContext.closeDatabase()
+    }
+
     func setStockTranslations() {
     func setStockTranslations() {
         dcContext.setStockTranslation(id: DC_STR_NOMESSAGES, localizationKey: "chat_no_messages")
         dcContext.setStockTranslation(id: DC_STR_NOMESSAGES, localizationKey: "chat_no_messages")
         dcContext.setStockTranslation(id: DC_STR_SELF, localizationKey: "self")
         dcContext.setStockTranslation(id: DC_STR_SELF, localizationKey: "self")
@@ -176,16 +181,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dcContext.setStockTranslation(id: DC_STR_DEVICE_MESSAGES, localizationKey: "device_talk")
         dcContext.setStockTranslation(id: DC_STR_DEVICE_MESSAGES, localizationKey: "device_talk")
     }
     }
 
 
-    func stopThreads() {
-        state = .background
-        dcContext.interruptIdle()
-    }
-
-    func closeDatabase() {
-        state = .stopped
-        dcContext.closeDatabase()
-    }
-
     func startThreads(_ completion: (() -> Void)? = nil) {
     func startThreads(_ completion: (() -> Void)? = nil) {
         logger.info("---- start ----")
         logger.info("---- start ----")
 
 
@@ -194,6 +189,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         }
         }
         state = .running
         state = .running
 
 
+        /* TODO-ASYNC: use that for events
         DispatchQueue.global(qos: .background).async {
         DispatchQueue.global(qos: .background).async {
             self.registerBackgroundTask()
             self.registerBackgroundTask()
             while self.state == .running {
             while self.state == .running {
@@ -204,28 +200,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                 self.endBackgroundTask()
                 self.endBackgroundTask()
             }
             }
         }
         }
+        */
 
 
-        DispatchQueue.global(qos: .utility).async {
-            self.registerBackgroundTask()
-            while self.state == .running {
-                self.dcContext.performSmtp()
-            }
-            if self.backgroundTask != .invalid {
-                self.endBackgroundTask()
-            }
-        }
-
-        DispatchQueue.global(qos: .background).async {
-            while self.state == .running {
-                self.dcContext.performSentbox()
-            }
-        }
+        dcContext.maybeStartIo()
+    }
 
 
-        DispatchQueue.global(qos: .background).async {
-            while self.state == .running {
-                self.dcContext.performMoveBox()
-            }
-        }
+    func stopThreads() {
+        state = .background
+        dcContext.maybeStopIo()
     }
     }
 
 
     // MARK: - BackgroundTask
     // MARK: - BackgroundTask