mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-17 21:56:11 +08:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4231d377e6 |
@@ -18,7 +18,7 @@
|
||||
"react-native": "0.69.8",
|
||||
"react-native-paper": "^5.12.1",
|
||||
"react-native-safe-area-context": "^4.8.2",
|
||||
"react-native-update": "^10.0.2",
|
||||
"react-native-update": "^10.0.0-beta.3",
|
||||
"react-native-vector-icons": "^10.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@@ -6231,10 +6231,10 @@ react-native-safe-area-context@^4.8.2:
|
||||
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.8.2.tgz#e6b3d8acf3c6afcb4b5db03a97f9c37df7668f65"
|
||||
integrity sha512-ffUOv8BJQ6RqO3nLml5gxJ6ab3EestPiyWekxdzO/1MQ7NF8fW1Mzh1C5QE9yq573Xefnc7FuzGXjtesZGv7cQ==
|
||||
|
||||
react-native-update@^10.0.2:
|
||||
version "10.0.2"
|
||||
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.0.2.tgz#2bb01ab6e41e72bbbb535cebd34083b1fed69eb0"
|
||||
integrity sha512-XkEPmTC3X6FV1eXq6uDyjfhXpAaug0HI48Mm+PkbMlXcgFjTrOmtuq7yuvemS2nPG2pwnrYQuGs0A6tE2aoRBA==
|
||||
react-native-update@^10.0.0-beta.3:
|
||||
version "10.0.0-beta.3"
|
||||
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.0.0-beta.3.tgz#cad099ebb40ff04b31ba2df13930517039e4fae3"
|
||||
integrity sha512-Ak1ylgHbOUeaNsq3ItZGRenqqAwYKSTlB6T4sBn4PPNGaMmIMt6uIKKWrQqcNyc9WEy9LlFM6kSqQXBQdaVatw==
|
||||
dependencies:
|
||||
nanoid "^3.3.3"
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.1.0",
|
||||
"version": "10.0.2",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
|
||||
import { CheckResult, PushyOptions, ProgressData } from './type';
|
||||
import { assertRelease, log } from './utils';
|
||||
import {
|
||||
EmitterSubscription,
|
||||
@@ -12,9 +12,9 @@ import {
|
||||
pushyNativeEventEmitter,
|
||||
currentVersion,
|
||||
packageVersion,
|
||||
report,
|
||||
rolledBackVersion,
|
||||
setLocalHashInfo,
|
||||
isRolledBack,
|
||||
} from './core';
|
||||
|
||||
const defaultServer = {
|
||||
@@ -25,8 +25,6 @@ const defaultServer = {
|
||||
};
|
||||
|
||||
const empty = {};
|
||||
const noop = () => {};
|
||||
|
||||
export class Pushy {
|
||||
options: PushyOptions = {
|
||||
appKey: '',
|
||||
@@ -34,7 +32,6 @@ export class Pushy {
|
||||
autoMarkSuccess: true,
|
||||
useAlert: true,
|
||||
strategy: 'both',
|
||||
logger: noop,
|
||||
};
|
||||
|
||||
lastChecking: number;
|
||||
@@ -58,45 +55,10 @@ export class Pushy {
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
if (value !== undefined) {
|
||||
this.options[key] = value;
|
||||
if (key === 'logger') {
|
||||
if (isRolledBack) {
|
||||
this.report({
|
||||
type: 'rollback',
|
||||
data: {
|
||||
rolledBackVersion,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
report = ({
|
||||
type,
|
||||
message = '',
|
||||
data = {},
|
||||
}: {
|
||||
type: EventType;
|
||||
message?: string;
|
||||
data?: Record<string, string | number>;
|
||||
}) => {
|
||||
log(type + ' ' + message);
|
||||
const { logger = noop, appKey } = this.options;
|
||||
logger({
|
||||
type,
|
||||
data: {
|
||||
appKey,
|
||||
currentVersion,
|
||||
cInfo,
|
||||
packageVersion,
|
||||
buildTime,
|
||||
message,
|
||||
...data,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
getCheckUrl = (endpoint: string = this.options.server!.main) => {
|
||||
return `${endpoint}/checkUpdate/${this.options.appKey}`;
|
||||
};
|
||||
@@ -117,7 +79,7 @@ export class Pushy {
|
||||
}
|
||||
this.marked = true;
|
||||
PushyModule.markSuccess();
|
||||
this.report({ type: 'markSuccess' });
|
||||
report({ type: 'markSuccess' });
|
||||
};
|
||||
switchVersion = (hash: string) => {
|
||||
assertRelease();
|
||||
@@ -146,7 +108,7 @@ export class Pushy {
|
||||
return this.lastResult;
|
||||
}
|
||||
this.lastChecking = now;
|
||||
this.report({ type: 'checking' });
|
||||
report({ type: 'checking' });
|
||||
const fetchPayload = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -164,7 +126,7 @@ export class Pushy {
|
||||
try {
|
||||
resp = await fetch(this.getCheckUrl(), fetchPayload);
|
||||
} catch (e) {
|
||||
this.report({
|
||||
report({
|
||||
type: 'errorChecking',
|
||||
message: 'Can not connect to update server. Trying backup endpoints.',
|
||||
});
|
||||
@@ -180,7 +142,7 @@ export class Pushy {
|
||||
}
|
||||
}
|
||||
if (!resp) {
|
||||
this.report({
|
||||
report({
|
||||
type: 'errorChecking',
|
||||
message: 'Can not connect to update server. Please check your network.',
|
||||
});
|
||||
@@ -191,7 +153,7 @@ export class Pushy {
|
||||
this.lastResult = result;
|
||||
|
||||
if (resp.status !== 200) {
|
||||
this.report({
|
||||
report({
|
||||
type: 'errorChecking',
|
||||
message: result.message,
|
||||
});
|
||||
@@ -252,7 +214,7 @@ export class Pushy {
|
||||
);
|
||||
}
|
||||
let succeeded = false;
|
||||
this.report({ type: 'downloading' });
|
||||
report({ type: 'downloading' });
|
||||
if (diffUrl) {
|
||||
log('downloading diff');
|
||||
try {
|
||||
@@ -295,7 +257,7 @@ export class Pushy {
|
||||
delete this.progressHandlers[hash];
|
||||
}
|
||||
if (!succeeded) {
|
||||
return this.report({
|
||||
return report({
|
||||
type: 'errorUpdate',
|
||||
data: { newVersion: hash },
|
||||
});
|
||||
@@ -316,17 +278,17 @@ export class Pushy {
|
||||
if (Platform.OS !== 'android') {
|
||||
return;
|
||||
}
|
||||
this.report({ type: 'downloadingApk' });
|
||||
report({ type: 'downloadingApk' });
|
||||
if (Platform.Version <= 23) {
|
||||
try {
|
||||
const granted = await PermissionsAndroid.request(
|
||||
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
||||
);
|
||||
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
|
||||
return this.report({ type: 'rejectStoragePermission' });
|
||||
return report({ type: 'rejectStoragePermission' });
|
||||
}
|
||||
} catch (err) {
|
||||
return this.report({ type: 'errorStoragePermission' });
|
||||
return report({ type: 'errorStoragePermission' });
|
||||
}
|
||||
}
|
||||
const progressKey = 'downloadingApk';
|
||||
@@ -345,7 +307,7 @@ export class Pushy {
|
||||
target: 'update.apk',
|
||||
hash: progressKey,
|
||||
}).catch(() => {
|
||||
this.report({ type: 'errowDownloadAndInstallApk' });
|
||||
report({ type: 'errowDownloadAndInstallApk' });
|
||||
});
|
||||
if (this.progressHandlers[progressKey]) {
|
||||
this.progressHandlers[progressKey].remove();
|
||||
|
39
src/core.ts
39
src/core.ts
@@ -1,4 +1,5 @@
|
||||
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
||||
import { EventType, UpdateEventsLogger } from './type';
|
||||
import { log } from './utils';
|
||||
const {
|
||||
version: v,
|
||||
@@ -57,6 +58,44 @@ if (!uuid) {
|
||||
PushyModule.setUuid(uuid);
|
||||
}
|
||||
|
||||
const noop = () => {};
|
||||
let reporter: UpdateEventsLogger = noop;
|
||||
|
||||
export function onPushyEvents(customReporter: UpdateEventsLogger) {
|
||||
reporter = customReporter;
|
||||
if (isRolledBack) {
|
||||
report({
|
||||
type: 'rollback',
|
||||
data: {
|
||||
rolledBackVersion,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function report({
|
||||
type,
|
||||
message = '',
|
||||
data = {},
|
||||
}: {
|
||||
type: EventType;
|
||||
message?: string;
|
||||
data?: Record<string, string | number>;
|
||||
}) {
|
||||
log(type + ' ' + message);
|
||||
reporter({
|
||||
type,
|
||||
data: {
|
||||
currentVersion,
|
||||
cInfo,
|
||||
packageVersion,
|
||||
buildTime,
|
||||
message,
|
||||
...data,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
log('uuid: ' + uuid);
|
||||
|
||||
export const cInfo = {
|
||||
|
Reference in New Issue
Block a user