capacitor-pica-network-logger 0.2.1 → 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.1.6'
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' }
@@ -1,6 +1,7 @@
1
1
  plugins {
2
2
  id 'com.android.library'
3
3
  id 'org.jetbrains.kotlin.android'
4
+ id 'org.jetbrains.kotlin.plugin.compose'
4
5
  }
5
6
 
6
7
  android {
@@ -10,15 +11,6 @@ android {
10
11
  defaultConfig {
11
12
  minSdk 23
12
13
  }
13
-
14
- buildFeatures {
15
- buildConfig true
16
- compose true
17
- }
18
-
19
- composeOptions {
20
- kotlinCompilerExtensionVersion '1.5.10'
21
- }
22
14
  }
23
15
 
24
16
  dependencies {
@@ -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,35 +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)
22
+ channel.setSound(null, null)
23
+ channel.enableVibration(false)
19
24
  manager.createNotificationChannel(channel)
20
25
  }
21
26
 
22
27
  val intent = Intent(context, InspectorActivity::class.java).apply {
23
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
28
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
24
29
  }
30
+
31
+ val requestCode = (System.currentTimeMillis() % 10000).toInt()
25
32
  val pendingIntent = PendingIntent.getActivity(
26
33
  context,
27
- 0,
34
+ requestCode,
28
35
  intent,
29
36
  PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
30
37
  )
31
38
 
32
39
  val title = if (status != null) "$method $status" else method
33
- val notification = NotificationCompat.Builder(context, channelId)
40
+ val notification = NotificationCompat.Builder(context, CHANNEL_ID)
34
41
  .setSmallIcon(android.R.drawable.stat_notify_sync)
35
42
  .setContentTitle(title)
36
43
  .setContentText(url)
37
44
  .setContentIntent(pendingIntent)
38
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)
39
72
  .build()
40
73
 
41
- manager.notify((System.currentTimeMillis() % 10000).toInt(), notification)
74
+ manager.notify(SUMMARY_ID, summaryNotification)
42
75
  }
43
76
  }
@@ -5,11 +5,11 @@ import com.getcapacitor.Plugin
5
5
 
6
6
  class LoggerConfigProvider {
7
7
  fun getConfig(plugin: Plugin): JSObject {
8
- val config = plugin.config.getObject("PicaNetworkLogger", JSObject())
8
+ val config = plugin.bridge.config.getPluginConfiguration("PicaNetworkLogger")
9
9
  val output = JSObject()
10
10
  output.put("maxBodySize", config.getInt("maxBodySize", 131072))
11
- output.put("redactHeaders", config.optJSONArray("redactHeaders"))
12
- output.put("redactJsonFields", config.optJSONArray("redactJsonFields"))
11
+ output.put("redactHeaders", config.getArray("redactHeaders"))
12
+ output.put("redactJsonFields", config.getArray("redactJsonFields"))
13
13
  output.put("notify", config.getBoolean("notify", true))
14
14
  return output
15
15
  }
@@ -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() {
@@ -32,8 +33,8 @@ class PicaNetworkLoggerPlugin : Plugin() {
32
33
  }
33
34
  }
34
35
  LogRepositoryStore.updateRedaction(redactHeaders, redactJsonFields)
35
- LogRepositoryStore.updateNotify(config.getBoolean("notify", true))
36
- requestNotificationPermissionIfNeeded(config.getBoolean("notify", true))
36
+ LogRepositoryStore.updateNotify(config.optBoolean("notify", true))
37
+ requestNotificationPermissionIfNeeded(config.optBoolean("notify", true))
37
38
  }
38
39
 
39
40
  private fun requestNotificationPermissionIfNeeded(notifyEnabled: Boolean) {
@@ -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()
@@ -1,10 +1,12 @@
1
1
  import Foundation
2
2
  import UserNotifications
3
3
 
4
- class InspectorNotifications: NSObject {
4
+ class InspectorNotifications: NSObject, UNUserNotificationCenterDelegate {
5
5
  static let shared = InspectorNotifications()
6
6
 
7
7
  static func show(method: String, url: String, status: Int?) {
8
+ let center = UNUserNotificationCenter.current()
9
+ center.delegate = shared
8
10
  let content = UNMutableNotificationContent()
9
11
  if let status = status {
10
12
  content.title = "\(method) \(status)"
@@ -12,7 +14,12 @@ class InspectorNotifications: NSObject {
12
14
  content.title = method
13
15
  }
14
16
  content.body = url
17
+ content.sound = nil
15
18
  let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
16
- UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
19
+ center.add(request, withCompletionHandler: nil)
20
+ }
21
+
22
+ func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
23
+ completionHandler([])
17
24
  }
18
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-pica-network-logger",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Capacitor HTTP network logger with debug-only native capture",
5
5
  "license": "MIT",
6
6
  "repository": {