mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-12-17 18:22:38 +08:00
resolve harmony hot update fail issue (#483)
* fix harmony more than 2M issue * fix mtpush-react-native conflics * update harmony remote dependency flow * udpate * udpate * udpate * udpate * udpate * update * uddate * udpapte * adapter pushy for Expo * udpate * resolve harmony hot update fail issue * udpate * udpate * udpate * udpate * udpate * update * udpate
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"pushy_build_time": "2025-02-14T09:43:25.648Z",
|
"pushy_build_time": "2025-03-09T01:57:42.464Z",
|
||||||
"versionName": "1.0.0"
|
"versionName": "1.0.0"
|
||||||
}
|
}
|
||||||
@@ -5520,9 +5520,9 @@ mustache@^4.2.0:
|
|||||||
integrity sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==
|
integrity sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==
|
||||||
|
|
||||||
nanoid@^3.3.3:
|
nanoid@^3.3.3:
|
||||||
version "3.3.8"
|
version "3.3.9"
|
||||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.8.tgz#b1be3030bee36aaff18bacb375e5cce521684baf"
|
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.9.tgz#e0097d8e026b3343ff053e9ccd407360a03f503a"
|
||||||
integrity sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==
|
integrity sha512-SppoicMGpZvbF1l3z4x7No3OlIjP7QJvC9XR7AhZr1kL133KHnKPztkKDc+Ir4aJ/1VhTySrtKhrsycmrMQfvg==
|
||||||
|
|
||||||
natural-compare-lite@^1.4.0:
|
natural-compare-lite@^1.4.0:
|
||||||
version "1.4.0"
|
version "1.4.0"
|
||||||
@@ -6003,7 +6003,7 @@ react-is@^17.0.1:
|
|||||||
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
||||||
|
|
||||||
"react-native-update@file:../..":
|
"react-native-update@file:../..":
|
||||||
version "10.19.6"
|
version "10.26.1"
|
||||||
dependencies:
|
dependencies:
|
||||||
nanoid "^3.3.3"
|
nanoid "^3.3.3"
|
||||||
react-native-url-polyfill "^2.0.0"
|
react-native-url-polyfill "^2.0.0"
|
||||||
|
|||||||
@@ -65,9 +65,13 @@ export class DownloadTask {
|
|||||||
0,
|
0,
|
||||||
params.targetFile.lastIndexOf('/'),
|
params.targetFile.lastIndexOf('/'),
|
||||||
);
|
);
|
||||||
await fileIo.mkdir(targetDir);
|
const exists = fileIo.accessSync(targetDir);
|
||||||
|
if(!exists){
|
||||||
|
await fileIo.mkdir(targetDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await httpRequest.request(params.url, {
|
const response = await httpRequest.request(params.url, {
|
||||||
@@ -78,12 +82,11 @@ export class DownloadTask {
|
|||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': 'application/octet-stream',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.responseCode > 299) {
|
if (response.responseCode > 299) {
|
||||||
throw new Error(`Server error: ${response.responseCode}`);
|
throw new Error(`Server error: ${response.responseCode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentLength = parseInt(response.header['Content-Length'] || '0');
|
const contentLength = parseInt(response.header['content-length'] || '0');
|
||||||
const writer = await fileIo.open(
|
const writer = await fileIo.open(
|
||||||
params.targetFile,
|
params.targetFile,
|
||||||
fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE,
|
fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE,
|
||||||
@@ -102,8 +105,12 @@ export class DownloadTask {
|
|||||||
this.onProgressUpdate(received, contentLength);
|
this.onProgressUpdate(received, contentLength);
|
||||||
}
|
}
|
||||||
await fileIo.close(writer);
|
await fileIo.close(writer);
|
||||||
const stat = await fileIo.stat(params.targetFile);
|
const stats = await fileIo.stat(params.targetFile);
|
||||||
const fileSize = stat.size;
|
const fileSize = stats.size;
|
||||||
|
if (fileSize !== contentLength) {
|
||||||
|
throw new Error(`Download incomplete: expected ${contentLength} bytes but got ${stats.size} bytes`);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Download failed:', error);
|
console.error('Download failed:', error);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -113,7 +120,7 @@ export class DownloadTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private onProgressUpdate(received: number, total: number): void {
|
private onProgressUpdate(received: number, total: number): void {
|
||||||
this.eventHub.emit('downloadProgress', {
|
this.eventHub.emit('RCTPushyDownloadProgress', {
|
||||||
received,
|
received,
|
||||||
total,
|
total,
|
||||||
hash: this.hash,
|
hash: this.hash,
|
||||||
@@ -288,8 +295,8 @@ export class DownloadTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entry.filename !== '.DS_Store'){
|
if(fn !== '.DS_Store'){
|
||||||
await zip.decompressFile(entry.filename, params.unzipDirectory);
|
await zip.decompressFile(fn, params.unzipDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ type EventCallback = (data: any) => void;
|
|||||||
export class EventHub {
|
export class EventHub {
|
||||||
private static instance: EventHub;
|
private static instance: EventHub;
|
||||||
private listeners: Map<string, Set<EventCallback>>;
|
private listeners: Map<string, Set<EventCallback>>;
|
||||||
|
private rnInstance: any;
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
this.listeners = new Map();
|
this.listeners = new Map();
|
||||||
@@ -27,12 +28,12 @@ export class EventHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public emit(event: string, data: any): void {
|
public emit(event: string, data: any): void {
|
||||||
this.listeners.get(event)?.forEach(callback => {
|
if (this.rnInstance) {
|
||||||
try {
|
this.rnInstance.emitDeviceEvent(event, data);
|
||||||
callback(data);
|
}
|
||||||
} catch (error) {
|
}
|
||||||
console.error(`Error in event listener for ${event}:`, error);
|
|
||||||
}
|
setRNInstance(instance: any) {
|
||||||
});
|
this.rnInstance = instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import { BusinessError } from '@ohos.base';
|
|||||||
import logger from './Logger';
|
import logger from './Logger';
|
||||||
import { UpdateModuleImpl } from './UpdateModuleImpl';
|
import { UpdateModuleImpl } from './UpdateModuleImpl';
|
||||||
import { UpdateContext } from './UpdateContext';
|
import { UpdateContext } from './UpdateContext';
|
||||||
|
import { EventHub } from './EventHub';
|
||||||
|
|
||||||
const TAG = "PushyTurboModule"
|
const TAG = "PushyTurboModule"
|
||||||
|
|
||||||
@@ -18,9 +19,8 @@ export class PushyTurboModule extends TurboModule {
|
|||||||
super(ctx);
|
super(ctx);
|
||||||
logger.debug(TAG, ",PushyTurboModule constructor");
|
logger.debug(TAG, ",PushyTurboModule constructor");
|
||||||
this.mUiCtx = ctx.uiAbilityContext
|
this.mUiCtx = ctx.uiAbilityContext
|
||||||
let rnInstance = ctx.rnInstance
|
|
||||||
this.context = new UpdateContext(this.mUiCtx)
|
this.context = new UpdateContext(this.mUiCtx)
|
||||||
// rnInstance.emitDeviceEvent("Pushy",{code: err.code, message: err.message});
|
EventHub.getInstance().setRNInstance(ctx.rnInstance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,14 @@ export class UpdateContext {
|
|||||||
this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
|
this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
|
||||||
const packageVersion = this.getPackageVersion();
|
const packageVersion = this.getPackageVersion();
|
||||||
const storedVersion = this.preferences.getSync('packageVersion', '');
|
const storedVersion = this.preferences.getSync('packageVersion', '');
|
||||||
if (packageVersion !== storedVersion) {
|
if(!storedVersion){
|
||||||
this.preferences.clear();
|
this.preferences.putSync('packageVersion', packageVersion);
|
||||||
this.preferences.putSync('packageVersion', packageVersion);
|
this.preferences.flush();
|
||||||
this.preferences.flush();
|
} else if (storedVersion && packageVersion !== storedVersion) {
|
||||||
this.cleanUp();
|
this.preferences.clear();
|
||||||
|
this.preferences.putSync('packageVersion', packageVersion);
|
||||||
|
this.preferences.flush();
|
||||||
|
this.cleanUp();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to init preferences:', e);
|
console.error('Failed to init preferences:', e);
|
||||||
@@ -137,8 +140,9 @@ export class UpdateContext {
|
|||||||
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
||||||
|
|
||||||
const downloadTask = new DownloadTask(this.context);
|
const downloadTask = new DownloadTask(this.context);
|
||||||
await downloadTask.execute(params);
|
return await downloadTask.execute(params);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
console.error('Failed to download APK patch:', e);
|
console.error('Failed to download APK patch:', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,14 +156,13 @@ export class UpdateContext {
|
|||||||
|
|
||||||
const lastVersion = this.getKv('currentVersion');
|
const lastVersion = this.getKv('currentVersion');
|
||||||
this.setKv('currentVersion', hash);
|
this.setKv('currentVersion', hash);
|
||||||
|
|
||||||
if (lastVersion && lastVersion !== hash) {
|
if (lastVersion && lastVersion !== hash) {
|
||||||
this.setKv('lastVersion', lastVersion);
|
this.setKv('lastVersion', lastVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setKv('firstTime', 'true');
|
this.setKv('firstTime', 'true');
|
||||||
this.setKv('firstTimeOk', 'false');
|
this.setKv('firstTimeOk', 'false');
|
||||||
this.setKv('rolledBackVersion', null);
|
this.setKv('rolledBackVersion', "");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to switch version:', e);
|
console.error('Failed to switch version:', e);
|
||||||
}
|
}
|
||||||
@@ -211,7 +214,7 @@ export class UpdateContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getCurrentVersion() : string {
|
public getCurrentVersion() : string {
|
||||||
const currentVersion = this.preferences.getSync('currentVersion', '') as string;
|
const currentVersion = this.getKv('currentVersion');
|
||||||
return currentVersion;
|
return currentVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export class UpdateModuleImpl {
|
|||||||
options: { updateUrl: string; hash: string }
|
options: { updateUrl: string; hash: string }
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await updateContext.downloadPatchFromPackage(options.updateUrl, options.hash, {
|
return await updateContext.downloadPatchFromPackage(options.updateUrl, options.hash, {
|
||||||
onDownloadCompleted: (params: DownloadTaskParams) => {
|
onDownloadCompleted: (params: DownloadTaskParams) => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
promiseAny,
|
promiseAny,
|
||||||
testUrls,
|
testUrls,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { EmitterSubscription, Platform } from 'react-native';
|
import { EmitterSubscription, Platform, DeviceEventEmitter } from 'react-native';
|
||||||
import { PermissionsAndroid } from './permissions';
|
import { PermissionsAndroid } from './permissions';
|
||||||
import {
|
import {
|
||||||
PushyModule,
|
PushyModule,
|
||||||
@@ -350,14 +350,25 @@ export class Pushy {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (onDownloadProgress) {
|
if (onDownloadProgress) {
|
||||||
Pushy.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
|
if (Platform.OS === 'harmony') {
|
||||||
'RCTPushyDownloadProgress',
|
Pushy.progressHandlers[hash] = DeviceEventEmitter.addListener(
|
||||||
progressData => {
|
'RCTPushyDownloadProgress',
|
||||||
if (progressData.hash === hash) {
|
progressData => {
|
||||||
onDownloadProgress(progressData);
|
if (progressData.hash === hash) {
|
||||||
}
|
onDownloadProgress(progressData);
|
||||||
},
|
}
|
||||||
);
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Pushy.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
|
||||||
|
'RCTPushyDownloadProgress',
|
||||||
|
progressData => {
|
||||||
|
if (progressData.hash === hash) {
|
||||||
|
onDownloadProgress(progressData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let succeeded = '';
|
let succeeded = '';
|
||||||
this.report({ type: 'downloading' });
|
this.report({ type: 'downloading' });
|
||||||
|
|||||||
Reference in New Issue
Block a user