mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 10:21:37 +08:00
ensure logger is ready
This commit is contained in:
@@ -52,6 +52,16 @@ export class Pushy {
|
|||||||
marked = false;
|
marked = false;
|
||||||
applyingUpdate = false;
|
applyingUpdate = false;
|
||||||
version = cInfo.pushy;
|
version = cInfo.pushy;
|
||||||
|
loggerPromise = (() => {
|
||||||
|
let resolve;
|
||||||
|
const promise = new Promise((res) => {
|
||||||
|
resolve = res;
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
promise,
|
||||||
|
resolve
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
constructor(options: PushyOptions) {
|
constructor(options: PushyOptions) {
|
||||||
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
||||||
@@ -60,6 +70,14 @@ export class Pushy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.setOptions(options);
|
this.setOptions(options);
|
||||||
|
if (isRolledBack) {
|
||||||
|
this.report({
|
||||||
|
type: 'rollback',
|
||||||
|
data: {
|
||||||
|
rolledBackVersion,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setOptions = (options: Partial<PushyOptions>) => {
|
setOptions = (options: Partial<PushyOptions>) => {
|
||||||
@@ -67,20 +85,13 @@ export class Pushy {
|
|||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
(this.options as any)[key] = value;
|
(this.options as any)[key] = value;
|
||||||
if (key === 'logger') {
|
if (key === 'logger') {
|
||||||
if (isRolledBack) {
|
this.loggerPromise.resolve();
|
||||||
this.report({
|
|
||||||
type: 'rollback',
|
|
||||||
data: {
|
|
||||||
rolledBackVersion,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
report = ({
|
report = async ({
|
||||||
type,
|
type,
|
||||||
message = '',
|
message = '',
|
||||||
data = {},
|
data = {},
|
||||||
@@ -90,6 +101,7 @@ export class Pushy {
|
|||||||
data?: Record<string, string | number>;
|
data?: Record<string, string | number>;
|
||||||
}) => {
|
}) => {
|
||||||
log(type + ' ' + message);
|
log(type + ' ' + message);
|
||||||
|
await this.loggerPromise.promise;
|
||||||
const { logger = noop, appKey } = this.options;
|
const { logger = noop, appKey } = this.options;
|
||||||
logger({
|
logger({
|
||||||
type,
|
type,
|
||||||
|
Reference in New Issue
Block a user