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