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.
- package/CapacitorPicaNetworkLogger.podspec +1 -1
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/linakis/capacitorpicanetworklogger/InspectorNotifications.kt +38 -7
- package/android/src/main/java/com/linakis/capacitorpicanetworklogger/PicaNetworkLoggerPlugin.kt +3 -2
- package/package.json +1 -1
|
@@ -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>
|
package/android/src/main/java/com/linakis/capacitorpicanetworklogger/InspectorNotifications.kt
CHANGED
|
@@ -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
|
|
13
|
-
private const val
|
|
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(
|
|
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
|
-
|
|
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,
|
|
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(
|
|
74
|
+
manager.notify(SUMMARY_ID, summaryNotification)
|
|
44
75
|
}
|
|
45
76
|
}
|
package/android/src/main/java/com/linakis/capacitorpicanetworklogger/PicaNetworkLoggerPlugin.kt
CHANGED
|
@@ -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.
|
|
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.
|
|
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()
|