@capgo/capacitor-updater 7.42.9 → 7.45.10

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.
@@ -37,11 +37,16 @@ extension UIWindow {
37
37
  return
38
38
  }
39
39
 
40
- showShakeMenu(plugin: plugin, bridge: bridge)
40
+ // Check if channel selector mode is enabled
41
+ if plugin.shakeChannelSelectorEnabled {
42
+ showChannelSelector(plugin: plugin, bridge: bridge)
43
+ } else {
44
+ showDefaultMenu(plugin: plugin, bridge: bridge)
45
+ }
41
46
  }
42
47
  }
43
48
 
44
- private func showShakeMenu(plugin: CapacitorUpdaterPlugin, bridge: CAPBridgeProtocol) {
49
+ private func showDefaultMenu(plugin: CapacitorUpdaterPlugin, bridge: CAPBridgeProtocol) {
45
50
  // Prevent multiple alerts from showing
46
51
  if let topVC = UIApplication.topViewController(),
47
52
  topVC.isKind(of: UIAlertController.self) {
@@ -110,4 +115,344 @@ extension UIWindow {
110
115
  }
111
116
  }
112
117
  }
118
+
119
+ private func showChannelSelector(plugin: CapacitorUpdaterPlugin, bridge: CAPBridgeProtocol) {
120
+ // Prevent multiple alerts from showing
121
+ if let topVC = UIApplication.topViewController(),
122
+ topVC.isKind(of: UIAlertController.self) {
123
+ plugin.logger.info("UIAlertController is already presented")
124
+ return
125
+ }
126
+
127
+ let updater = plugin.implementation
128
+
129
+ // Show loading indicator
130
+ let loadingAlert = UIAlertController(title: "Loading Channels...", message: nil, preferredStyle: .alert)
131
+ var didCancel = false
132
+ let loadingIndicator = UIActivityIndicatorView(style: .medium)
133
+ loadingIndicator.translatesAutoresizingMaskIntoConstraints = false
134
+ loadingIndicator.startAnimating()
135
+ loadingAlert.view.addSubview(loadingIndicator)
136
+
137
+ NSLayoutConstraint.activate([
138
+ loadingIndicator.centerXAnchor.constraint(equalTo: loadingAlert.view.centerXAnchor),
139
+ loadingIndicator.bottomAnchor.constraint(equalTo: loadingAlert.view.bottomAnchor, constant: -20)
140
+ ])
141
+
142
+ // Add cancel button to loading alert
143
+ loadingAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel) { _ in
144
+ didCancel = true
145
+ })
146
+
147
+ DispatchQueue.main.async {
148
+ if let topVC = UIApplication.topViewController() {
149
+ topVC.present(loadingAlert, animated: true) {
150
+ // Fetch channels in background
151
+ DispatchQueue.global(qos: .userInitiated).async {
152
+ let result = updater.listChannels()
153
+
154
+ DispatchQueue.main.async {
155
+ loadingAlert.dismiss(animated: true) {
156
+ guard !didCancel else { return }
157
+ if !result.error.isEmpty {
158
+ self.showError(message: "Failed to load channels: \(result.error)", plugin: plugin)
159
+ } else if result.channels.isEmpty {
160
+ self.showError(message: "No channels available for self-assignment", plugin: plugin)
161
+ } else {
162
+ self.presentChannelPicker(channels: result.channels, plugin: plugin, bridge: bridge)
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }
169
+ }
170
+ }
171
+
172
+ private func presentChannelPicker(channels: [[String: Any]], plugin: CapacitorUpdaterPlugin, bridge: CAPBridgeProtocol) {
173
+ let alert = UIAlertController(title: "Select Channel", message: "Choose a channel to switch to", preferredStyle: .actionSheet)
174
+
175
+ // Get channel names
176
+ let channelNames = channels.compactMap { $0["name"] as? String }
177
+
178
+ // Show first 5 channels as actions
179
+ let channelsToShow = Array(channelNames.prefix(5))
180
+
181
+ for channelName in channelsToShow {
182
+ alert.addAction(UIAlertAction(title: channelName, style: .default) { [weak self] _ in
183
+ self?.selectChannel(name: channelName, plugin: plugin, bridge: bridge)
184
+ })
185
+ }
186
+
187
+ // If there are more channels, add a "More..." option
188
+ if channelNames.count > 5 {
189
+ alert.addAction(UIAlertAction(title: "More channels...", style: .default) { [weak self] _ in
190
+ self?.showSearchableChannelPicker(channels: channels, plugin: plugin, bridge: bridge)
191
+ })
192
+ }
193
+
194
+ alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
195
+
196
+ // For iPad support
197
+ if let popoverController = alert.popoverPresentationController {
198
+ popoverController.sourceView = self
199
+ popoverController.sourceRect = CGRect(x: self.bounds.midX, y: self.bounds.midY, width: 0, height: 0)
200
+ popoverController.permittedArrowDirections = []
201
+ }
202
+
203
+ DispatchQueue.main.async {
204
+ if let topVC = UIApplication.topViewController() {
205
+ topVC.present(alert, animated: true)
206
+ }
207
+ }
208
+ }
209
+
210
+ private func showSearchableChannelPicker(channels: [[String: Any]], plugin: CapacitorUpdaterPlugin, bridge: CAPBridgeProtocol) {
211
+ let alert = UIAlertController(title: "Search Channels", message: "Enter channel name to search", preferredStyle: .alert)
212
+
213
+ alert.addTextField { textField in
214
+ textField.placeholder = "Channel name..."
215
+ }
216
+
217
+ let channelNames = channels.compactMap { $0["name"] as? String }
218
+
219
+ alert.addAction(UIAlertAction(title: "Search", style: .default) { [weak self, weak alert] _ in
220
+ guard let searchText = alert?.textFields?.first?.text?.lowercased(), !searchText.isEmpty else {
221
+ // If empty, show first 5
222
+ self?.presentChannelPicker(channels: channels, plugin: plugin, bridge: bridge)
223
+ return
224
+ }
225
+
226
+ // Filter channels
227
+ let filtered = channelNames.filter { $0.lowercased().contains(searchText) }
228
+
229
+ if filtered.isEmpty {
230
+ self?.showError(message: "No channels found matching '\(searchText)'", plugin: plugin)
231
+ } else if filtered.count == 1 {
232
+ // Directly select if only one match
233
+ self?.selectChannel(name: filtered[0], plugin: plugin, bridge: bridge)
234
+ } else {
235
+ // Show filtered results
236
+ let filteredChannels = channels.filter { channel in
237
+ if let name = channel["name"] as? String {
238
+ return name.lowercased().contains(searchText)
239
+ }
240
+ return false
241
+ }
242
+ self?.presentChannelPicker(channels: filteredChannels, plugin: plugin, bridge: bridge)
243
+ }
244
+ })
245
+
246
+ alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
247
+
248
+ DispatchQueue.main.async {
249
+ if let topVC = UIApplication.topViewController() {
250
+ topVC.present(alert, animated: true)
251
+ }
252
+ }
253
+ }
254
+
255
+ private func selectChannel(name: String, plugin: CapacitorUpdaterPlugin, bridge: CAPBridgeProtocol) {
256
+ let updater = plugin.implementation
257
+
258
+ // Show progress indicator
259
+ let progressAlert = UIAlertController(title: "Switching to \(name)", message: "Setting channel...", preferredStyle: .alert)
260
+ let indicator = UIActivityIndicatorView(style: .medium)
261
+ indicator.translatesAutoresizingMaskIntoConstraints = false
262
+ indicator.startAnimating()
263
+ progressAlert.view.addSubview(indicator)
264
+
265
+ NSLayoutConstraint.activate([
266
+ indicator.centerXAnchor.constraint(equalTo: progressAlert.view.centerXAnchor),
267
+ indicator.bottomAnchor.constraint(equalTo: progressAlert.view.bottomAnchor, constant: -20)
268
+ ])
269
+
270
+ DispatchQueue.main.async {
271
+ if let topVC = UIApplication.topViewController() {
272
+ topVC.present(progressAlert, animated: true) {
273
+ DispatchQueue.global(qos: .userInitiated).async {
274
+ // Set the channel - respect plugin's allowSetDefaultChannel config
275
+ let setResult = updater.setChannel(
276
+ channel: name,
277
+ defaultChannelKey: "CapacitorUpdater.defaultChannel",
278
+ allowSetDefaultChannel: plugin.allowSetDefaultChannel
279
+ )
280
+
281
+ if !setResult.error.isEmpty {
282
+ DispatchQueue.main.async {
283
+ progressAlert.dismiss(animated: true) {
284
+ self.showError(message: "Failed to set channel: \(setResult.error)", plugin: plugin)
285
+ }
286
+ }
287
+ return
288
+ }
289
+
290
+ // Update progress message
291
+ DispatchQueue.main.async {
292
+ progressAlert.message = "Checking for updates..."
293
+ }
294
+
295
+ // Check for updates with the new channel
296
+ let pluginUpdateUrl = plugin.getUpdateUrl()
297
+ let updateUrlStr = pluginUpdateUrl.isEmpty ? CapacitorUpdaterPlugin.updateUrlDefault : pluginUpdateUrl
298
+ guard let updateUrl = URL(string: updateUrlStr) else {
299
+ DispatchQueue.main.async {
300
+ progressAlert.dismiss(animated: true) {
301
+ self.showError(
302
+ message: "Channel set to \(name). Invalid update URL, could not check for updates.",
303
+ plugin: plugin
304
+ )
305
+ }
306
+ }
307
+ return
308
+ }
309
+
310
+ let latest = updater.getLatest(url: updateUrl, channel: name)
311
+ let latestKind = latest.kind
312
+
313
+ let detail = [latest.message, latest.error, latestKind]
314
+ .compactMap { value in
315
+ guard let value, !value.isEmpty else { return nil }
316
+ return value
317
+ }
318
+ .first ?? "server did not provide a message"
319
+
320
+ // Handle update errors first (before "no new version" check)
321
+ if latestKind == "failed" || (latest.error?.isEmpty == false && latestKind != "up_to_date" && latestKind != "blocked") {
322
+ DispatchQueue.main.async {
323
+ progressAlert.dismiss(animated: true) {
324
+ self.showError(message: "Channel set to \(name). Update check failed: \(detail)", plugin: plugin)
325
+ }
326
+ }
327
+ return
328
+ }
329
+
330
+ if latestKind == "blocked" {
331
+ DispatchQueue.main.async {
332
+ progressAlert.dismiss(animated: true) {
333
+ self.showError(message: "Channel set to \(name). Update check blocked: \(detail)", plugin: plugin)
334
+ }
335
+ }
336
+ return
337
+ }
338
+
339
+ // Check if there's an actual update available
340
+ if latestKind == "up_to_date" || latest.url.isEmpty {
341
+ DispatchQueue.main.async {
342
+ progressAlert.dismiss(animated: true) {
343
+ self.showSuccess(message: "Channel set to \(name). Already on latest version.", plugin: plugin)
344
+ }
345
+ }
346
+ return
347
+ }
348
+
349
+ // Update message
350
+ DispatchQueue.main.async {
351
+ progressAlert.message = "Downloading update \(latest.version)..."
352
+ }
353
+
354
+ // Download the update
355
+ do {
356
+ let bundle: BundleInfo
357
+ if let manifest = latest.manifest, !manifest.isEmpty {
358
+ bundle = try updater.downloadManifest(
359
+ manifest: manifest,
360
+ version: latest.version,
361
+ sessionKey: latest.sessionKey ?? ""
362
+ )
363
+ } else {
364
+ // Safe unwrap URL
365
+ guard let downloadUrl = URL(string: latest.url) else {
366
+ DispatchQueue.main.async {
367
+ progressAlert.dismiss(animated: true) {
368
+ self.showError(message: "Failed to download update: invalid update URL.", plugin: plugin)
369
+ }
370
+ }
371
+ return
372
+ }
373
+ bundle = try updater.download(
374
+ url: downloadUrl,
375
+ version: latest.version,
376
+ sessionKey: latest.sessionKey ?? ""
377
+ )
378
+ }
379
+
380
+ // Set as next bundle
381
+ _ = updater.setNextBundle(next: bundle.getId())
382
+
383
+ DispatchQueue.main.async {
384
+ progressAlert.dismiss(animated: true) {
385
+ self.showSuccessWithReload(
386
+ message: "Update downloaded! Reload to apply version \(latest.version)?",
387
+ plugin: plugin,
388
+ bridge: bridge,
389
+ onReload: { [weak plugin] in
390
+ _ = updater.set(bundle: bundle)
391
+ _ = plugin?._reload()
392
+ }
393
+ )
394
+ }
395
+ }
396
+ } catch {
397
+ DispatchQueue.main.async {
398
+ progressAlert.dismiss(animated: true) {
399
+ self.showError(message: "Failed to download update: \(error.localizedDescription)", plugin: plugin)
400
+ }
401
+ }
402
+ }
403
+ }
404
+ }
405
+ }
406
+ }
407
+ }
408
+
409
+ private func showError(message: String, plugin: CapacitorUpdaterPlugin) {
410
+ plugin.logger.error(message)
411
+ let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert)
412
+ alert.addAction(UIAlertAction(title: "OK", style: .default))
413
+
414
+ DispatchQueue.main.async {
415
+ if let topVC = UIApplication.topViewController() {
416
+ topVC.present(alert, animated: true)
417
+ }
418
+ }
419
+ }
420
+
421
+ private func showSuccess(message: String, plugin: CapacitorUpdaterPlugin) {
422
+ plugin.logger.info(message)
423
+ let alert = UIAlertController(title: "Success", message: message, preferredStyle: .alert)
424
+ alert.addAction(UIAlertAction(title: "OK", style: .default))
425
+
426
+ DispatchQueue.main.async {
427
+ if let topVC = UIApplication.topViewController() {
428
+ topVC.present(alert, animated: true)
429
+ }
430
+ }
431
+ }
432
+
433
+ private func showSuccessWithReload(
434
+ message: String,
435
+ plugin: CapacitorUpdaterPlugin,
436
+ bridge: CAPBridgeProtocol,
437
+ onReload: (() -> Void)? = nil
438
+ ) {
439
+ plugin.logger.info(message)
440
+ let alert = UIAlertController(title: "Update Ready", message: message, preferredStyle: .alert)
441
+ alert.addAction(UIAlertAction(title: "Later", style: .cancel))
442
+ alert.addAction(UIAlertAction(title: "Reload Now", style: .default) { _ in
443
+ if let onReload = onReload {
444
+ onReload()
445
+ } else {
446
+ DispatchQueue.main.async {
447
+ bridge.webView?.reload()
448
+ }
449
+ }
450
+ })
451
+
452
+ DispatchQueue.main.async {
453
+ if let topVC = UIApplication.topViewController() {
454
+ topVC.present(alert, animated: true)
455
+ }
456
+ }
457
+ }
113
458
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "7.42.9",
3
+ "version": "7.45.10",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",
@@ -41,23 +41,27 @@
41
41
  "native"
42
42
  ],
43
43
  "scripts": {
44
- "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
44
+ "verify": "bun run verify:ios && bun run verify:android && bun run verify:web",
45
45
  "verify:ios": "xcodebuild -scheme CapgoCapacitorUpdater -destination generic/platform=iOS",
46
46
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
47
- "verify:web": "npm run build",
48
- "test": "npm run test:ios && npm run test:android",
47
+ "verify:web": "bun run build",
48
+ "test": "bun run test:ios && bun run test:android",
49
49
  "test:ios": "./scripts/test-ios.sh",
50
50
  "test:android": "cd android && ./gradlew test && cd ..",
51
- "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
52
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
51
+ "test:maestro": "./scripts/maestro/run-android-live-update.sh",
52
+ "test:maestro:android": "./scripts/test-maestro-android.sh",
53
+ "test:maestro:ios": "./scripts/test-maestro-ios.sh",
54
+ "lint": "bun run eslint && bun run prettier -- --check && bun run swiftlint -- lint",
55
+ "fmt": "bun run eslint -- --fix && bun run prettier -- --write && bun run swiftlint -- --fix --format",
53
56
  "eslint": "eslint . --ext .ts",
54
57
  "prettier": "prettier-pretty-check \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
55
58
  "swiftlint": "node-swiftlint",
56
59
  "docgen": "node scripts/generate-docs.js",
57
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
60
+ "build": "bun run clean && bun run docgen && tsc && rollup -c rollup.config.mjs",
58
61
  "clean": "rimraf ./dist",
59
62
  "watch": "tsc --watch",
60
- "prepublishOnly": "npm run build"
63
+ "prepublishOnly": "bun run build",
64
+ "check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs"
61
65
  },
62
66
  "devDependencies": {
63
67
  "@capacitor/android": "^7.4.3",