Skip to content

Commit

Permalink
fix: Register workers when boot signal is received
Browse files Browse the repository at this point in the history
The local broad cast was never handled as the Activity does not
automatically start.
  • Loading branch information
Leander Beernaert committed Aug 4, 2024
1 parent 8f595ae commit cc9414e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions you-have-mail-android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId "dev.lbeernaert.youhavemail"
minSdk 29
targetSdk 33
versionCode 33
versionName "0.16.1"
versionCode 34
versionName "0.16.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.localbroadcastmanager.content.LocalBroadcastManager

const val START_INTENT= "APP_STARTED"
import dev.lbeernaert.youhavemail.Yhm
import dev.lbeernaert.youhavemail.YhmException

class StartReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
Log.i("BOOT", "Received boot notification")

try {
val localIntent = Intent(START_INTENT)
LocalBroadcastManager.getInstance(context).sendBroadcast(localIntent)
} catch (e: Exception) {
Log.e("BOOT", "Failed to send intent: $e")
val key = getOrCreateEncryptionKey(context)
val dbPath = getDatabasePath(context)
val yhm = Yhm.withoutDbInit(dbPath, encryptionKey = key)
registerWorker(context, yhm.pollInterval().toLong() / 60, false)
} catch (e: YhmException) {
createServiceErrorNotification(
context,
"Failed to Create Yhm on boot and register work",
e
)
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class State(context: Context) : BroadcastReceiver() {

val filter = IntentFilter()
filter.addAction(POLL_INTENT)
filter.addAction(START_INTENT)
LocalBroadcastManager.getInstance(context)
.registerReceiver(this, filter)
}
Expand Down Expand Up @@ -208,11 +207,6 @@ class State(context: Context) : BroadcastReceiver() {
Log.d(STATE_LOG_TAG, "Received poll intent")
onPolled(context, intent.getStringExtra(POLL_INTENT))
}

START_INTENT -> {
Log.d(STATE_LOG_TAG, "Received start intent")
registerWorker(context, mPollInterval.value.toLong(), true)
}
}
}

Expand Down

0 comments on commit cc9414e

Please # to comment.