craft-native 0.0.90 → 0.0.92

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.
Files changed (31) hide show
  1. package/dist/android/src/index.d.ts +36 -1
  2. package/dist/android/src/index.js +332 -44
  3. package/dist/android/src/promise-runtime.d.ts +3 -0
  4. package/dist/android/templates/CraftBridge.kt.template +2167 -1177
  5. package/dist/android/templates/CraftHealthConnect.kt.template +45 -6
  6. package/dist/android/templates/CraftHealthConnectStub.kt.template +7 -1
  7. package/dist/android/templates/CraftNative.kt.template +2250 -0
  8. package/dist/android/templates/LocationRecordingService.kt.template +34 -9
  9. package/dist/android/templates/MainActivity.kt.template +42 -8
  10. package/dist/android/templates/proguard-rules.pro.template +4 -1
  11. package/dist/android/templates/test-bridges.html +10 -33
  12. package/dist/api/index.d.ts +1 -1
  13. package/dist/api/ios-advanced.d.ts +8 -5
  14. package/dist/api/live-activity-handle.d.ts +6 -0
  15. package/dist/api/mobile.d.ts +25 -7
  16. package/dist/api/window.d.ts +2 -0
  17. package/dist/cli.js +452 -129
  18. package/dist/index.cjs +77 -22
  19. package/dist/index.js +77 -22
  20. package/dist/ios/src/index.d.ts +1 -1
  21. package/dist/ios/src/index.js +23 -5
  22. package/dist/ios/templates/CraftApp.swift +706 -92
  23. package/dist/ios/templates/CraftWatchApp.swift.template +8 -0
  24. package/dist/ios/templates/WatchApp.Info.plist.template +2 -0
  25. package/dist/ios/templates/WatchExtension.Info.plist.template +34 -0
  26. package/dist/ios/templates/project.yml.template +10 -4
  27. package/dist/mobile.js +52 -21
  28. package/dist/scaffold-version.d.ts +5 -0
  29. package/package.json +1 -1
  30. package/dist/android/templates/CraftBridgeExtensions.kt.template +0 -383
  31. package/dist/android/templates/CraftWidgetProvider.kt.template +0 -246
@@ -1,246 +0,0 @@
1
- package {{PACKAGE_NAME}}
2
-
3
- import android.app.PendingIntent
4
- import android.appwidget.AppWidgetManager
5
- import android.appwidget.AppWidgetProvider
6
- import android.content.BroadcastReceiver
7
- import android.content.ComponentName
8
- import android.content.Context
9
- import android.content.Intent
10
- import android.content.IntentFilter
11
- import android.os.Build
12
- import android.widget.RemoteViews
13
-
14
- /**
15
- * Craft Widget Provider
16
- *
17
- * A customizable home screen widget that displays data from your Craft app.
18
- * The widget can show title, subtitle, value, and an icon.
19
- *
20
- * To use widgets:
21
- * 1. Add this provider to your AndroidManifest.xml
22
- * 2. Create widget layout in res/layout/craft_widget.xml
23
- * 3. Create widget info in res/xml/craft_widget_info.xml
24
- * 4. Call window.craft.widget.update() from your web app
25
- */
26
- class CraftWidgetProvider : AppWidgetProvider() {
27
-
28
- companion object {
29
- const val ACTION_WIDGET_UPDATE = "{{PACKAGE_NAME}}.WIDGET_UPDATE"
30
- const val PREFS_NAME = "craft_widget_prefs"
31
- const val PREF_TITLE = "widget_title"
32
- const val PREF_SUBTITLE = "widget_subtitle"
33
- const val PREF_VALUE = "widget_value"
34
- const val PREF_ICON = "widget_icon"
35
-
36
- /**
37
- * Update all widgets programmatically
38
- */
39
- fun updateAllWidgets(context: Context) {
40
- val intent = Intent(context, CraftWidgetProvider::class.java).apply {
41
- action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
42
- val appWidgetManager = AppWidgetManager.getInstance(context)
43
- val widgetComponent = ComponentName(context, CraftWidgetProvider::class.java)
44
- val appWidgetIds = appWidgetManager.getAppWidgetIds(widgetComponent)
45
- putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds)
46
- }
47
- context.sendBroadcast(intent)
48
- }
49
- }
50
-
51
- override fun onUpdate(
52
- context: Context,
53
- appWidgetManager: AppWidgetManager,
54
- appWidgetIds: IntArray
55
- ) {
56
- // Update each widget instance
57
- for (appWidgetId in appWidgetIds) {
58
- updateAppWidget(context, appWidgetManager, appWidgetId)
59
- }
60
- }
61
-
62
- override fun onReceive(context: Context, intent: Intent) {
63
- super.onReceive(context, intent)
64
-
65
- // Handle custom update action from the app
66
- if (intent.action == ACTION_WIDGET_UPDATE) {
67
- val appWidgetManager = AppWidgetManager.getInstance(context)
68
- val widgetComponent = ComponentName(context, CraftWidgetProvider::class.java)
69
- val appWidgetIds = appWidgetManager.getAppWidgetIds(widgetComponent)
70
-
71
- for (appWidgetId in appWidgetIds) {
72
- updateAppWidget(context, appWidgetManager, appWidgetId)
73
- }
74
- }
75
- }
76
-
77
- override fun onEnabled(context: Context) {
78
- // Register broadcast receiver for widget updates
79
- val filter = IntentFilter(ACTION_WIDGET_UPDATE)
80
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
81
- context.registerReceiver(widgetUpdateReceiver, filter, Context.RECEIVER_EXPORTED)
82
- } else {
83
- context.registerReceiver(widgetUpdateReceiver, filter)
84
- }
85
- }
86
-
87
- override fun onDisabled(context: Context) {
88
- // Unregister broadcast receiver
89
- try {
90
- context.unregisterReceiver(widgetUpdateReceiver)
91
- } catch (_: IllegalArgumentException) {
92
- // Receiver not registered
93
- }
94
- }
95
-
96
- private val widgetUpdateReceiver = object : BroadcastReceiver() {
97
- override fun onReceive(context: Context, intent: Intent) {
98
- if (intent.action == ACTION_WIDGET_UPDATE) {
99
- updateAllWidgets(context)
100
- }
101
- }
102
- }
103
-
104
- private fun updateAppWidget(
105
- context: Context,
106
- appWidgetManager: AppWidgetManager,
107
- appWidgetId: Int
108
- ) {
109
- // Get data from shared preferences
110
- val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
111
- val title = prefs.getString(PREF_TITLE, "Craft Widget") ?: "Craft Widget"
112
- val subtitle = prefs.getString(PREF_SUBTITLE, "") ?: ""
113
- val value = prefs.getString(PREF_VALUE, "") ?: ""
114
- val iconName = prefs.getString(PREF_ICON, null)
115
-
116
- // Create remote views
117
- val views = RemoteViews(context.packageName, R.layout.craft_widget)
118
-
119
- // Set text values
120
- views.setTextViewText(R.id.widget_title, title)
121
- views.setTextViewText(R.id.widget_subtitle, subtitle)
122
- views.setTextViewText(R.id.widget_value, value)
123
-
124
- // Set visibility for subtitle
125
- views.setViewVisibility(
126
- R.id.widget_subtitle,
127
- if (subtitle.isEmpty()) android.view.View.GONE else android.view.View.VISIBLE
128
- )
129
-
130
- // Set visibility for value
131
- views.setViewVisibility(
132
- R.id.widget_value,
133
- if (value.isEmpty()) android.view.View.GONE else android.view.View.VISIBLE
134
- )
135
-
136
- // Set icon if provided
137
- if (iconName != null) {
138
- val iconResId = context.resources.getIdentifier(
139
- iconName,
140
- "drawable",
141
- context.packageName
142
- )
143
- if (iconResId != 0) {
144
- views.setImageViewResource(R.id.widget_icon, iconResId)
145
- views.setViewVisibility(R.id.widget_icon, android.view.View.VISIBLE)
146
- } else {
147
- views.setViewVisibility(R.id.widget_icon, android.view.View.GONE)
148
- }
149
- } else {
150
- views.setViewVisibility(R.id.widget_icon, android.view.View.GONE)
151
- }
152
-
153
- // Create click intent to launch main app
154
- val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
155
- if (launchIntent != null) {
156
- val pendingIntent = PendingIntent.getActivity(
157
- context,
158
- 0,
159
- launchIntent,
160
- PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
161
- )
162
- views.setOnClickPendingIntent(R.id.widget_container, pendingIntent)
163
- }
164
-
165
- // Update the widget
166
- appWidgetManager.updateAppWidget(appWidgetId, views)
167
- }
168
- }
169
-
170
- /**
171
- * Widget Layout (res/layout/craft_widget.xml):
172
- *
173
- * <?xml version="1.0" encoding="utf-8"?>
174
- * <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
175
- * android:id="@+id/widget_container"
176
- * android:layout_width="match_parent"
177
- * android:layout_height="match_parent"
178
- * android:orientation="vertical"
179
- * android:padding="16dp"
180
- * android:background="@drawable/widget_background">
181
- *
182
- * <ImageView
183
- * android:id="@+id/widget_icon"
184
- * android:layout_width="32dp"
185
- * android:layout_height="32dp"
186
- * android:visibility="gone" />
187
- *
188
- * <TextView
189
- * android:id="@+id/widget_title"
190
- * android:layout_width="wrap_content"
191
- * android:layout_height="wrap_content"
192
- * android:textSize="16sp"
193
- * android:textStyle="bold"
194
- * android:textColor="@color/widget_text_primary" />
195
- *
196
- * <TextView
197
- * android:id="@+id/widget_subtitle"
198
- * android:layout_width="wrap_content"
199
- * android:layout_height="wrap_content"
200
- * android:textSize="12sp"
201
- * android:textColor="@color/widget_text_secondary" />
202
- *
203
- * <TextView
204
- * android:id="@+id/widget_value"
205
- * android:layout_width="wrap_content"
206
- * android:layout_height="wrap_content"
207
- * android:textSize="32sp"
208
- * android:textStyle="bold"
209
- * android:textColor="@color/widget_accent"
210
- * android:layout_marginTop="8dp" />
211
- *
212
- * </LinearLayout>
213
- */
214
-
215
- /**
216
- * Widget Info (res/xml/craft_widget_info.xml):
217
- *
218
- * <?xml version="1.0" encoding="utf-8"?>
219
- * <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
220
- * android:minWidth="110dp"
221
- * android:minHeight="110dp"
222
- * android:targetCellWidth="2"
223
- * android:targetCellHeight="2"
224
- * android:updatePeriodMillis="1800000"
225
- * android:initialLayout="@layout/craft_widget"
226
- * android:resizeMode="horizontal|vertical"
227
- * android:widgetCategory="home_screen"
228
- * android:previewImage="@drawable/widget_preview"
229
- * android:description="@string/widget_description" />
230
- */
231
-
232
- /**
233
- * AndroidManifest.xml entries needed:
234
- *
235
- * <receiver
236
- * android:name=".CraftWidgetProvider"
237
- * android:exported="true">
238
- * <intent-filter>
239
- * <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
240
- * <action android:name="{{PACKAGE_NAME}}.WIDGET_UPDATE" />
241
- * </intent-filter>
242
- * <meta-data
243
- * android:name="android.appwidget.provider"
244
- * android:resource="@xml/craft_widget_info" />
245
- * </receiver>
246
- */