expo-app-blocker 0.1.44 → 0.1.46

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.
@@ -19,8 +19,13 @@ jobs:
19
19
 
20
20
  - name: Determine version bump
21
21
  id: version
22
+ # Never inline `${{ github.event.head_commit.message }}` into the
23
+ # script body — GitHub Actions substitutes it BEFORE the shell runs,
24
+ # so backticks / parens / `${...}` / `{vars}` get evaluated as
25
+ # commands. Always pass via env: so it lands as a quoted string.
26
+ env:
27
+ COMMIT_MSG: ${{ github.event.head_commit.message }}
22
28
  run: |
23
- COMMIT_MSG="${{ github.event.head_commit.message }}"
24
29
  if echo "$COMMIT_MSG" | grep -qw "\[major\]"; then
25
30
  echo "bump=major" >> $GITHUB_OUTPUT
26
31
  elif echo "$COMMIT_MSG" | grep -qw "\[minor\]"; then
@@ -6,7 +6,11 @@ import android.content.SharedPreferences
6
6
  object AppBlockerPrefs {
7
7
  const val PREFS_NAME = "expo_app_blocker_prefs"
8
8
  const val KEY_BLOCKED_PACKAGES = "blocked_packages"
9
+ private const val KEY_OVERLAY_TITLE = "overlay_title"
9
10
  private const val KEY_OVERLAY_TEXT = "overlay_text"
11
+ private const val KEY_OVERLAY_BG_COLOR = "overlay_bg_color"
12
+ private const val KEY_OVERLAY_TITLE_COLOR = "overlay_title_color"
13
+ private const val KEY_OVERLAY_TEXT_COLOR = "overlay_text_color"
10
14
  private const val KEY_NOTIFICATION_TITLE = "notification_title"
11
15
  private const val KEY_NOTIFICATION_TEXT = "notification_text"
12
16
 
@@ -24,20 +28,40 @@ object AppBlockerPrefs {
24
28
 
25
29
  fun setAndroidConfig(
26
30
  context: Context,
31
+ overlayTitle: String?,
27
32
  overlayText: String?,
33
+ overlayBackgroundColor: String?,
34
+ overlayTitleColor: String?,
35
+ overlayTextColor: String?,
28
36
  notificationTitle: String?,
29
37
  notificationText: String?,
30
38
  ) {
31
39
  get(context).edit()
40
+ .putString(KEY_OVERLAY_TITLE, overlayTitle)
32
41
  .putString(KEY_OVERLAY_TEXT, overlayText)
42
+ .putString(KEY_OVERLAY_BG_COLOR, overlayBackgroundColor)
43
+ .putString(KEY_OVERLAY_TITLE_COLOR, overlayTitleColor)
44
+ .putString(KEY_OVERLAY_TEXT_COLOR, overlayTextColor)
33
45
  .putString(KEY_NOTIFICATION_TITLE, notificationTitle)
34
46
  .putString(KEY_NOTIFICATION_TEXT, notificationText)
35
47
  .apply()
36
48
  }
37
49
 
50
+ fun getOverlayTitle(context: Context): String =
51
+ get(context).getString(KEY_OVERLAY_TITLE, null) ?: "App Blocked"
52
+
38
53
  fun getOverlayText(context: Context): String =
39
54
  get(context).getString(KEY_OVERLAY_TEXT, null) ?: "{appName} is blocked."
40
55
 
56
+ fun getOverlayBackgroundColor(context: Context): String =
57
+ get(context).getString(KEY_OVERLAY_BG_COLOR, null) ?: "#FFFFFF"
58
+
59
+ fun getOverlayTitleColor(context: Context): String =
60
+ get(context).getString(KEY_OVERLAY_TITLE_COLOR, null) ?: "#111111"
61
+
62
+ fun getOverlayTextColor(context: Context): String =
63
+ get(context).getString(KEY_OVERLAY_TEXT_COLOR, null) ?: "#737373"
64
+
41
65
  fun getNotificationTitle(context: Context): String =
42
66
  get(context).getString(KEY_NOTIFICATION_TITLE, null) ?: "App Blocked"
43
67
 
@@ -68,7 +68,11 @@ class ExpoAppBlockerModule : Module() {
68
68
  Function("setAndroidConfig") { config: Map<String, Any?> ->
69
69
  AppBlockerPrefs.setAndroidConfig(
70
70
  context,
71
+ overlayTitle = config["overlayTitle"] as? String,
71
72
  overlayText = config["overlayText"] as? String,
73
+ overlayBackgroundColor = config["overlayBackgroundColor"] as? String,
74
+ overlayTitleColor = config["overlayTitleColor"] as? String,
75
+ overlayTextColor = config["overlayTextColor"] as? String,
72
76
  notificationTitle = config["notificationTitle"] as? String,
73
77
  notificationText = config["notificationText"] as? String,
74
78
  )
@@ -117,18 +117,32 @@ class OverlayManager(private val context: Context) {
117
117
  val density = context.resources.displayMetrics.density
118
118
  fun dp(value: Int) = (value * density).toInt()
119
119
 
120
+ val overlayTitle = AppBlockerPrefs.getOverlayTitle(context)
121
+ .replace("{appName}", appName)
120
122
  val overlayText = AppBlockerPrefs.getOverlayText(context)
121
123
  .replace("{appName}", appName)
124
+ val backgroundColor = parseColorOrDefault(
125
+ AppBlockerPrefs.getOverlayBackgroundColor(context),
126
+ Color.WHITE,
127
+ )
128
+ val titleColor = parseColorOrDefault(
129
+ AppBlockerPrefs.getOverlayTitleColor(context),
130
+ Color.parseColor("#111111"),
131
+ )
132
+ val textColor = parseColorOrDefault(
133
+ AppBlockerPrefs.getOverlayTextColor(context),
134
+ Color.parseColor("#737373"),
135
+ )
122
136
 
123
137
  return LinearLayout(context).apply {
124
138
  orientation = LinearLayout.VERTICAL
125
139
  gravity = Gravity.CENTER
126
- setBackgroundColor(Color.WHITE)
140
+ setBackgroundColor(backgroundColor)
127
141
  setPadding(dp(32), dp(32), dp(32), dp(32))
128
142
 
129
143
  addView(TextView(context).apply {
130
- text = "App Blocked"
131
- setTextColor(Color.parseColor("#111111"))
144
+ text = overlayTitle
145
+ setTextColor(titleColor)
132
146
  setTextSize(TypedValue.COMPLEX_UNIT_SP, 24f)
133
147
  setTypeface(typeface, Typeface.BOLD)
134
148
  gravity = Gravity.CENTER
@@ -137,13 +151,19 @@ class OverlayManager(private val context: Context) {
137
151
 
138
152
  addView(TextView(context).apply {
139
153
  text = overlayText
140
- setTextColor(Color.parseColor("#737373"))
154
+ setTextColor(textColor)
141
155
  setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
142
156
  gravity = Gravity.CENTER
143
157
  })
144
158
  }
145
159
  }
146
160
 
161
+ private fun parseColorOrDefault(hex: String, fallback: Int): Int = try {
162
+ Color.parseColor(hex)
163
+ } catch (_: IllegalArgumentException) {
164
+ fallback
165
+ }
166
+
147
167
  private fun buildLayoutParams(): WindowManager.LayoutParams {
148
168
  @Suppress("DEPRECATION")
149
169
  val type = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-app-blocker",
3
- "version": "0.1.44",
3
+ "version": "0.1.46",
4
4
  "description": "Expo module for cross-platform app blocking. Android: UsageStatsManager + Overlay. iOS: Screen Time API (FamilyControls + ManagedSettings + DeviceActivity).",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -149,8 +149,16 @@ export interface ShieldConfig {
149
149
  }
150
150
 
151
151
  export interface AndroidConfig {
152
- /** Text shown on the blocking overlay. Use {appName} as placeholder. Default: "{appName} is blocked." */
152
+ /** Bold title rendered on the blocking overlay. Use {appName} as placeholder. Default: "App Blocked" */
153
+ overlayTitle?: string;
154
+ /** Body text shown under the overlay title. Use {appName} as placeholder. Default: "{appName} is blocked." */
153
155
  overlayText?: string;
156
+ /** Hex color (e.g. "#f6f6f6") for the overlay background. Default: "#FFFFFF". */
157
+ overlayBackgroundColor?: string;
158
+ /** Hex color (e.g. "#111111") for the overlay title text. Default: "#111111". */
159
+ overlayTitleColor?: string;
160
+ /** Hex color (e.g. "#737373") for the overlay body text. Default: "#737373". */
161
+ overlayTextColor?: string;
154
162
  /** Notification title when app is blocked. Use {appName} as placeholder. Default: "App Blocked" */
155
163
  notificationTitle?: string;
156
164
  /** Notification text when app is blocked. Use {appName} as placeholder. */