@capgo/capacitor-updater 7.4.0 → 7.5.1

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.
@@ -0,0 +1,112 @@
1
+ /*
2
+ * This Source Code Form is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
+ */
6
+
7
+ import UIKit
8
+ import Capacitor
9
+
10
+ extension UIApplication {
11
+ public class func topViewController(_ base: UIViewController? = UIApplication.shared.windows.first?.rootViewController) -> UIViewController? {
12
+ if let nav = base as? UINavigationController {
13
+ return topViewController(nav.visibleViewController)
14
+ }
15
+ if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
16
+ return topViewController(selected)
17
+ }
18
+ if let presented = base?.presentedViewController {
19
+ return topViewController(presented)
20
+ }
21
+ return base
22
+ }
23
+ }
24
+
25
+ extension UIWindow {
26
+ override open func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
27
+ if motion == .motionShake {
28
+ // Find the CapacitorUpdaterPlugin instance
29
+ guard let bridge = (rootViewController as? CAPBridgeProtocol),
30
+ let plugin = bridge.plugin(withName: "CapacitorUpdaterPlugin") as? CapacitorUpdaterPlugin else {
31
+ return
32
+ }
33
+
34
+ // Check if shake menu is enabled
35
+ if !plugin.shakeMenuEnabled {
36
+ return
37
+ }
38
+
39
+ showShakeMenu(plugin: plugin, bridge: bridge)
40
+ }
41
+ }
42
+
43
+ private func showShakeMenu(plugin: CapacitorUpdaterPlugin, bridge: CAPBridgeProtocol) {
44
+ // Prevent multiple alerts from showing
45
+ if let topVC = UIApplication.topViewController(),
46
+ topVC.isKind(of: UIAlertController.self) {
47
+ plugin.logger.info("UIAlertController is already presented")
48
+ return
49
+ }
50
+
51
+ let appName = Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String ?? "App"
52
+ let title = "Preview \(appName) Menu"
53
+ let message = "What would you like to do?"
54
+ let okButtonTitle = "Go Home"
55
+ let reloadButtonTitle = "Reload app"
56
+ let cancelButtonTitle = "Close menu"
57
+
58
+ let updater = plugin.implementation
59
+
60
+ func resetBuiltin() {
61
+ updater.reset()
62
+ bridge.setServerBasePath("")
63
+ DispatchQueue.main.async {
64
+ if let vc = (self.rootViewController as? CAPBridgeViewController) {
65
+ vc.loadView()
66
+ vc.viewDidLoad()
67
+ }
68
+ _ = updater.delete(id: updater.getCurrentBundleId())
69
+ plugin.logger.info("Reset to builtin version")
70
+ }
71
+ }
72
+
73
+ let bundleId = updater.getCurrentBundleId()
74
+ if let vc = (self.rootViewController as? CAPBridgeViewController) {
75
+ plugin.logger.info("getServerBasePath: \(vc.getServerBasePath())")
76
+ }
77
+ plugin.logger.info("bundleId: \(bundleId)")
78
+
79
+ let alertShake = UIAlertController(title: title, message: message, preferredStyle: .alert)
80
+
81
+ alertShake.addAction(UIAlertAction(title: okButtonTitle, style: .default) { _ in
82
+ guard let next = updater.getNextBundle() else {
83
+ resetBuiltin()
84
+ return
85
+ }
86
+ if !next.isBuiltin() {
87
+ plugin.logger.info("Resetting to: \(next.toString())")
88
+ _ = updater.set(bundle: next)
89
+ let destHot = updater.getBundleDirectory(id: next.getId())
90
+ plugin.logger.info("Reloading \(next.toString())")
91
+ bridge.setServerBasePath(destHot.path)
92
+ } else {
93
+ resetBuiltin()
94
+ }
95
+ plugin.logger.info("Reload app done")
96
+ })
97
+
98
+ alertShake.addAction(UIAlertAction(title: cancelButtonTitle, style: .default))
99
+
100
+ alertShake.addAction(UIAlertAction(title: reloadButtonTitle, style: .default) { _ in
101
+ DispatchQueue.main.async {
102
+ bridge.webView?.reload()
103
+ }
104
+ })
105
+
106
+ DispatchQueue.main.async {
107
+ if let topVC = UIApplication.topViewController() {
108
+ topVC.present(alertShake, animated: true)
109
+ }
110
+ }
111
+ }
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "7.4.0",
3
+ "version": "7.5.1",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",