add notifcaiton support with unmount button

This commit is contained in:
2026-03-10 01:01:20 +05:00
parent 0c5524a9a5
commit 93c239eb12
9 changed files with 259 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package sh.sar.isodroid.notification
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.widget.Toast
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import sh.sar.isodroid.isodrive.IsoDriveManager
import sh.sar.isodroid.isodrive.MountEventBus
class UnmountReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == NotificationHelper.ACTION_UNMOUNT) {
val pendingResult = goAsync()
CoroutineScope(Dispatchers.IO).launch {
try {
val isoDriveManager = IsoDriveManager.getInstance(context)
val result = isoDriveManager.unmount()
CoroutineScope(Dispatchers.Main).launch {
if (result.success) {
Toast.makeText(context, "Unmounted successfully", Toast.LENGTH_SHORT).show()
NotificationHelper.getInstance(context).hideNotification()
MountEventBus.emitUnmounted()
} else {
Toast.makeText(context, "Unmount failed: ${result.message}", Toast.LENGTH_LONG).show()
}
pendingResult.finish()
}
} catch (e: Exception) {
CoroutineScope(Dispatchers.Main).launch {
Toast.makeText(context, "Error: ${e.message}", Toast.LENGTH_LONG).show()
pendingResult.finish()
}
}
}
}
}
}