@capgo/capacitor-screen-recorder 8.3.14 → 8.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,12 +63,11 @@ dependencies {
63
63
  implementation project(':capacitor-android')
64
64
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
65
65
  testImplementation "junit:junit:$junitVersion"
66
- testImplementation "org.mockito:mockito-core:5.23.0"
66
+ testImplementation "org.mockito:mockito-core:5.24.0"
67
67
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
68
68
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
69
69
  implementation "androidx.core:core-ktx:$androidxCoreVersion"
70
70
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
71
71
  implementation ("dev.bmcreations:scrcast:0.3.0")
72
- implementation "com.karumi:dexter:6.2.3"
73
72
  implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.1.0"
74
73
  }
@@ -7,18 +7,16 @@ import android.content.Context
7
7
  import android.content.Intent
8
8
  import android.content.IntentFilter
9
9
  import android.content.ServiceConnection
10
+ import android.content.pm.PackageManager
10
11
  import android.media.MediaScannerConnection
11
12
  import android.os.IBinder
12
13
  import android.util.DisplayMetrics
13
14
  import android.util.Log
14
15
  import androidx.activity.ComponentActivity
15
16
  import androidx.activity.result.ActivityResult
17
+ import androidx.activity.result.contract.ActivityResultContracts
18
+ import androidx.core.content.ContextCompat
16
19
  import androidx.localbroadcastmanager.content.LocalBroadcastManager
17
- import com.karumi.dexter.Dexter
18
- import com.karumi.dexter.MultiplePermissionsReport
19
- import com.karumi.dexter.PermissionToken
20
- import com.karumi.dexter.listener.PermissionRequest
21
- import com.karumi.dexter.listener.multi.MultiplePermissionsListener
22
20
  import dev.bmcreations.scrcast.config.Options
23
21
  import dev.bmcreations.scrcast.internal.recorder.Action
24
22
  import dev.bmcreations.scrcast.internal.recorder.EXTRA_ERROR
@@ -74,30 +72,28 @@ class CapgoScrCast private constructor(
74
72
  startListener = null
75
73
  }
76
74
  STATE_IDLE -> {
75
+ val startPending = startListener != null
77
76
  val error = intent.getSerializableExtra(EXTRA_ERROR) as? Throwable
78
77
  if (error != null) {
79
78
  startListener?.onFailed(error)
79
+ } else if (startPending) {
80
+ startListener?.onFailed(
81
+ IllegalStateException("Recording stopped before it started"),
82
+ )
80
83
  }
81
- cleanupSession()
84
+ cleanupSession(deleteEmptyOutput = startPending || error != null)
82
85
  }
83
86
  }
84
87
  }
85
88
  }
86
89
 
87
- private val permissionListener = object : MultiplePermissionsListener {
88
- override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
89
- if (report?.areAllPermissionsGranted() == true) {
90
- startProjection.launch(Unit)
91
- } else {
92
- notifyStartFailed(SecurityException("Required permissions were not granted"))
93
- }
94
- }
95
-
96
- override fun onPermissionRationaleShouldBeShown(
97
- permissions: MutableList<PermissionRequest>?,
98
- token: PermissionToken?,
99
- ) {
100
- token?.continuePermissionRequest()
90
+ private val requestRuntimePermissions = activity.registerForActivityResult(
91
+ ActivityResultContracts.RequestMultiplePermissions(),
92
+ ) { _ ->
93
+ if (requiredRuntimePermissions().all { isPermissionGranted(it) }) {
94
+ startProjection.launch(Unit)
95
+ } else {
96
+ notifyStartFailed(SecurityException("Required permissions were not granted"))
101
97
  }
102
98
  }
103
99
 
@@ -131,20 +127,27 @@ class CapgoScrCast private constructor(
131
127
  return false
132
128
  }
133
129
  startListener = listener
134
- val permissions = buildList {
135
- add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
136
- add(Manifest.permission.READ_EXTERNAL_STORAGE)
137
- if (recordAudio) {
138
- add(Manifest.permission.RECORD_AUDIO)
139
- }
130
+ val missing = requiredRuntimePermissions().filterNot { isPermissionGranted(it) }
131
+ if (missing.isEmpty()) {
132
+ startProjection.launch(Unit)
133
+ } else {
134
+ requestRuntimePermissions.launch(missing.toTypedArray())
140
135
  }
141
- Dexter.withContext(activity)
142
- .withPermissions(permissions)
143
- .withListener(permissionListener)
144
- .check()
145
136
  return true
146
137
  }
147
138
 
139
+ private fun requiredRuntimePermissions(): List<String> = buildList {
140
+ add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
141
+ add(Manifest.permission.READ_EXTERNAL_STORAGE)
142
+ if (recordAudio) {
143
+ add(Manifest.permission.RECORD_AUDIO)
144
+ }
145
+ }
146
+
147
+ private fun isPermissionGranted(permission: String): Boolean {
148
+ return ContextCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED
149
+ }
150
+
148
151
  private fun notifyStartFailed(error: Throwable) {
149
152
  startListener?.onFailed(error)
150
153
  startListener = null
@@ -213,7 +216,7 @@ class CapgoScrCast private constructor(
213
216
  receiverRegistered = false
214
217
  }
215
218
 
216
- private fun cleanupSession() {
219
+ private fun cleanupSession(deleteEmptyOutput: Boolean = false) {
217
220
  startListener = null
218
221
  unregisterRecordingReceiver()
219
222
 
@@ -227,8 +230,12 @@ class CapgoScrCast private constructor(
227
230
  recordingSession = null
228
231
 
229
232
  outputFile?.let { file ->
230
- MediaScannerConnection.scanFile(activity, arrayOf(file.absolutePath), null) { path, uri ->
231
- Log.i("CapgoScreenRecorder", "Saved recording: $path uri=$uri")
233
+ if (file.isFile && file.length() > 0L) {
234
+ MediaScannerConnection.scanFile(activity, arrayOf(file.absolutePath), null) { path, uri ->
235
+ Log.i("CapgoScreenRecorder", "Saved recording: $path uri=$uri")
236
+ }
237
+ } else if (deleteEmptyOutput && file.exists()) {
238
+ runCatching { file.delete() }
232
239
  }
233
240
  }
234
241
  outputFile = null
@@ -10,7 +10,7 @@ import dev.bmcreations.scrcast.config.Options;
10
10
  @CapacitorPlugin(name = "ScreenRecorder")
11
11
  public class ScreenRecorderPlugin extends Plugin {
12
12
 
13
- private final String pluginVersion = "8.3.14";
13
+ private final String pluginVersion = "8.3.17";
14
14
 
15
15
  private CapgoScrCast videoRecorder;
16
16
  private CapgoScrCast audioRecorder;
@@ -7,7 +7,7 @@ import Capacitor
7
7
  */
8
8
  @objc(ScreenRecorderPlugin)
9
9
  public class ScreenRecorderPlugin: CAPPlugin, CAPBridgedPlugin {
10
- private let pluginVersion: String = "8.3.14"
10
+ private let pluginVersion: String = "8.3.17"
11
11
  public let identifier = "ScreenRecorderPlugin"
12
12
  public let jsName = "ScreenRecorder"
13
13
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-screen-recorder",
3
- "version": "8.3.14",
3
+ "version": "8.3.17",
4
4
  "description": "Record device's screen",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",