@capgo/capacitor-updater 3.0.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.
@@ -0,0 +1,36 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { CapacitorUpdaterPlugin } from './definitions';
3
+ export declare class CapacitorUpdaterWeb extends WebPlugin implements CapacitorUpdaterPlugin {
4
+ download(options: {
5
+ url: string;
6
+ }): Promise<{
7
+ version: string;
8
+ }>;
9
+ set(options: {
10
+ version: string;
11
+ versionName?: string;
12
+ }): Promise<void>;
13
+ getId(): Promise<{
14
+ id: string;
15
+ }>;
16
+ delete(options: {
17
+ version: string;
18
+ }): Promise<void>;
19
+ list(): Promise<{
20
+ versions: string[];
21
+ }>;
22
+ reset(options?: {
23
+ toAutoUpdate?: boolean;
24
+ }): Promise<void>;
25
+ current(): Promise<{
26
+ current: string;
27
+ currentNative: string;
28
+ }>;
29
+ reload(): Promise<void>;
30
+ versionName(): Promise<{
31
+ versionName: string;
32
+ }>;
33
+ notifyAppReady(): Promise<void>;
34
+ delayUpdate(): Promise<void>;
35
+ cancelDelay(): Promise<void>;
36
+ }
@@ -0,0 +1,49 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class CapacitorUpdaterWeb extends WebPlugin {
3
+ async download(options) {
4
+ console.log('Cannot download version in web', options);
5
+ return { version: "" };
6
+ }
7
+ async set(options) {
8
+ console.log('Cannot set version in web', options);
9
+ }
10
+ async getId() {
11
+ console.log('Cannot get ID in web');
12
+ return { id: 'default' };
13
+ }
14
+ async delete(options) {
15
+ console.log('Cannot delete version in web', options);
16
+ }
17
+ async list() {
18
+ console.log('Cannot list version in web');
19
+ return { versions: [] };
20
+ }
21
+ async reset(options) {
22
+ console.log('Cannot reset version in web', options);
23
+ }
24
+ async current() {
25
+ console.log('Cannot get current version in web');
26
+ return { current: 'default', currentNative: '0.0.0' };
27
+ }
28
+ async reload() {
29
+ console.log('Cannot reload current version in web');
30
+ return;
31
+ }
32
+ async versionName() {
33
+ console.log('Cannot get current versionName in web');
34
+ return { versionName: 'default' };
35
+ }
36
+ async notifyAppReady() {
37
+ console.log('Cannot notify App Ready in web');
38
+ return;
39
+ }
40
+ async delayUpdate() {
41
+ console.log('Cannot delay update in web');
42
+ return;
43
+ }
44
+ async cancelDelay() {
45
+ console.log('Cannot cancel delay update in web');
46
+ return;
47
+ }
48
+ }
49
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,mBACX,SAAQ,SAAS;IAEjB,KAAK,CAAC,QAAQ,CAAC,OAAwB;QACrC,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;QACvD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAC,CAAC;IACxB,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,OAAkD;QAC1D,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IACD,KAAK,CAAC,KAAK;QACT,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QACpC,OAAO,EAAE,EAAE,EAAE,SAAS,EAAC,CAAC;IAC1B,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,OAA4B;QACvC,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,CAAC;IACvD,CAAC;IACD,KAAK,CAAC,IAAI;QACR,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAC1C,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAC,CAAC;IACzB,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,OAAoC;QAC9C,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IACD,KAAK,CAAC,OAAO;QACX,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;QACjD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAC,CAAC;IACvD,CAAC;IACD,KAAK,CAAC,MAAM;QACV,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;QACpD,OAAO;IACT,CAAC;IACD,KAAK,CAAC,WAAW;QACf,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;QACrD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAC,CAAC;IACnC,CAAC;IACD,KAAK,CAAC,cAAc;QAClB,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IACD,KAAK,CAAC,WAAW;QACf,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAC1C,OAAO;IACT,CAAC;IACD,KAAK,CAAC,WAAW;QACf,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;QACjD,OAAO;IACT,CAAC;CACF"}
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@capacitor/core');
6
+
7
+ const CapacitorUpdater = core.registerPlugin('CapacitorUpdater', {
8
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorUpdaterWeb()),
9
+ });
10
+
11
+ class CapacitorUpdaterWeb extends core.WebPlugin {
12
+ async download(options) {
13
+ console.log('Cannot download version in web', options);
14
+ return { version: "" };
15
+ }
16
+ async set(options) {
17
+ console.log('Cannot set version in web', options);
18
+ }
19
+ async getId() {
20
+ console.log('Cannot get ID in web');
21
+ return { id: 'default' };
22
+ }
23
+ async delete(options) {
24
+ console.log('Cannot delete version in web', options);
25
+ }
26
+ async list() {
27
+ console.log('Cannot list version in web');
28
+ return { versions: [] };
29
+ }
30
+ async reset(options) {
31
+ console.log('Cannot reset version in web', options);
32
+ }
33
+ async current() {
34
+ console.log('Cannot get current version in web');
35
+ return { current: 'default', currentNative: '0.0.0' };
36
+ }
37
+ async reload() {
38
+ console.log('Cannot reload current version in web');
39
+ return;
40
+ }
41
+ async versionName() {
42
+ console.log('Cannot get current versionName in web');
43
+ return { versionName: 'default' };
44
+ }
45
+ async notifyAppReady() {
46
+ console.log('Cannot notify App Ready in web');
47
+ return;
48
+ }
49
+ async delayUpdate() {
50
+ console.log('Cannot delay update in web');
51
+ return;
52
+ }
53
+ async cancelDelay() {
54
+ console.log('Cannot cancel delay update in web');
55
+ return;
56
+ }
57
+ }
58
+
59
+ var web = /*#__PURE__*/Object.freeze({
60
+ __proto__: null,
61
+ CapacitorUpdaterWeb: CapacitorUpdaterWeb
62
+ });
63
+
64
+ exports.CapacitorUpdater = CapacitorUpdater;
65
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorUpdater = registerPlugin('CapacitorUpdater', {\n web: () => import('./web').then(m => new m.CapacitorUpdaterWeb()),\n});\nexport * from './definitions';\nexport { CapacitorUpdater };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorUpdaterWeb extends WebPlugin {\n async download(options) {\n console.log('Cannot download version in web', options);\n return { version: \"\" };\n }\n async set(options) {\n console.log('Cannot set version in web', options);\n }\n async getId() {\n console.log('Cannot get ID in web');\n return { id: 'default' };\n }\n async delete(options) {\n console.log('Cannot delete version in web', options);\n }\n async list() {\n console.log('Cannot list version in web');\n return { versions: [] };\n }\n async reset(options) {\n console.log('Cannot reset version in web', options);\n }\n async current() {\n console.log('Cannot get current version in web');\n return { current: 'default', currentNative: '0.0.0' };\n }\n async reload() {\n console.log('Cannot reload current version in web');\n return;\n }\n async versionName() {\n console.log('Cannot get current versionName in web');\n return { versionName: 'default' };\n }\n async notifyAppReady() {\n console.log('Cannot notify App Ready in web');\n return;\n }\n async delayUpdate() {\n console.log('Cannot delay update in web');\n return;\n }\n async cancelDelay() {\n console.log('Cannot cancel delay update in web');\n return;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,gBAAgB,GAAGA,mBAAc,CAAC,kBAAkB,EAAE;AAC5D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;AACrE,CAAC;;ACFM,MAAM,mBAAmB,SAASC,cAAS,CAAC;AACnD,IAAI,MAAM,QAAQ,CAAC,OAAO,EAAE;AAC5B,QAAQ,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;AAC/D,QAAQ,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAC/B,KAAK;AACL,IAAI,MAAM,GAAG,CAAC,OAAO,EAAE;AACvB,QAAQ,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;AAC1D,KAAK;AACL,IAAI,MAAM,KAAK,GAAG;AAClB,QAAQ,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAC5C,QAAQ,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;AACjC,KAAK;AACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B,QAAQ,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,CAAC;AAC7D,KAAK;AACL,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAClD,QAAQ,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AAChC,KAAK;AACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;AAC5D,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AACzD,QAAQ,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;AAC9D,KAAK;AACL,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;AAC5D,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AAC7D,QAAQ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AAC1C,KAAK;AACL,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AACtD,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAClD,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AACzD,QAAQ,OAAO;AACf,KAAK;AACL;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,68 @@
1
+ var capacitorCapacitorUpdater = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const CapacitorUpdater = core.registerPlugin('CapacitorUpdater', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorUpdaterWeb()),
6
+ });
7
+
8
+ class CapacitorUpdaterWeb extends core.WebPlugin {
9
+ async download(options) {
10
+ console.log('Cannot download version in web', options);
11
+ return { version: "" };
12
+ }
13
+ async set(options) {
14
+ console.log('Cannot set version in web', options);
15
+ }
16
+ async getId() {
17
+ console.log('Cannot get ID in web');
18
+ return { id: 'default' };
19
+ }
20
+ async delete(options) {
21
+ console.log('Cannot delete version in web', options);
22
+ }
23
+ async list() {
24
+ console.log('Cannot list version in web');
25
+ return { versions: [] };
26
+ }
27
+ async reset(options) {
28
+ console.log('Cannot reset version in web', options);
29
+ }
30
+ async current() {
31
+ console.log('Cannot get current version in web');
32
+ return { current: 'default', currentNative: '0.0.0' };
33
+ }
34
+ async reload() {
35
+ console.log('Cannot reload current version in web');
36
+ return;
37
+ }
38
+ async versionName() {
39
+ console.log('Cannot get current versionName in web');
40
+ return { versionName: 'default' };
41
+ }
42
+ async notifyAppReady() {
43
+ console.log('Cannot notify App Ready in web');
44
+ return;
45
+ }
46
+ async delayUpdate() {
47
+ console.log('Cannot delay update in web');
48
+ return;
49
+ }
50
+ async cancelDelay() {
51
+ console.log('Cannot cancel delay update in web');
52
+ return;
53
+ }
54
+ }
55
+
56
+ var web = /*#__PURE__*/Object.freeze({
57
+ __proto__: null,
58
+ CapacitorUpdaterWeb: CapacitorUpdaterWeb
59
+ });
60
+
61
+ exports.CapacitorUpdater = CapacitorUpdater;
62
+
63
+ Object.defineProperty(exports, '__esModule', { value: true });
64
+
65
+ return exports;
66
+
67
+ })({}, capacitorExports);
68
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorUpdater = registerPlugin('CapacitorUpdater', {\n web: () => import('./web').then(m => new m.CapacitorUpdaterWeb()),\n});\nexport * from './definitions';\nexport { CapacitorUpdater };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorUpdaterWeb extends WebPlugin {\n async download(options) {\n console.log('Cannot download version in web', options);\n return { version: \"\" };\n }\n async set(options) {\n console.log('Cannot set version in web', options);\n }\n async getId() {\n console.log('Cannot get ID in web');\n return { id: 'default' };\n }\n async delete(options) {\n console.log('Cannot delete version in web', options);\n }\n async list() {\n console.log('Cannot list version in web');\n return { versions: [] };\n }\n async reset(options) {\n console.log('Cannot reset version in web', options);\n }\n async current() {\n console.log('Cannot get current version in web');\n return { current: 'default', currentNative: '0.0.0' };\n }\n async reload() {\n console.log('Cannot reload current version in web');\n return;\n }\n async versionName() {\n console.log('Cannot get current versionName in web');\n return { versionName: 'default' };\n }\n async notifyAppReady() {\n console.log('Cannot notify App Ready in web');\n return;\n }\n async delayUpdate() {\n console.log('Cannot delay update in web');\n return;\n }\n async cancelDelay() {\n console.log('Cannot cancel delay update in web');\n return;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,gBAAgB,GAAGA,mBAAc,CAAC,kBAAkB,EAAE;IAC5D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;IACrE,CAAC;;ICFM,MAAM,mBAAmB,SAASC,cAAS,CAAC;IACnD,IAAI,MAAM,QAAQ,CAAC,OAAO,EAAE;IAC5B,QAAQ,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;IAC/D,QAAQ,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC/B,KAAK;IACL,IAAI,MAAM,GAAG,CAAC,OAAO,EAAE;IACvB,QAAQ,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;IAC1D,KAAK;IACL,IAAI,MAAM,KAAK,GAAG;IAClB,QAAQ,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAC5C,QAAQ,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;IACjC,KAAK;IACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;IAC1B,QAAQ,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,CAAC;IAC7D,KAAK;IACL,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAClD,QAAQ,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAChC,KAAK;IACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;IAC5D,KAAK;IACL,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACzD,QAAQ,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;IAC9D,KAAK;IACL,IAAI,MAAM,MAAM,GAAG;IACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IAC5D,QAAQ,OAAO;IACf,KAAK;IACL,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IAC7D,QAAQ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;IAC1C,KAAK;IACL,IAAI,MAAM,cAAc,GAAG;IAC3B,QAAQ,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IACtD,QAAQ,OAAO;IACf,KAAK;IACL,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAClD,QAAQ,OAAO;IACf,KAAK;IACL,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACzD,QAAQ,OAAO;IACf,KAAK;IACL;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,266 @@
1
+ import Foundation
2
+ import SSZipArchive
3
+ import Alamofire
4
+
5
+ extension URL {
6
+ var isDirectory: Bool {
7
+ (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true
8
+ }
9
+ var exist: Bool {
10
+ return FileManager().fileExists(atPath: self.path)
11
+ }
12
+ }
13
+ struct AppVersionDec: Decodable {
14
+ let version: String?
15
+ let url: String?
16
+ let message: String?
17
+ let major: Bool?
18
+ }
19
+ public class AppVersion: NSObject {
20
+ var version: String = ""
21
+ var url: String = ""
22
+ var message: String?
23
+ var major: Bool?
24
+ }
25
+ extension Bundle {
26
+ var releaseVersionNumber: String? {
27
+ return infoDictionary?["CFBundleShortVersionString"] as? String
28
+ }
29
+ var buildVersionNumber: String? {
30
+ return infoDictionary?["CFBundleVersion"] as? String
31
+ }
32
+ }
33
+
34
+ @objc public class CapacitorUpdater: NSObject {
35
+
36
+ public var statsUrl = ""
37
+ public var appId = ""
38
+ public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
39
+ public var notifyDownload: (Int) -> Void = { _ in }
40
+ public var pluginVersion = "3.0.3"
41
+ private var versionBuild = Bundle.main.releaseVersionNumber ?? ""
42
+ private var lastPathHot = ""
43
+ private var lastPathPersist = ""
44
+ private let basePathHot = "versions"
45
+ private let basePathPersist = "NoCloud/ionic_built_snapshots"
46
+ private let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
47
+ private let libraryUrl = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!
48
+
49
+ @objc private func calcTotalPercent(percent: Int, min: Int, max: Int) -> Int {
50
+ return (percent * (max - min)) / 100 + min;
51
+ }
52
+
53
+ @objc private func randomString(length: Int) -> String {
54
+ let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
55
+ return String((0..<length).map{ _ in letters.randomElement()! })
56
+ }
57
+
58
+ // Persistent path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Library/NoCloud/ionic_built_snapshots/FOLDER
59
+ // Hot Reload path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Documents/FOLDER
60
+ // Normal /private/var/containers/Bundle/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/App.app/public
61
+
62
+ private func prepareFolder(source: URL) {
63
+ if (!FileManager.default.fileExists(atPath: source.path)) {
64
+ do {
65
+ try FileManager.default.createDirectory(atPath: source.path, withIntermediateDirectories: true, attributes: nil)
66
+ } catch {
67
+ print("✨ Capacitor-updater: Cannot createDirectory \(source.path)")
68
+ }
69
+ }
70
+ }
71
+
72
+ private func deleteFolder(source: URL) {
73
+ do {
74
+ try FileManager.default.removeItem(atPath: source.path)
75
+ } catch {
76
+ print("✨ Capacitor-updater: File not removed. \(source.path)")
77
+ }
78
+ }
79
+
80
+ private func unflatFolder(source: URL, dest: URL) -> Bool {
81
+ let index = source.appendingPathComponent("index.html")
82
+ do {
83
+ let files = try FileManager.default.contentsOfDirectory(atPath: source.path)
84
+ if (files.count == 1 && source.appendingPathComponent(files[0]).isDirectory && !FileManager.default.fileExists(atPath: index.path)) {
85
+ try FileManager.default.moveItem(at: source.appendingPathComponent(files[0]), to: dest)
86
+ return true
87
+ } else {
88
+ try FileManager.default.moveItem(at: source, to: dest)
89
+ return false
90
+ }
91
+ } catch {
92
+ print("✨ Capacitor-updater: File not moved. source: \(source.path) dest: \(dest.path)")
93
+ return true
94
+ }
95
+ }
96
+
97
+ private func saveDownloaded(sourceZip: URL, version: String, base: URL) {
98
+ prepareFolder(source: base)
99
+ let destHot = base.appendingPathComponent(version)
100
+ let destUnZip = documentsUrl.appendingPathComponent(randomString(length: 10))
101
+ SSZipArchive.unzipFile(atPath: sourceZip.path, toDestination: destUnZip.path)
102
+ if (unflatFolder(source: destUnZip, dest: destHot)) {
103
+ deleteFolder(source: destUnZip)
104
+ }
105
+ }
106
+
107
+ @objc public func getLatest(url: URL) -> AppVersion? {
108
+ let semaphore = DispatchSemaphore(value: 0)
109
+ let latest = AppVersion()
110
+ let headers: HTTPHeaders = [
111
+ "cap_platform": "ios",
112
+ "cap_device_id": self.deviceID,
113
+ "cap_app_id": self.appId,
114
+ "cap_version_build": self.versionBuild,
115
+ "cap_plugin_version": self.pluginVersion,
116
+ "cap_version_name": UserDefaults.standard.string(forKey: "versionName") ?? "builtin"
117
+ ]
118
+ let request = AF.request(url, headers: headers)
119
+
120
+ request.validate().responseDecodable(of: AppVersionDec.self) { response in
121
+ switch response.result {
122
+ case .success:
123
+ if let url = response.value?.url {
124
+ latest.url = url
125
+ }
126
+ if let version = response.value?.version {
127
+ latest.version = version
128
+ }
129
+ if let major = response.value?.major {
130
+ latest.major = major
131
+ }
132
+ if let message = response.value?.message {
133
+ latest.message = message
134
+ }
135
+ case let .failure(error):
136
+ print("✨ Capacitor-updater: Error getting Latest", error )
137
+ }
138
+ semaphore.signal()
139
+ }
140
+ semaphore.wait()
141
+ return latest.url != "" ? latest : nil
142
+ }
143
+
144
+ @objc public func download(url: URL) -> String? {
145
+ let semaphore = DispatchSemaphore(value: 0)
146
+ var version: String? = nil
147
+ let destination: DownloadRequest.Destination = { _, _ in
148
+ let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
149
+ let fileURL = documentsURL.appendingPathComponent(self.randomString(length: 10))
150
+
151
+ return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
152
+ }
153
+ let request = AF.download(url, to: destination)
154
+
155
+ request.downloadProgress { progress in
156
+ let percent = self.calcTotalPercent(percent: Int(progress.fractionCompleted * 100), min: 10, max: 70)
157
+ self.notifyDownload(percent)
158
+ }
159
+ request.responseURL { (response) in
160
+ if let fileURL = response.fileURL {
161
+ switch response.result {
162
+ case .success:
163
+ self.notifyDownload(71);
164
+ version = self.randomString(length: 10)
165
+ self.saveDownloaded(sourceZip: fileURL, version: version!, base: self.documentsUrl.appendingPathComponent(self.basePathHot))
166
+ self.notifyDownload(85);
167
+ self.saveDownloaded(sourceZip: fileURL, version: version!, base: self.libraryUrl.appendingPathComponent(self.basePathPersist))
168
+ self.notifyDownload(100);
169
+ self.deleteFolder(source: fileURL)
170
+ case let .failure(error):
171
+ print("✨ Capacitor-updater: download error", error)
172
+ version = nil
173
+ }
174
+ }
175
+ semaphore.signal()
176
+ }
177
+ self.notifyDownload(0);
178
+ semaphore.wait()
179
+ return version
180
+ }
181
+
182
+ @objc public func list() -> [String] {
183
+ let dest = documentsUrl.appendingPathComponent(basePathHot)
184
+ do {
185
+ let files = try FileManager.default.contentsOfDirectory(atPath: dest.path)
186
+ return files
187
+ } catch {
188
+ print("✨ Capacitor-updater: No version available \(dest.path)")
189
+ return []
190
+ }
191
+ }
192
+
193
+ @objc public func delete(version: String, versionName: String) -> Bool {
194
+ let destHot = documentsUrl.appendingPathComponent(basePathHot).appendingPathComponent(version)
195
+ let destPersist = libraryUrl.appendingPathComponent(basePathPersist).appendingPathComponent(version)
196
+ do {
197
+ try FileManager.default.removeItem(atPath: destHot.path)
198
+ } catch {
199
+ print("✨ Capacitor-updater: Hot Folder \(destHot.path), not removed.")
200
+ }
201
+ do {
202
+ try FileManager.default.removeItem(atPath: destPersist.path)
203
+ } catch {
204
+ print("✨ Capacitor-updater: Folder \(destPersist.path), not removed.")
205
+ return false
206
+ }
207
+ sendStats(action: "delete", version: versionName)
208
+ return true
209
+ }
210
+
211
+ @objc public func set(version: String, versionName: String) -> Bool {
212
+ let destHot = documentsUrl.appendingPathComponent(basePathHot).appendingPathComponent(version)
213
+ let indexHot = destHot.appendingPathComponent("index.html")
214
+ let destHotPersist = libraryUrl.appendingPathComponent(basePathPersist).appendingPathComponent(version)
215
+ let indexPersist = destHotPersist.appendingPathComponent("index.html")
216
+ if (destHot.isDirectory && destHotPersist.isDirectory && indexHot.exist && indexPersist.exist) {
217
+ UserDefaults.standard.set(destHot.path, forKey: "lastPathHot")
218
+ UserDefaults.standard.set(destHotPersist.path, forKey: "lastPathPersist")
219
+ UserDefaults.standard.set(versionName, forKey: "versionName")
220
+ sendStats(action: "set", version: versionName)
221
+ return true
222
+ }
223
+ sendStats(action: "set_fail", version: versionName)
224
+ return false
225
+ }
226
+
227
+ @objc public func getLastPathHot() -> String {
228
+ return UserDefaults.standard.string(forKey: "lastPathHot") ?? ""
229
+ }
230
+
231
+ @objc public func getVersionName() -> String {
232
+ return UserDefaults.standard.string(forKey: "versionName") ?? ""
233
+ }
234
+
235
+ @objc public func getLastPathPersist() -> String {
236
+ return UserDefaults.standard.string(forKey: "lastPathPersist") ?? ""
237
+ }
238
+
239
+ @objc public func reset() {
240
+ let version = UserDefaults.standard.string(forKey: "versionName") ?? ""
241
+ sendStats(action: "reset", version: version)
242
+ UserDefaults.standard.set("", forKey: "lastPathHot")
243
+ UserDefaults.standard.set("", forKey: "lastPathPersist")
244
+ UserDefaults.standard.set("", forKey: "versionName")
245
+ UserDefaults.standard.synchronize()
246
+ }
247
+
248
+ @objc func sendStats(action: String, version: String) {
249
+ if (statsUrl == "") { return }
250
+ let parameters: [String: String] = [
251
+ "platform": "ios",
252
+ "action": action,
253
+ "device_id": self.deviceID,
254
+ "version_name": version,
255
+ "version_build": self.versionBuild,
256
+ "plugin_version": self.pluginVersion,
257
+ "app_id": self.appId
258
+ ]
259
+
260
+ DispatchQueue.global(qos: .background).async {
261
+ let _ = AF.request(self.statsUrl, method: .post,parameters: parameters, encoder: JSONParameterEncoder.default)
262
+ print("✨ Capacitor-updater: Stats send for \(action), version \(version)")
263
+ }
264
+ }
265
+
266
+ }
@@ -0,0 +1,10 @@
1
+ #import <UIKit/UIKit.h>
2
+
3
+ //! Project version number for Plugin.
4
+ FOUNDATION_EXPORT double PluginVersionNumber;
5
+
6
+ //! Project version string for Plugin.
7
+ FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8
+
9
+ // In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
10
+
@@ -0,0 +1,18 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <Capacitor/Capacitor.h>
3
+
4
+ // Define the plugin using the CAP_PLUGIN Macro, and
5
+ // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
+ CAP_PLUGIN(CapacitorUpdaterPlugin, "CapacitorUpdater",
7
+ CAP_PLUGIN_METHOD(download, CAPPluginReturnPromise);
8
+ CAP_PLUGIN_METHOD(set, CAPPluginReturnPromise);
9
+ CAP_PLUGIN_METHOD(list, CAPPluginReturnPromise);
10
+ CAP_PLUGIN_METHOD(delete, CAPPluginReturnPromise);
11
+ CAP_PLUGIN_METHOD(reset, CAPPluginReturnPromise);
12
+ CAP_PLUGIN_METHOD(current, CAPPluginReturnPromise);
13
+ CAP_PLUGIN_METHOD(reload, CAPPluginReturnPromise);
14
+ CAP_PLUGIN_METHOD(versionName, CAPPluginReturnPromise);
15
+ CAP_PLUGIN_METHOD(notifyAppReady, CAPPluginReturnPromise);
16
+ CAP_PLUGIN_METHOD(delayUpdate, CAPPluginReturnPromise);
17
+ CAP_PLUGIN_METHOD(getId, CAPPluginReturnPromise);
18
+ )