Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 4 additions & 4 deletions Example/harmony_use_pushy/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
25 changes: 16 additions & 9 deletions harmony/src/main/ets/DownloadTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -491,4 +498,4 @@ export class DownloadTask {
params.listener?.onDownloadFailed(error);
}
}
}
}
15 changes: 8 additions & 7 deletions harmony/src/main/ets/EventHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions harmony/src/main/ets/PushyTurboModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
}


Expand Down
21 changes: 12 additions & 9 deletions harmony/src/main/ets/UpdateContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion harmony/src/main/ets/UpdateModuleImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down
29 changes: 20 additions & 9 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
promiseAny,
testUrls,
} from './utils';
import { EmitterSubscription, Platform } from 'react-native';
import { EmitterSubscription, Platform, DeviceEventEmitter } from 'react-native';

Check failure on line 12 in src/client.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

Replace `·EmitterSubscription,·Platform,·DeviceEventEmitter·` with `⏎··EmitterSubscription,⏎··Platform,⏎··DeviceEventEmitter,⏎`
import { PermissionsAndroid } from './permissions';
import {
PushyModule,
Expand Down Expand Up @@ -350,14 +350,25 @@
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' });
Expand Down
Loading