MCPcopy Index your code
hub / github.com/reactnativecn/react-native-update / Pushy

Class Pushy

src/client.ts:115–721  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114// for China users
115export class Pushy {
116 options = defaultClientOptions;
117 clientType: 'Pushy' | 'Cresc' = 'Pushy';
118 lastChecking?: number;
119 lastRespJson?: Promise<CheckResult>;
120
121 version = cInfo.rnu;
122 loggerPromise = (() => {
123 let resolve: (value?: unknown) => void = () => {};
124 const promise = new Promise(res => {
125 resolve = res;
126 });
127 return {
128 promise,
129 resolve,
130 };
131 })();
132
133 constructor(options: ClientOptions, clientType?: 'Pushy' | 'Cresc') {
134 this.clientType = clientType || 'Pushy';
135 this.options.server = cloneServerConfig(SERVER_PRESETS[this.clientType]);
136
137 i18n.setLocale(options.locale ?? this.clientType === 'Pushy' ? 'zh' : 'en');
138
139 if (Platform.OS === 'ios' || Platform.OS === 'android') {
140 if (!options.appKey) {
141 throw Error(i18n.t('error_appkey_required'));
142 }
143 }
144
145 this.setOptions(options);
146 if (isRolledBack) {
147 this.report({
148 type: 'rollback',
149 data: {
150 rolledBackVersion,
151 },
152 });
153 }
154 }
155
156 setOptions = (options: Partial<ClientOptions>) => {
157 for (const [key, value] of Object.entries(options)) {
158 if (value !== undefined) {
159 (this.options as any)[key] =
160 key === 'server'
161 ? cloneServerConfig(value as UpdateServerConfig)
162 : value;
163 if (key === 'logger') {
164 this.loggerPromise.resolve();
165 }
166 }
167 }
168 };
169
170 /**
171 * Get translated text based on current clientType
172 * @param key - Translation key

Callers

nothing calls this directly

Calls 15

logFunction · 0.90
dedupeEndpointsFunction · 0.90
promiseAnyFunction · 0.90
fetchWithTimeoutFunction · 0.90
infoFunction · 0.90
assertWebFunction · 0.90
testUrlsFunction · 0.90
joinUrlsFunction · 0.90
setLocalHashInfoFunction · 0.90
cloneServerConfigFunction · 0.85
assertHashFunction · 0.85

Tested by

no test coverage detected