1.修复概率出现jscrash问题 2.修复进度条问题

Signed-off-by: baofeng <baofeng6@h-partners.com>
This commit is contained in:
baofeng 2024-03-14 10:27:54 +08:00
parent 9b90cf9a6e
commit e271199f19
11 changed files with 177 additions and 132 deletions

View File

@ -1,5 +1,11 @@
## 2.1.2-rc.10 ## 2.1.2-rc.11
- 修复概率出现jscrash问题
- 修复进度条问题
- 修复单帧gif图片加载失败 - 修复单帧gif图片加载失败
## 2.1.2-rc.10
- 修复部分gif图片识别成静态图
- 修复同一张图片发送多次请求
- 复用场景缓存到树aboutToRecycle清理定时器 - 复用场景缓存到树aboutToRecycle清理定时器
## 2.1.2-rc.9 ## 2.1.2-rc.9

View File

@ -4,7 +4,7 @@
"name": "entry", "name": "entry",
"description": "example description", "description": "example description",
"repository": {}, "repository": {},
"version": "2.1.2-rc.10", "version": "2.1.2-rc.11",
"dependencies": { "dependencies": {
"@ohos/libraryimageknife": "file:../sharedlibrary", "@ohos/libraryimageknife": "file:../sharedlibrary",
"@ohos/sharedlibrary2": "file:../sharedlibrary2", "@ohos/sharedlibrary2": "file:../sharedlibrary2",

View File

@ -29,7 +29,6 @@ struct TestManyNetImageLoadWithPage2 {
Column() { Column() {
Grid(this.scroller) { Grid(this.scroller) {
LazyForEach(this.data, (item: Material, index) => { LazyForEach(this.data, (item: Material, index) => {
if(index < 100) {
GridItem() { GridItem() {
Stack({ alignContent: Alignment.BottomEnd }) { Stack({ alignContent: Alignment.BottomEnd }) {
ImageKnifeComponent({ ImageKnifeComponent({
@ -39,12 +38,10 @@ struct TestManyNetImageLoadWithPage2 {
mainScaleType: ScaleType.CENTER_CROP, mainScaleType: ScaleType.CENTER_CROP,
placeholderScaleType: ScaleType.CENTER_CROP, placeholderScaleType: ScaleType.CENTER_CROP,
isCacheable: false, isCacheable: false,
// strategy: this.setting strategy: this.setting
} }
}).width('100%').height('100%') }).width('100%').height('100%')
//Grid组件并发加载大量图片会出现白块对比使用image库也会出现 Text(index + "." + item.name)
//Image(item.thumbnail).width('100%').backgroundColor(Color.Blue).objectFit(ImageFit.Contain)
Text(index+"."+item.name)
.fontSize(10) .fontSize(10)
.maxLines(1) .maxLines(1)
.fontColor(Color.White) .fontColor(Color.White)
@ -53,18 +50,15 @@ struct TestManyNetImageLoadWithPage2 {
.width('100%') .width('100%')
.backgroundColor(Color.Orange) .backgroundColor(Color.Orange)
} }
}.width('45%').height(200) }.width('45%').height(200)
}
}, (item: Material) => item.material_id) }, (item: Material) => item.material_id)
} }
.columnsTemplate('1fr 1fr') .columnsTemplate('1fr 1fr')
.columnsGap(8) .columnsGap(8)
.maxCount(8)
.rowsGap(10) .rowsGap(10)
.width('100%') .width('100%')
.hitTestBehavior(HitTestMode.None) .cachedCount(1)
.maxCount(10) .height('100%')
.cachedCount(3)
}.margin({ top: 5 }) }.margin({ top: 5 })
} }
} }

View File

@ -14,7 +14,7 @@
"main": "index.ets", "main": "index.ets",
"repository": "https://gitee.com/openharmony-tpc/ImageKnife", "repository": "https://gitee.com/openharmony-tpc/ImageKnife",
"type": "module", "type": "module",
"version": "2.1.2-rc.10", "version": "2.1.2-rc.11",
"dependencies": { "dependencies": {
"pako": "^2.1.0", "pako": "^2.1.0",
"@ohos/gpu_transform": "^1.0.0" "@ohos/gpu_transform": "^1.0.0"

View File

@ -25,7 +25,7 @@ export class FileReader {
// 读取的长度 // 读取的长度
length: number = 0 length: number = 0
// 读写stream // 读写stream
stream: fs.Stream | null = null stream: fs.Stream
// 缓存buf // 缓存buf
buf: ArrayBuffer = new ArrayBuffer(1) buf: ArrayBuffer = new ArrayBuffer(1)
@ -39,14 +39,9 @@ export class FileReader {
throw new Error('FileReader constructor path is null, checking the parameter') throw new Error('FileReader constructor path is null, checking the parameter')
return; return;
} }
try { this.stream = fs.createStreamSync(path, 'r+');
this.stream = fs.createStreamSync(path, 'r+'); let stat = fs.statSync(path)
let stat = fs.statSync(path) this.fileLength = stat.size
this.fileLength = stat.size
} catch (e) {
console.log(path);
console.log(e.toString());
}
} }
/** /**
@ -54,8 +49,8 @@ export class FileReader {
*/ */
readLine(): string { readLine(): string {
let line = '' let line = ''
while (this.length < this.fileLength) { while (this.stream && this.length < this.fileLength) {
this.stream?.readSync(this.buf, { length: this.length }) this.stream?.readSync(this.buf, { offset: this.length })
this.length++ this.length++
let temp = String.fromCharCode(...new Uint8Array(this.buf)); let temp = String.fromCharCode(...new Uint8Array(this.buf));
line = line + temp line = line + temp
@ -64,7 +59,7 @@ export class FileReader {
// 边界判断 首先拿到下一个字符判断是否是LF 如果是CRLF需要再向后挪一位 // 边界判断 首先拿到下一个字符判断是否是LF 如果是CRLF需要再向后挪一位
if (this.length < this.fileLength) { if (this.length < this.fileLength) {
let nextBuf = new ArrayBuffer(1) let nextBuf = new ArrayBuffer(1)
this.stream?.readSync(nextBuf, { length: this.length }) this.stream?.readSync(nextBuf, { offset: this.length })
let nextTemp = String.fromCharCode(...new Uint8Array(nextBuf)); let nextTemp = String.fromCharCode(...new Uint8Array(nextBuf));
// 如果是CRLF 需要给当前length+1 向后挪一位 // 如果是CRLF 需要给当前length+1 向后挪一位
if (nextTemp == FileReader.LF) { if (nextTemp == FileReader.LF) {

View File

@ -16,7 +16,7 @@
import { DiskLruCache } from "../cache/DiskLruCache" import { DiskLruCache } from "../cache/DiskLruCache"
import { EngineKeyFactories } from "../cache/key/EngineKeyFactories" import { EngineKeyFactories } from "../cache/key/EngineKeyFactories"
import { EngineKeyInterface } from "../cache/key/EngineKeyInterface" import { EngineKeyInterface } from "../cache/key/EngineKeyInterface"
import { RequestOption } from "../imageknife/RequestOption" import { RequestOption, Size } from "../imageknife/RequestOption"
import { AsyncCallback } from "../imageknife/interface/AsyncCallback" import { AsyncCallback } from "../imageknife/interface/AsyncCallback"
import { PlaceHolderManager } from "../imageknife/holder/PlaceHolderManager" import { PlaceHolderManager } from "../imageknife/holder/PlaceHolderManager"
import { RetryHolderManager } from "../imageknife/holder/RetryHolderManager" import { RetryHolderManager } from "../imageknife/holder/RetryHolderManager"
@ -42,17 +42,12 @@ import { MemoryLruCache } from '../cache/MemoryLruCache'
import { BusinessError } from '@kit.BasicServicesKit' import { BusinessError } from '@kit.BasicServicesKit'
import { taskpool } from '@kit.ArkTS' import { taskpool } from '@kit.ArkTS'
import { GIFFrame } from './utils/gif/GIFFrame' import { GIFFrame } from './utils/gif/GIFFrame'
import emitter from '@ohos.events.emitter';
import { MemoryCacheProxy } from './requestmanage/MemoryCacheProxy' import { MemoryCacheProxy } from './requestmanage/MemoryCacheProxy'
import { ObjectKey } from './ObjectKey' import { ObjectKey } from './ObjectKey'
import { TaskParams } from './TaskParams'
export enum ResourceUsage { import { Constants } from './constants/Constants'
PLACEHOLDER = 'placeholder',
RETRYHODLER = 'retryholder',
ERRORHOLDER = 'errorholder',
MAIN = 'main'
}
export class ImageKnife { export class ImageKnife {
static readonly SEPARATOR: string = '/' static readonly SEPARATOR: string = '/'
@ -313,21 +308,21 @@ export class ImageKnife {
this.generateDataCacheKey(request) this.generateDataCacheKey(request)
// 首先执行占位图 解析任务 // 首先执行占位图 解析任务
if (request.placeholderSrc) { if (request.placeholderSrc) {
this.taskpoolLoadResource(request, ResourceUsage.PLACEHOLDER); this.taskpoolLoadResource(request, Constants.PLACE_HOLDER);
} }
// 其次执行重试占位图 解析任务 // 其次执行重试占位图 解析任务
if (request.retryholderSrc) { if (request.retryholderSrc) {
this.taskpoolLoadResource(request, ResourceUsage.RETRYHODLER); this.taskpoolLoadResource(request, Constants.RETRY_HOLDER);
} }
// 最后解析错误占位图 // 最后解析错误占位图
if (request.errorholderSrc) { if (request.errorholderSrc) {
this.taskpoolLoadResource(request, ResourceUsage.ERRORHOLDER); this.taskpoolLoadResource(request, Constants.ERROR_HOLDER);
} }
return this.parseSource(request); return this.parseSource(request);
} }
generateDataCacheKey(request: RequestOption){ generateDataCacheKey(request: RequestOption) {
let factories: EngineKeyInterface; let factories: EngineKeyInterface;
let cacheKey: string; let cacheKey: string;
let transferKey: string; let transferKey: string;
@ -435,7 +430,7 @@ export class ImageKnife {
this.runningMaps.put(nextPending.uuid, nextPending); this.runningMaps.put(nextPending.uuid, nextPending);
// RequestManager.execute((nextPending as RequestOption), this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch) // RequestManager.execute((nextPending as RequestOption), this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch)
this.taskpoolLoadResource(nextPending, ResourceUsage.MAIN); this.taskpoolLoadResource(nextPending, Constants.MAIN_HOLDER);
} }
@ -466,7 +461,7 @@ export class ImageKnife {
this.runningMaps.put(nextPending.uuid, nextPending) this.runningMaps.put(nextPending.uuid, nextPending)
this.pendingMaps.remove(nextPending.uuid) this.pendingMaps.remove(nextPending.uuid)
//RequestManager.execute((nextPending as RequestOption), this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch) //RequestManager.execute((nextPending as RequestOption), this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch)
this.taskpoolLoadResource(nextPending, ResourceUsage.MAIN); this.taskpoolLoadResource(nextPending, Constants.MAIN_HOLDER);
} }
} }
@ -518,7 +513,7 @@ export class ImageKnife {
} else { } else {
this.runningMaps.put(request.uuid, request) this.runningMaps.put(request.uuid, request)
this.taskpoolLoadResource(request, ResourceUsage.MAIN); this.taskpoolLoadResource(request, Constants.MAIN_HOLDER);
} }
} }
else { else {
@ -527,66 +522,98 @@ export class ImageKnife {
} }
} }
//多线程请求加载资源 //组装任务参数
private taskpoolLoadResource(request: RequestOption, usageType: ResourceUsage) { private assembleTaskParams(request: RequestOption, usageType: string) {
let mainCache = this.memoryCacheProxy.loadMemoryCache(request.generateCacheKey, request.isCacheable); //图片变换方法无法直接传递到子线程,这里先把对象名和构造参数传递到子线程,然后在子线程中实例化变换方法
let placeholderCache = this.memoryCacheProxy.loadMemoryCache(request.placeholderCacheKey, true); let transformations: string [][] = [];
let retryholderCache = this.memoryCacheProxy.loadMemoryCache(request.retryholderCacheKey, true); if (usageType == Constants.MAIN_HOLDER) {
let errorholderCacheKey = this.memoryCacheProxy.loadMemoryCache(request.errorholderCacheKey, true); for (let i = 0; i < request.transformations.length; i++) {
transformations.push([request.transformations[i].getClassName(), request.transformations[i].getConstructorParams()])
}
}
let displayProgress = request.progressFunc ? true : false;
//將要传递到子线程的参数放在一个json对象上避免方法参数过多
let taskParams: TaskParams = {
headers: request.headers,
moduleContext: request.moduleContext,
transformations: transformations,
usageType: usageType,
displayProgress: displayProgress,
uuid: request.uuid,
dontAnimateFlag: request.dontAnimateFlag,
generateCacheKey: request.generateCacheKey,
generateResourceKey: request.generateResourceKey,
generateDataKey: request.generateDataKey,
thumbSizeMultiplier: request.thumbSizeMultiplier,
thumbDelayTime: request.thumbDelayTime,
size: request.size,
onlyRetrieveFromCache: request.onlyRetrieveFromCache,
gpuEnabled: request.gpuEnabled,
signature: request.signature,
isCacheable: request.isCacheable
}
return taskParams;
}
if (usageType == "placeholder" && placeholderCache && !mainCache && !retryholderCache && !errorholderCacheKey) { //多线程请求加载资源
private taskpoolLoadResource(request: RequestOption, usageType: string) {
let mainCache = this.memoryCacheProxy.loadMemoryCache(request.generateCacheKey, request.isCacheable);
let placeholderCache = this.memoryCacheProxy.loadMemoryCache(request.placeholderCacheKey, request.isCacheable);
let retryholderCache = this.memoryCacheProxy.loadMemoryCache(request.retryholderCacheKey, request.isCacheable);
let errorholderCacheKey = this.memoryCacheProxy.loadMemoryCache(request.errorholderCacheKey, request.isCacheable);
if (usageType == Constants.PLACE_HOLDER && placeholderCache && !mainCache && !retryholderCache && !errorholderCacheKey) {
LogUtil.info("imageknife load placeholder from MemoryCache") LogUtil.info("imageknife load placeholder from MemoryCache")
request.placeholderOnComplete(placeholderCache); request.placeholderOnComplete(placeholderCache);
return; return;
} else if (usageType == "retryholder" && retryholderCache && !mainCache && !errorholderCacheKey) { } else if (usageType == Constants.RETRY_HOLDER && retryholderCache && !mainCache && !errorholderCacheKey) {
LogUtil.info("imageknife load retryholder from MemoryCache") LogUtil.info("imageknife load retryholder from MemoryCache")
request.retryholderOnComplete(retryholderCache); request.retryholderOnComplete(retryholderCache);
return; return;
} else if (usageType == "errorholder" && errorholderCacheKey && !mainCache) { } else if (usageType == Constants.ERROR_HOLDER && errorholderCacheKey && !mainCache) {
LogUtil.info("imageknife load errorholder from MemoryCache") LogUtil.info("imageknife load errorholder from MemoryCache")
request.errorholderOnComplete(errorholderCacheKey); request.errorholderOnComplete(errorholderCacheKey);
return; return;
} else if (usageType == "main" && mainCache) { } else if (usageType == Constants.MAIN_HOLDER && mainCache) {
LogUtil.info("imageknife load mainsource from MemoryCache") LogUtil.info("imageknife load mainsource from MemoryCache")
mainCache.waitSaveDisk = false; mainCache.waitSaveDisk = false;
request.loadComplete(mainCache); request.loadComplete(mainCache);
return; return;
} }
//图片变换方法无法直接传递到子线程,这里先把对象名和构造参数传递到子线程,然后在子线程中实例化变换方法 let taskParams: TaskParams = this.assembleTaskParams(request, usageType);
let transformations: string [][] = []; let loadSrcJson = JSON.stringify({
if (usageType == ResourceUsage.MAIN) { loadSrc: request.loadSrc,
for (let i = 0; i < request.transformations.length; i++) { placeholderSrc: request.placeholderSrc,
transformations.push([request.transformations[i].getClassName(), request.transformations[i].getConstructorParams()]) errorholderSrc: request.errorholderSrc,
} retryholderSrc: request.retryholderSrc,
} });
//將要传递到子线程的参数放在一个json对象上避免方法参数过多
let taskParams = JSON.stringify({
transformations: transformations,
request: request,
usageType: usageType
})
//使用taskpool多线程执行资源下载 //使用taskpool多线程执行资源下载
let task = new taskpool.Task(taskExecute, taskParams, request.headers, request.moduleContext as common.UIAbilityContext) let task = new taskpool.Task(taskExecute, taskParams, loadSrcJson)
task.setTransferList([]) task.setTransferList([])
emitter.on(Constants.PROGRESS_EMITTER, (data) => {
if (request.progressFunc && data?.data?.value) {
let percent = data.data.value as number;
request.progressFunc.asyncSuccess(percent);
}
});
taskpool.execute(task).then((data) => { taskpool.execute(task).then((data) => {
if (usageType == "placeholder") { if (usageType == Constants.PLACE_HOLDER) {
if ((typeof (data as PixelMap).isEditable) == 'boolean') { if ((typeof (data as PixelMap).isEditable) == 'boolean') {
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, data as PixelMap); let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, data as PixelMap);
request.placeholderOnComplete(imageKnifeData) request.placeholderOnComplete(imageKnifeData)
} else { } else {
request.placeholderOnError("request placeholder error") request.placeholderOnError("request placeholder error")
} }
} else if (usageType == "retryholder") { } else if (usageType == Constants.RETRY_HOLDER) {
if ((typeof (data as PixelMap).isEditable) == 'boolean') { if ((typeof (data as PixelMap).isEditable) == 'boolean') {
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, data as PixelMap); let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, data as PixelMap);
request.retryholderOnComplete(imageKnifeData) request.retryholderOnComplete(imageKnifeData)
} else { } else {
request.retryholderOnError("request retryholder error") request.retryholderOnError("request retryholder error")
} }
} else if (usageType == "errorholder") { } else if (usageType == Constants.ERROR_HOLDER) {
if ((typeof (data as PixelMap).isEditable) == 'boolean') { if ((typeof (data as PixelMap).isEditable) == 'boolean') {
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, data as PixelMap); let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, data as PixelMap);
request.errorholderOnComplete(imageKnifeData) request.errorholderOnComplete(imageKnifeData)
@ -684,51 +711,65 @@ export class ImageKnife {
* @returns * @returns
*/ */
@Concurrent @Concurrent
async function taskExecute(taskParams: string, headers: Map<string, Object>, moduleContext: common.UIAbilityContext): Promise<PixelMap | GIFFrame[]> { async function taskExecute(taskParams: TaskParams, loadSrcJson: string): Promise<PixelMap | GIFFrame[]> {
// try { let emitProgressPercent = (percentValue: number) => {
let params: object = JSON.parse(taskParams); let eventData: emitter.EventData = {
let option = params["request"] as RequestOption; data: {
let transformations = params["transformations"] as string [][]; "value": percentValue,
let usageType = params["usageType"] as string; }
};
emitter.emit(Constants.PROGRESS_EMITTER, eventData)
}
let transformations = taskParams.transformations;
let usageType = taskParams.usageType;
let displayProgress = taskParams.displayProgress;
//子线程构造RequestOption对象 //子线程构造RequestOption对象
let newRequestOption = new RequestOption(); let newRequestOption = new RequestOption();
newRequestOption.uuid = option.uuid; let loadSrcObj: object = JSON.parse(loadSrcJson);
newRequestOption.loadSrc = option.loadSrc; newRequestOption.uuid = taskParams.uuid;
newRequestOption.dontAnimateFlag = option.dontAnimateFlag; newRequestOption.loadSrc = loadSrcObj["loadSrc"] as string | PixelMap | Resource;
newRequestOption.generateCacheKey = option.generateCacheKey; newRequestOption.dontAnimateFlag = taskParams.dontAnimateFlag;
newRequestOption.generateResourceKey = option.generateResourceKey; newRequestOption.generateCacheKey = taskParams.generateCacheKey;
newRequestOption.generateDataKey = option.generateDataKey; newRequestOption.generateResourceKey = taskParams.generateResourceKey;
newRequestOption.thumbSizeMultiplier = option.thumbSizeMultiplier; newRequestOption.generateDataKey = taskParams.generateDataKey;
newRequestOption.thumbDelayTime = option.thumbDelayTime; newRequestOption.thumbSizeMultiplier = taskParams.thumbSizeMultiplier;
newRequestOption.size = option.size; newRequestOption.thumbDelayTime = taskParams.thumbDelayTime;
newRequestOption.size = taskParams.size;
newRequestOption.placeholderSrc = option.placeholderSrc; newRequestOption.placeholderSrc = loadSrcObj["placeholderSrc"] as PixelMap | Resource | undefined;
newRequestOption.errorholderSrc = option.errorholderSrc; newRequestOption.errorholderSrc = loadSrcObj["errorholderSrc"] as PixelMap | Resource | undefined;
newRequestOption.retryholderSrc = option.retryholderSrc; newRequestOption.retryholderSrc = loadSrcObj["retryholderSrc"] as PixelMap | Resource | undefined;
newRequestOption.onlyRetrieveFromCache = option.onlyRetrieveFromCache; newRequestOption.onlyRetrieveFromCache = taskParams.onlyRetrieveFromCache;
newRequestOption.gpuEnabled = option.gpuEnabled; newRequestOption.gpuEnabled = taskParams.gpuEnabled;
newRequestOption.headers = headers; newRequestOption.headers = taskParams.headers;
newRequestOption.signature = option.signature; newRequestOption.signature = taskParams.signature;
ImageKnifeGlobal.getInstance().setHapContext(moduleContext); ImageKnifeGlobal.getInstance().setHapContext(taskParams.moduleContext as common.UIAbilityContext);
newRequestOption.moduleContext = moduleContext; newRequestOption.moduleContext = taskParams.moduleContext;
if (option.isCacheable != null && option.isCacheable != undefined) { newRequestOption.isCacheable = taskParams.isCacheable;
newRequestOption.isCacheable = option.isCacheable;
if (displayProgress) {
newRequestOption.addProgressListener({
asyncSuccess: (percentValue: number) => {
// 如果进度条百分比 未展示大小,展示其动画
emitProgressPercent(percentValue)
}
})
} }
//如果是本地图片不作磁盘缓存 //如果是本地图片不作磁盘缓存
if (typeof option.loadSrc !== 'string') { if (typeof newRequestOption.loadSrc !== 'string') {
let none = new NONE(); let none = new NONE();
newRequestOption.diskCacheStrategy(none); newRequestOption.diskCacheStrategy(none);
} }
if (usageType == "placeholder") { if (usageType == Constants.PLACE_HOLDER) {
let manager = new PlaceHolderManager<PixelMap>(newRequestOption); let manager = new PlaceHolderManager<PixelMap>(newRequestOption);
return await new Promise<PixelMap>(manager.process); return await new Promise<PixelMap>(manager.process);
} else if (usageType == "retryholder") { } else if (usageType == Constants.RETRY_HOLDER) {
let manager = new RetryHolderManager<PixelMap>(newRequestOption); let manager = new RetryHolderManager<PixelMap>(newRequestOption);
return await new Promise<PixelMap>(manager.process); return await new Promise<PixelMap>(manager.process);
} else if (usageType == "errorholder") { } else if (usageType == Constants.ERROR_HOLDER) {
let manager = new ErrorHolderManager<PixelMap>(newRequestOption); let manager = new ErrorHolderManager<PixelMap>(newRequestOption);
return await new Promise<PixelMap>(manager.process); return await new Promise<PixelMap>(manager.process);
} else { } else {
@ -744,9 +785,5 @@ async function taskExecute(taskParams: string, headers: Map<string, Object>, mod
let manager = new RequestManager(newRequestOption, newDataFetch, newResourceFetch); let manager = new RequestManager(newRequestOption, newDataFetch, newResourceFetch);
return await new Promise<PixelMap | GIFFrame[]>(manager.process); return await new Promise<PixelMap | GIFFrame[]>(manager.process);
} }
// } catch (e) {
// console.log(e)
// return await new Promise<PixelMap | GIFFrame[]>(() => {
// });
// }
} }

View File

@ -545,15 +545,6 @@ export class RequestOption {
} }
} }
} }
//显示进度条
if (this.progressFunc) {
this.progressFunc.asyncSuccess(0);
setTimeout(() => {
}, 1000);
this.progressFunc.asyncSuccess(100);
}
//输出缓存相关内容和信息 //输出缓存相关内容和信息
if (this.allCacheInfoCallback) { if (this.allCacheInfoCallback) {
// 内存缓存 // 内存缓存

View File

@ -0,0 +1,23 @@
import { ObjectKey } from './ObjectKey';
import { Size } from '../imageknife/RequestOption'
import common from '@ohos.app.ability.common'
export class TaskParams {
headers: Map<string, Object> = new Map<string, Object>();
moduleContext?: common.UIAbilityContext = undefined;
transformations: string [][] = []
usageType: string = ''
displayProgress: boolean = false
uuid: string = '' // 唯一标识
dontAnimateFlag: boolean = false;
thumbSizeMultiplier: number = 0;
thumbDelayTime: number = 1000;
size: Size = { width: -1, height: -1 };
onlyRetrieveFromCache: boolean = false;
isCacheable: boolean = true;
gpuEnabled: boolean = false;
generateCacheKey: string = "";
generateResourceKey: string = "";
generateDataKey: string = "";
signature?: ObjectKey;
}

View File

@ -14,5 +14,10 @@
*/ */
export class Constants { export class Constants {
public static PROJECT_TAG: string= "ImageKnife_js" public static PROJECT_TAG: string = "ImageKnife_js"
public static PROGRESS_EMITTER: string = "progressEmitter"
public static PLACE_HOLDER: string = "placeholder"
public static RETRY_HOLDER: string = "retryholder"
public static ERROR_HOLDER: string = "errorholder"
public static MAIN_HOLDER: string = "main"
} }

View File

@ -13,18 +13,12 @@
* limitations under the License. * limitations under the License.
*/ */
import { IDataFetch } from '../networkmanage/IDataFetch' import { IDataFetch } from '../networkmanage/IDataFetch'
import { RequestOption } from '../RequestOption' import { RequestOption } from '../RequestOption'
import { SparkMD5 } from '../../3rd_party/sparkmd5/spark-md5'
import { FileUtils } from '../../cache/FileUtils'
import loadRequest from '@ohos.request';
import { LogUtil } from '../utils/LogUtil'
import { ImageKnifeGlobal } from '../ImageKnifeGlobal'
import common from '@ohos.app.ability.common'
import { BusinessError } from '@ohos.base'
import http from '@ohos.net.http' import http from '@ohos.net.http'
// 数据加载器 // 数据加载器
class RequestData{ class RequestData {
receiveSize: number = 2000 receiveSize: number = 2000
totalSize: number = 2000 totalSize: number = 2000
} }
@ -47,7 +41,7 @@ export class HttpDownloadClient implements IDataFetch {
}) })
httpRequest.on('dataReceiveProgress', (data: RequestData) => { httpRequest.on('dataReceiveProgress', (data: RequestData) => {
// 下载进度 // 下载进度
if(data != undefined && (typeof data.receiveSize == 'number') && (typeof data.totalSize == 'number') ) { if (data != undefined && (typeof data.receiveSize == 'number') && (typeof data.totalSize == 'number')) {
let percent = Math.round(((data.receiveSize * 1.0) / (data.totalSize * 1.0)) * 100) let percent = Math.round(((data.receiveSize * 1.0) / (data.totalSize * 1.0)) * 100)
if (request.progressFunc) { if (request.progressFunc) {
request.progressFunc.asyncSuccess(percent) request.progressFunc.asyncSuccess(percent)
@ -64,7 +58,7 @@ export class HttpDownloadClient implements IDataFetch {
request.headers.forEach((value, key) => { request.headers.forEach((value, key) => {
headerObj[key] = value headerObj[key] = value
}) })
let promise = httpRequest.requestInStream(request.loadSrc as string, { let promise = httpRequest.requestInStream(request.loadSrc as string, {
header: headerObj, header: headerObj,
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
expectDataType: http.HttpDataType.ARRAY_BUFFER, expectDataType: http.HttpDataType.ARRAY_BUFFER,
@ -73,17 +67,17 @@ export class HttpDownloadClient implements IDataFetch {
usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定 usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定
usingCache: false usingCache: false
}); });
await promise.then((data)=>{ await promise.then((data) => {
if(data == 200) { if (data == 200) {
} else { } else {
onError(`HttpDownloadClient has error, http code = ${data}`) onError(`HttpDownloadClient has error, http code = ${data}`)
} }
}).catch((err:Error)=>{ }).catch((err: Error) => {
onError(`HttpDownloadClient has error, http code = ${err}`) onError(`HttpDownloadClient has error, http code = ${err}`)
}) })
} catch (err) { } catch (err) {
onError('HttpDownloadClient catch err request uuid ='+request.uuid) onError('HttpDownloadClient catch err request uuid =' + request.uuid)
} }
} }

View File

@ -6,6 +6,6 @@
"name": "imageknife", "name": "imageknife",
"description": "example description", "description": "example description",
"repository": {}, "repository": {},
"version": "2.1.2-rc.10", "version": "2.1.2-rc.11",
"dependencies": {} "dependencies": {}
} }