capacitor-pica-network-logger 0.2.2 → 0.2.3

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.
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = 'CapacitorPicaNetworkLogger'
3
- s.version = '0.2.2'
3
+ s.version = '0.2.3'
4
4
  s.summary = 'Capacitor HTTP inspector'
5
5
  s.license = 'MIT'
6
6
  s.author = { 'Nikos Linakis' => 'nikos@linakis.net' }
@@ -4,6 +4,7 @@
4
4
  <activity
5
5
  android:name="com.linakis.capacitorpicanetworklogger.InspectorActivity"
6
6
  android:exported="false"
7
+ android:taskAffinity="com.linakis.capacitorpicanetworklogger.inspector"
7
8
  android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar" />
8
9
  </application>
9
10
  </manifest>
@@ -9,37 +9,68 @@ import android.os.Build
9
9
  import androidx.core.app.NotificationCompat
10
10
 
11
11
  object InspectorNotifications {
12
- private const val channelId = "pica_network_logger"
13
- private const val channelName = "Network Logger"
12
+ private const val CHANNEL_ID = "pica_network_inspector"
13
+ private const val CHANNEL_NAME = "Network Logger"
14
+ private const val GROUP_KEY = "pica_network_inspector_group"
15
+ private const val SUMMARY_ID = 0
14
16
 
15
17
  fun show(context: Context, method: String, url: String, status: Int?) {
16
18
  val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
19
+
17
20
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
18
- val channel = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_LOW)
21
+ val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW)
19
22
  channel.setSound(null, null)
20
23
  channel.enableVibration(false)
21
24
  manager.createNotificationChannel(channel)
22
25
  }
23
26
 
24
27
  val intent = Intent(context, InspectorActivity::class.java).apply {
25
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
28
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
26
29
  }
30
+
31
+ val requestCode = (System.currentTimeMillis() % 10000).toInt()
27
32
  val pendingIntent = PendingIntent.getActivity(
28
33
  context,
29
- 0,
34
+ requestCode,
30
35
  intent,
31
36
  PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
32
37
  )
33
38
 
34
39
  val title = if (status != null) "$method $status" else method
35
- val notification = NotificationCompat.Builder(context, channelId)
40
+ val notification = NotificationCompat.Builder(context, CHANNEL_ID)
36
41
  .setSmallIcon(android.R.drawable.stat_notify_sync)
37
42
  .setContentTitle(title)
38
43
  .setContentText(url)
39
44
  .setContentIntent(pendingIntent)
40
45
  .setAutoCancel(true)
46
+ .setSilent(true)
47
+ .setGroup(GROUP_KEY)
48
+ .build()
49
+
50
+ manager.notify(requestCode, notification)
51
+
52
+ // Summary notification for the group
53
+ val summaryIntent = Intent(context, InspectorActivity::class.java).apply {
54
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
55
+ }
56
+ val summaryNotification = NotificationCompat.Builder(context, CHANNEL_ID)
57
+ .setSmallIcon(android.R.drawable.stat_notify_sync)
58
+ .setContentTitle(CHANNEL_NAME)
59
+ .setContentText("Tap to open inspector")
60
+ .setContentIntent(
61
+ PendingIntent.getActivity(
62
+ context,
63
+ 0,
64
+ summaryIntent,
65
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
66
+ )
67
+ )
68
+ .setAutoCancel(true)
69
+ .setSilent(true)
70
+ .setGroup(GROUP_KEY)
71
+ .setGroupSummary(true)
41
72
  .build()
42
73
 
43
- manager.notify((System.currentTimeMillis() % 10000).toInt(), notification)
74
+ manager.notify(SUMMARY_ID, summaryNotification)
44
75
  }
45
76
  }
@@ -8,6 +8,7 @@ import com.getcapacitor.annotation.CapacitorPlugin
8
8
  import android.content.pm.PackageManager
9
9
  import android.os.Build
10
10
  import androidx.core.app.ActivityCompat
11
+ import org.json.JSONObject
11
12
 
12
13
  @CapacitorPlugin(name = "PicaNetworkLogger")
13
14
  class PicaNetworkLoggerPlugin : Plugin() {
@@ -58,7 +59,7 @@ class PicaNetworkLoggerPlugin : Plugin() {
58
59
  val headers = call.getObject("headers")?.let { obj ->
59
60
  obj.keys().asSequence().associateWith { key -> obj.getString(key) ?: "" }
60
61
  }
61
- val body = call.getString("body")
62
+ val body = call.data.opt("body")?.let { if ( it == JSONObject.NULL) null else it.toString() }
62
63
  val id = java.util.UUID.randomUUID().toString()
63
64
  LogRepositoryStore.logStart(id, method, url, headers, body)
64
65
  val ret = JSObject()
@@ -73,7 +74,7 @@ class PicaNetworkLoggerPlugin : Plugin() {
73
74
  val headers = call.getObject("headers")?.let { obj ->
74
75
  obj.keys().asSequence().associateWith { key -> obj.getString(key) ?: "" }
75
76
  }
76
- val body = call.getString("body")
77
+ val body = call.data.opt("body")?.let { if ( it == JSONObject.NULL) null else it.toString() }
77
78
  val error = call.getString("error")
78
79
  LogRepositoryStore.logFinish(id, status, headers, body, error, null, null)
79
80
  call.resolve()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-pica-network-logger",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Capacitor HTTP network logger with debug-only native capture",
5
5
  "license": "MIT",
6
6
  "repository": {