react-native-nitro-version-check 0.0.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.
- package/NitroVersionCheck.podspec +31 -0
- package/README.md +117 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +142 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/java/com/margelo/nitro/nitroversioncheck/HybridVersionCheck.kt +74 -0
- package/android/src/main/java/com/margelo/nitro/nitroversioncheck/NitroVersionCheckPackage.kt +18 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridVersionCheck.swift +71 -0
- package/lib/index.d.ts +168 -0
- package/lib/index.js +174 -0
- package/lib/semver.d.ts +22 -0
- package/lib/semver.js +51 -0
- package/lib/specs/Version.nitro.d.ts +14 -0
- package/lib/specs/Version.nitro.js +1 -0
- package/lib/types/UpdateResult.d.ts +6 -0
- package/lib/types/UpdateResult.js +1 -0
- package/nitro.json +18 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroVersionCheck+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroVersionCheck+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroVersionCheckOnLoad.cpp +47 -0
- package/nitrogen/generated/android/NitroVersionCheckOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JHybridVersionCheckSpec.cpp +129 -0
- package/nitrogen/generated/android/c++/JHybridVersionCheckSpec.hpp +72 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroversioncheck/HybridVersionCheckSpec.kt +84 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitroversioncheck/NitroVersionCheckOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroVersionCheck+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroVersionCheck-Swift-Cxx-Bridge.cpp +57 -0
- package/nitrogen/generated/ios/NitroVersionCheck-Swift-Cxx-Bridge.hpp +179 -0
- package/nitrogen/generated/ios/NitroVersionCheck-Swift-Cxx-Umbrella.hpp +46 -0
- package/nitrogen/generated/ios/NitroVersionCheckAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroVersionCheckAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridVersionCheckSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridVersionCheckSpecSwift.hpp +123 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridVersionCheckSpec.swift +61 -0
- package/nitrogen/generated/ios/swift/HybridVersionCheckSpec_cxx.swift +227 -0
- package/nitrogen/generated/shared/c++/HybridVersionCheckSpec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridVersionCheckSpec.hpp +70 -0
- package/package.json +116 -0
- package/react-native.config.js +16 -0
- package/src/index.ts +185 -0
- package/src/semver.ts +54 -0
- package/src/specs/Version.nitro.ts +16 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { UpdateLevel } from "./semver";
|
|
2
|
+
import { compareVersions } from "./semver";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the device's current 2-letter ISO country code.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* getCountry() // "US"
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const getCountry: () => string;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the store URL for this app.
|
|
14
|
+
*
|
|
15
|
+
* Automatically resolves to the App Store on iOS and Play Store on Android.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const url = await getStoreUrl();
|
|
20
|
+
* Linking.openURL(url);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const getStoreUrl: () => Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Fetches the latest version of this app available in the store.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const latest = await getLatestVersion(); // "1.3.0"
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const getLatestVersion: () => Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks whether an app update is available.
|
|
35
|
+
*
|
|
36
|
+
* Uses semantic version comparison. By default checks for any version
|
|
37
|
+
* increase, but you can filter by granularity:
|
|
38
|
+
*
|
|
39
|
+
* - `"major"` — only returns `true` for major bumps (1.x → 2.x)
|
|
40
|
+
* - `"minor"` — returns `true` for major or minor bumps
|
|
41
|
+
* - `"patch"` — returns `true` for any version increase (default)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* if (await needsUpdate()) {
|
|
46
|
+
* const url = await getStoreUrl();
|
|
47
|
+
* Linking.openURL(url);
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // Only prompt for major updates
|
|
51
|
+
* const majorUpdate = await needsUpdate({ level: "major" });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const needsUpdate: (options?: {
|
|
55
|
+
level?: UpdateLevel;
|
|
56
|
+
}) => Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* All version-check APIs in one object.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* VersionCheck.version // "1.2.0"
|
|
63
|
+
* VersionCheck.buildNumber // "42"
|
|
64
|
+
* VersionCheck.packageName // "com.example.app"
|
|
65
|
+
* VersionCheck.getCountry() // "US"
|
|
66
|
+
*
|
|
67
|
+
* const url = await VersionCheck.getStoreUrl();
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const VersionCheck: {
|
|
71
|
+
/**
|
|
72
|
+
* The current app version string.
|
|
73
|
+
*
|
|
74
|
+
* Read from `CFBundleShortVersionString` on iOS and `versionName` on Android.
|
|
75
|
+
* Cached at module init, so repeated reads have zero native overhead.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* VersionCheck.version // "1.2.0"
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
readonly version: string;
|
|
83
|
+
/**
|
|
84
|
+
* The current build number.
|
|
85
|
+
*
|
|
86
|
+
* Read from `CFBundleVersion` on iOS and `versionCode` on Android.
|
|
87
|
+
* Cached at module init.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* VersionCheck.buildNumber // "42"
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
readonly buildNumber: string;
|
|
95
|
+
/**
|
|
96
|
+
* The app's unique identifier.
|
|
97
|
+
*
|
|
98
|
+
* This is the Bundle ID on iOS and the Application ID on Android.
|
|
99
|
+
* Cached at module init.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* VersionCheck.packageName // "com.example.app"
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
readonly packageName: string;
|
|
107
|
+
/**
|
|
108
|
+
* Where the app was installed from, or `undefined` for dev/sideloaded builds.
|
|
109
|
+
*
|
|
110
|
+
* - iOS: `"appstore"` | `"testflight"` | `undefined`
|
|
111
|
+
* - Android: `"playstore"` | `undefined`
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* if (VersionCheck.installSource === "testflight") {
|
|
116
|
+
* // running a TestFlight build
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
readonly installSource: string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Returns the device's current 2-letter ISO country code.
|
|
123
|
+
*
|
|
124
|
+
* This is a synchronous Nitro call, no `await` needed.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* VersionCheck.getCountry() // "US"
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
readonly getCountry: () => string;
|
|
132
|
+
/**
|
|
133
|
+
* Returns the App Store (iOS) or Play Store (Android) URL for this app.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const url = await VersionCheck.getStoreUrl();
|
|
138
|
+
* Linking.openURL(url);
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
readonly getStoreUrl: () => Promise<string>;
|
|
142
|
+
/**
|
|
143
|
+
* Fetches the latest version of this app available in the store.
|
|
144
|
+
*
|
|
145
|
+
* Queries the iTunes API on iOS and the Play Store on Android.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* const latest = await VersionCheck.getLatestVersion(); // "1.3.0"
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
readonly getLatestVersion: () => Promise<string>;
|
|
153
|
+
/**
|
|
154
|
+
* Checks whether an app update is available by comparing the current
|
|
155
|
+
* version against the latest store version.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* if (await VersionCheck.needsUpdate()) {
|
|
160
|
+
* const url = await VersionCheck.getStoreUrl();
|
|
161
|
+
* Linking.openURL(url);
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
readonly needsUpdate: () => Promise<boolean>;
|
|
166
|
+
};
|
|
167
|
+
export { compareVersions };
|
|
168
|
+
export type { UpdateLevel };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { NitroModules } from "react-native-nitro-modules";
|
|
2
|
+
import { compareVersions, isNewerVersion } from "./semver";
|
|
3
|
+
const HybridVersionCheck = NitroModules.createHybridObject("VersionCheck");
|
|
4
|
+
// Cached at module init — plain JS values, no JSI overhead on repeated access.
|
|
5
|
+
const version = HybridVersionCheck.version;
|
|
6
|
+
const buildNumber = HybridVersionCheck.buildNumber;
|
|
7
|
+
const packageName = HybridVersionCheck.packageName;
|
|
8
|
+
const installSource = HybridVersionCheck.installSource;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the device's current 2-letter ISO country code.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* getCountry() // "US"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const getCountry = () => HybridVersionCheck.getCountry();
|
|
18
|
+
/**
|
|
19
|
+
* Returns the store URL for this app.
|
|
20
|
+
*
|
|
21
|
+
* Automatically resolves to the App Store on iOS and Play Store on Android.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const url = await getStoreUrl();
|
|
26
|
+
* Linking.openURL(url);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const getStoreUrl = () => HybridVersionCheck.getStoreUrl();
|
|
30
|
+
/**
|
|
31
|
+
* Fetches the latest version of this app available in the store.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const latest = await getLatestVersion(); // "1.3.0"
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const getLatestVersion = () => HybridVersionCheck.getLatestVersion();
|
|
39
|
+
/**
|
|
40
|
+
* Checks whether an app update is available.
|
|
41
|
+
*
|
|
42
|
+
* Uses semantic version comparison. By default checks for any version
|
|
43
|
+
* increase, but you can filter by granularity:
|
|
44
|
+
*
|
|
45
|
+
* - `"major"` — only returns `true` for major bumps (1.x → 2.x)
|
|
46
|
+
* - `"minor"` — returns `true` for major or minor bumps
|
|
47
|
+
* - `"patch"` — returns `true` for any version increase (default)
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* if (await needsUpdate()) {
|
|
52
|
+
* const url = await getStoreUrl();
|
|
53
|
+
* Linking.openURL(url);
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* // Only prompt for major updates
|
|
57
|
+
* const majorUpdate = await needsUpdate({ level: "major" });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export const needsUpdate = async (options) => {
|
|
61
|
+
const latest = await HybridVersionCheck.getLatestVersion();
|
|
62
|
+
return isNewerVersion(version, latest, options?.level ?? "patch");
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* All version-check APIs in one object.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* VersionCheck.version // "1.2.0"
|
|
70
|
+
* VersionCheck.buildNumber // "42"
|
|
71
|
+
* VersionCheck.packageName // "com.example.app"
|
|
72
|
+
* VersionCheck.getCountry() // "US"
|
|
73
|
+
*
|
|
74
|
+
* const url = await VersionCheck.getStoreUrl();
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export const VersionCheck = {
|
|
78
|
+
/**
|
|
79
|
+
* The current app version string.
|
|
80
|
+
*
|
|
81
|
+
* Read from `CFBundleShortVersionString` on iOS and `versionName` on Android.
|
|
82
|
+
* Cached at module init, so repeated reads have zero native overhead.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* VersionCheck.version // "1.2.0"
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
version,
|
|
90
|
+
/**
|
|
91
|
+
* The current build number.
|
|
92
|
+
*
|
|
93
|
+
* Read from `CFBundleVersion` on iOS and `versionCode` on Android.
|
|
94
|
+
* Cached at module init.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* VersionCheck.buildNumber // "42"
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
buildNumber,
|
|
102
|
+
/**
|
|
103
|
+
* The app's unique identifier.
|
|
104
|
+
*
|
|
105
|
+
* This is the Bundle ID on iOS and the Application ID on Android.
|
|
106
|
+
* Cached at module init.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* VersionCheck.packageName // "com.example.app"
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
packageName,
|
|
114
|
+
/**
|
|
115
|
+
* Where the app was installed from, or `undefined` for dev/sideloaded builds.
|
|
116
|
+
*
|
|
117
|
+
* - iOS: `"appstore"` | `"testflight"` | `undefined`
|
|
118
|
+
* - Android: `"playstore"` | `undefined`
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* if (VersionCheck.installSource === "testflight") {
|
|
123
|
+
* // running a TestFlight build
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
installSource,
|
|
128
|
+
/**
|
|
129
|
+
* Returns the device's current 2-letter ISO country code.
|
|
130
|
+
*
|
|
131
|
+
* This is a synchronous Nitro call, no `await` needed.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* VersionCheck.getCountry() // "US"
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
getCountry,
|
|
139
|
+
/**
|
|
140
|
+
* Returns the App Store (iOS) or Play Store (Android) URL for this app.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const url = await VersionCheck.getStoreUrl();
|
|
145
|
+
* Linking.openURL(url);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
getStoreUrl,
|
|
149
|
+
/**
|
|
150
|
+
* Fetches the latest version of this app available in the store.
|
|
151
|
+
*
|
|
152
|
+
* Queries the iTunes API on iOS and the Play Store on Android.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const latest = await VersionCheck.getLatestVersion(); // "1.3.0"
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
getLatestVersion,
|
|
160
|
+
/**
|
|
161
|
+
* Checks whether an app update is available by comparing the current
|
|
162
|
+
* version against the latest store version.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* if (await VersionCheck.needsUpdate()) {
|
|
167
|
+
* const url = await VersionCheck.getStoreUrl();
|
|
168
|
+
* Linking.openURL(url);
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
needsUpdate: () => HybridVersionCheck.needsUpdate(),
|
|
173
|
+
};
|
|
174
|
+
export { compareVersions };
|
package/lib/semver.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type UpdateLevel = "major" | "minor" | "patch";
|
|
2
|
+
/**
|
|
3
|
+
* Compares two version strings.
|
|
4
|
+
*
|
|
5
|
+
* @returns `-1` if `v1 < v2`, `0` if equal, `1` if `v1 > v2`
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* compareVersions("1.2.0", "1.3.0") // -1
|
|
10
|
+
* compareVersions("2.0.0", "1.9.9") // 1
|
|
11
|
+
* compareVersions("1.0.0", "1.0.0") // 0
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function compareVersions(v1: string, v2: string): -1 | 0 | 1;
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether `latest` is newer than `current` at the given granularity.
|
|
17
|
+
*
|
|
18
|
+
* - `"major"` — only returns `true` for major bumps (1.x → 2.x)
|
|
19
|
+
* - `"minor"` — returns `true` for major or minor bumps
|
|
20
|
+
* - `"patch"` — returns `true` for any version increase (default)
|
|
21
|
+
*/
|
|
22
|
+
export declare function isNewerVersion(current: string, latest: string, level?: UpdateLevel): boolean;
|
package/lib/semver.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function parseVersion(version) {
|
|
2
|
+
const parts = version.split(".");
|
|
3
|
+
return [Number(parts[0]) || 0, Number(parts[1]) || 0, Number(parts[2]) || 0];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Compares two version strings.
|
|
7
|
+
*
|
|
8
|
+
* @returns `-1` if `v1 < v2`, `0` if equal, `1` if `v1 > v2`
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* compareVersions("1.2.0", "1.3.0") // -1
|
|
13
|
+
* compareVersions("2.0.0", "1.9.9") // 1
|
|
14
|
+
* compareVersions("1.0.0", "1.0.0") // 0
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function compareVersions(v1, v2) {
|
|
18
|
+
const a = parseVersion(v1);
|
|
19
|
+
const b = parseVersion(v2);
|
|
20
|
+
for (let i = 0; i < 3; i++) {
|
|
21
|
+
if (a[i] > b[i])
|
|
22
|
+
return 1;
|
|
23
|
+
if (a[i] < b[i])
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether `latest` is newer than `current` at the given granularity.
|
|
30
|
+
*
|
|
31
|
+
* - `"major"` — only returns `true` for major bumps (1.x → 2.x)
|
|
32
|
+
* - `"minor"` — returns `true` for major or minor bumps
|
|
33
|
+
* - `"patch"` — returns `true` for any version increase (default)
|
|
34
|
+
*/
|
|
35
|
+
export function isNewerVersion(current, latest, level = "patch") {
|
|
36
|
+
const [curMajor, curMinor, curPatch] = parseVersion(current);
|
|
37
|
+
const [latMajor, latMinor, latPatch] = parseVersion(latest);
|
|
38
|
+
if (latMajor > curMajor)
|
|
39
|
+
return true;
|
|
40
|
+
if (latMajor < curMajor)
|
|
41
|
+
return false;
|
|
42
|
+
if (level === "major")
|
|
43
|
+
return false;
|
|
44
|
+
if (latMinor > curMinor)
|
|
45
|
+
return true;
|
|
46
|
+
if (latMinor < curMinor)
|
|
47
|
+
return false;
|
|
48
|
+
if (level === "minor")
|
|
49
|
+
return false;
|
|
50
|
+
return latPatch > curPatch;
|
|
51
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HybridObject } from "react-native-nitro-modules";
|
|
2
|
+
export interface VersionCheck extends HybridObject<{
|
|
3
|
+
ios: "swift";
|
|
4
|
+
android: "kotlin";
|
|
5
|
+
}> {
|
|
6
|
+
readonly version: string;
|
|
7
|
+
readonly buildNumber: string;
|
|
8
|
+
readonly packageName: string;
|
|
9
|
+
readonly installSource: string | undefined;
|
|
10
|
+
getCountry(): string;
|
|
11
|
+
getStoreUrl(): Promise<string>;
|
|
12
|
+
getLatestVersion(): Promise<string>;
|
|
13
|
+
needsUpdate(): Promise<boolean>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/nitro.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://nitro.margelo.com/nitro.schema.json",
|
|
3
|
+
"cxxNamespace": ["nitroversioncheck"],
|
|
4
|
+
"ios": {
|
|
5
|
+
"iosModuleName": "NitroVersionCheck"
|
|
6
|
+
},
|
|
7
|
+
"android": {
|
|
8
|
+
"androidNamespace": ["nitroversioncheck"],
|
|
9
|
+
"androidCxxLibName": "NitroVersionCheck"
|
|
10
|
+
},
|
|
11
|
+
"autolinking": {
|
|
12
|
+
"VersionCheck": {
|
|
13
|
+
"swift": "HybridVersionCheck",
|
|
14
|
+
"kotlin": "HybridVersionCheck"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"ignorePaths": ["**/node_modules"]
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
** linguist-generated=true
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#
|
|
2
|
+
# NitroVersionCheck+autolinking.cmake
|
|
3
|
+
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
# https://github.com/mrousavy/nitro
|
|
5
|
+
# Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
9
|
+
# to the current CMake project.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your CMakeLists.txt:
|
|
12
|
+
# ```cmake
|
|
13
|
+
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroVersionCheck+autolinking.cmake)
|
|
14
|
+
# ```
|
|
15
|
+
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_NITROVERSIONCHECK_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
22
|
+
# Add all headers that were generated by Nitrogen
|
|
23
|
+
include_directories(
|
|
24
|
+
"../nitrogen/generated/shared/c++"
|
|
25
|
+
"../nitrogen/generated/android/c++"
|
|
26
|
+
"../nitrogen/generated/android/"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
30
|
+
target_sources(
|
|
31
|
+
# CMake project name (Android C++ library name)
|
|
32
|
+
NitroVersionCheck PRIVATE
|
|
33
|
+
# Autolinking Setup
|
|
34
|
+
../nitrogen/generated/android/NitroVersionCheckOnLoad.cpp
|
|
35
|
+
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridVersionCheckSpec.cpp
|
|
37
|
+
# Android-specific Nitrogen C++ sources
|
|
38
|
+
../nitrogen/generated/android/c++/JHybridVersionCheckSpec.cpp
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
42
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
43
|
+
target_compile_definitions(
|
|
44
|
+
NitroVersionCheck PRIVATE
|
|
45
|
+
-DFOLLY_NO_CONFIG=1
|
|
46
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
47
|
+
-DFOLLY_USE_LIBCPP=1
|
|
48
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
49
|
+
-DFOLLY_MOBILE=1
|
|
50
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
51
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
52
|
+
# Once we target android-23 above, we can comment
|
|
53
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
54
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Add all libraries required by the generated specs
|
|
58
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
59
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
60
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
61
|
+
|
|
62
|
+
# Link all libraries together
|
|
63
|
+
target_link_libraries(
|
|
64
|
+
NitroVersionCheck
|
|
65
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
66
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
67
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
71
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
72
|
+
target_link_libraries(
|
|
73
|
+
NitroVersionCheck
|
|
74
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
75
|
+
)
|
|
76
|
+
else()
|
|
77
|
+
target_link_libraries(
|
|
78
|
+
NitroVersionCheck
|
|
79
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
80
|
+
)
|
|
81
|
+
endif()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVersionCheck+autolinking.gradle
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// ```gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/NitroVersionCheck+autolinking.gradle'
|
|
14
|
+
/// ```
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 NitroVersionCheck is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVersionCheckOnLoad.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#ifndef BUILDING_NITROVERSIONCHECK_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error NitroVersionCheckOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "NitroVersionCheckOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "JHybridVersionCheckSpec.hpp"
|
|
19
|
+
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::nitroversioncheck {
|
|
22
|
+
|
|
23
|
+
int initialize(JavaVM* vm) {
|
|
24
|
+
return facebook::jni::initialize(vm, []() {
|
|
25
|
+
::margelo::nitro::nitroversioncheck::registerAllNatives();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void registerAllNatives() {
|
|
30
|
+
using namespace margelo::nitro;
|
|
31
|
+
using namespace margelo::nitro::nitroversioncheck;
|
|
32
|
+
|
|
33
|
+
// Register native JNI methods
|
|
34
|
+
margelo::nitro::nitroversioncheck::JHybridVersionCheckSpec::registerNatives();
|
|
35
|
+
|
|
36
|
+
// Register Nitro Hybrid Objects
|
|
37
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
38
|
+
"VersionCheck",
|
|
39
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
40
|
+
static DefaultConstructableObject<JHybridVersionCheckSpec::javaobject> object("com/margelo/nitro/nitroversioncheck/HybridVersionCheck");
|
|
41
|
+
auto instance = object.create();
|
|
42
|
+
return instance->cthis()->shared();
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
} // namespace margelo::nitro::nitroversioncheck
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVersionCheckOnLoad.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
10
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::nitroversioncheck {
|
|
13
|
+
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register the native (C++) part of NitroVersionCheck, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
21
|
+
* Example:
|
|
22
|
+
* ```cpp (cpp-adapter.cpp)
|
|
23
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all NitroVersionCheck HybridObjects
|
|
26
|
+
* margelo::nitro::nitroversioncheck::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
void registerAllNatives();
|
|
33
|
+
|
|
34
|
+
} // namespace margelo::nitro::nitroversioncheck
|