Skip to content

Commit

Permalink
fix: ios email error (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel authored Nov 11, 2024
1 parent bd1ad27 commit 15def4a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
19 changes: 17 additions & 2 deletions composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import app.cash.sqldelight.driver.native.NativeSqliteDriver
import co.touchlab.kermit.Logger
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
Expand All @@ -30,6 +31,7 @@ import platform.BackgroundTasks.BGTaskScheduler
import platform.Foundation.NSBundle
import platform.Foundation.NSDate
import platform.Foundation.NSDocumentDirectory
import platform.Foundation.NSError
import platform.Foundation.NSFileManager
import platform.Foundation.NSLocale
import platform.Foundation.NSLocaleLanguageDirectionRightToLeft
Expand All @@ -41,7 +43,9 @@ import platform.Foundation.NSUserDomainMask
import platform.Foundation.characterDirectionForLanguage
import platform.Foundation.dateByAddingTimeInterval
import platform.Foundation.stringWithContentsOfFile
import platform.MessageUI.MFMailComposeResult
import platform.MessageUI.MFMailComposeViewController
import platform.MessageUI.MFMailComposeViewControllerDelegateProtocol
import platform.UIKit.UIActivityTypeAirDrop
import platform.UIKit.UIActivityTypePostToFacebook
import platform.UIKit.UIActivityViewController
Expand Down Expand Up @@ -155,6 +159,17 @@ class SetupDependencies(
val email = it.toString().removePrefix("mailto:")
if (canSendMail) {
MFMailComposeViewController().apply {
mailComposeDelegate = object :
NSObject(),
MFMailComposeViewControllerDelegateProtocol {
override fun mailComposeController(
controller: MFMailComposeViewController,
didFinishWithResult: MFMailComposeResult,
error: NSError?,
) {
controller.dismissViewControllerAnimated(true, null)
}
}
setToRecipients(listOf(email))
extras?.forEach { (key, value) ->
when (key) {
Expand Down Expand Up @@ -205,7 +220,7 @@ class SetupDependencies(

fun scheduleNextAutorun() {
val getAutoRunSettings by lazy { dependencies.getAutoRunSettings }
GlobalScope.launch {
CoroutineScope(Dispatchers.Default).launch {
configureAutoRun(getAutoRunSettings().first())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.ooni.probe.background

import co.touchlab.kermit.Logger
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
Expand All @@ -14,7 +16,8 @@ class RunOperation(
) : NSOperation() {
override fun main() {
Logger.d { "Running operation" }
GlobalScope.launch {
val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
coroutineScope.launch {
runBackgroundTask(spec).collect()
}.invokeOnCompletion {
Logger.d { "Operation completed" }
Expand Down

0 comments on commit 15def4a

Please sign in to comment.