async/await整改

Signed-off-by: zhengyongjie <15531316327@163.com>
This commit is contained in:
zhengyongjie 2024-07-15 14:36:21 +08:00
parent 43a21977cc
commit 0519cc7710
7 changed files with 84 additions and 114 deletions

View File

@ -50,18 +50,17 @@ class AmsMissionManager {
* @return {Array} missions * @return {Array} missions
*/ */
async getOriginRecentMissionsList(): Promise<Array<missionManager.MissionInfo>> { async getOriginRecentMissionsList(): Promise<Array<missionManager.MissionInfo>> {
let missionInfos = new Array<missionManager.MissionInfo>(); try {
await missionManager.getMissionInfos('', AmsMissionManager.RECENT_MISSIONS_LIMIT_NUM) let arrayMissionInfo = new Array<missionManager.MissionInfo>();
.then((res) => { let res = await missionManager.getMissionInfos('', AmsMissionManager.RECENT_MISSIONS_LIMIT_NUM);
if (!CheckEmptyUtils.isEmptyArr(res)) { if (!CheckEmptyUtils.isEmptyArr(res)) {
Log.showDebug(TAG, `getOriginRecentMissionsList res.length: ${res.length}`); Log.showDebug(TAG, `getOriginRecentMissionsList res.length: ${res.length}`);
missionInfos = res; arrayMissionInfo = res;
} return arrayMissionInfo;
}) }
.catch((err) => { } catch (err) {
Log.showError(TAG, `getOriginRecentMissionsList error: ${JSON.stringify(err)}`); Log.showError(TAG, `getOriginRecentMissionsList error: ${JSON.stringify(err)}`);
}); }
return missionInfos;
} }
/** /**
@ -149,13 +148,12 @@ class AmsMissionManager {
*/ */
async clearMission(missionId: number): Promise<void> { async clearMission(missionId: number): Promise<void> {
Log.showInfo(TAG, `clearMission Id:${missionId}`); Log.showInfo(TAG, `clearMission Id:${missionId}`);
await missionManager.clearMission(missionId) try {
.then((data) => { await missionManager.clearMission(missionId);
Log.showDebug(TAG, `clearMission data:${JSON.stringify(data)}`); Log.showDebug(TAG, 'clearMission success');
}) } catch (err) {
.catch((err) => { Log.showError(TAG, `clearMission err:${JSON.stringify(err)}`);
Log.showError(TAG, `clearMission err:${JSON.stringify(err)}`); }
});
} }
/** /**
@ -165,13 +163,12 @@ class AmsMissionManager {
* @return nothing. * @return nothing.
*/ */
async clearAllMissions(): Promise<void> { async clearAllMissions(): Promise<void> {
await missionManager.clearAllMissions() try {
.then((data) => { await missionManager.clearAllMissions();
Log.showDebug(TAG, `clearAllMissions data: ${JSON.stringify(data)}`); Log.showDebug(TAG, 'clearAllMissions success');
}) } catch (err) {
.catch((err) => { Log.showError(TAG, `clearAllMissions err: ${JSON.stringify(err)}`);
Log.showError(TAG, `clearAllMissions err: ${JSON.stringify(err)}`); }
});
} }
/** /**
@ -227,22 +224,15 @@ class AmsMissionManager {
Log.showInfo(TAG, `getMissionSnapShot start! missionId: ${missionId}`); Log.showInfo(TAG, `getMissionSnapShot start! missionId: ${missionId}`);
try { try {
let missionSnapshot: missionManager.MissionSnapshot = null; let missionSnapshot: missionManager.MissionSnapshot = null;
await missionManager.getMissionSnapShot('', missionId) missionSnapshot = await missionManager.getMissionSnapShot('', missionId);
.then((res) => {
Log.showDebug(TAG, `getMissionSnapShot ${missionId} success ${JSON.stringify(res)}`);
missionSnapshot = res;
})
.catch((err) => {
Log.showError(TAG, `getMissionSnapShot error: ${JSON.stringify(err)}`);
});
const imageInfo = await missionSnapshot.snapshot.getImageInfo(); const imageInfo = await missionSnapshot.snapshot.getImageInfo();
Log.showDebug(TAG, `getMissionSnapShot success ${JSON.stringify(imageInfo)}`); Log.showDebug(TAG, `getMissionSnapShot ${missionId} success ${JSON.stringify(imageInfo)}`);
snapShotInfo.missionId = missionId; snapShotInfo.missionId = missionId;
snapShotInfo.snapShotImage = missionSnapshot.snapshot; snapShotInfo.snapShotImage = missionSnapshot.snapshot;
snapShotInfo.snapShotImageWidth = imageInfo.size.width; snapShotInfo.snapShotImageWidth = imageInfo.size.width;
snapShotInfo.snapShotImageHeight = imageInfo.size.height; snapShotInfo.snapShotImageHeight = imageInfo.size.height;
} catch (err) { } catch (err) {
Log.showError(TAG, `missionManager.getMissionSnapShot err: ${err}`); Log.showError(TAG, `missionManager.getMissionSnapShot err: ${JSON.stringify(err)}`);
} }
return snapShotInfo; return snapShotInfo;
} }
@ -254,13 +244,13 @@ class AmsMissionManager {
*/ */
async moveMissionToFront(missionId: number, winMode?: number) { async moveMissionToFront(missionId: number, winMode?: number) {
Log.showInfo(TAG, `moveMissionToFront missionId: ${missionId}`); Log.showInfo(TAG, `moveMissionToFront missionId: ${missionId}`);
let promise = winMode ? missionManager.moveMissionToFront(missionId, { windowMode: winMode }) : try {
missionManager.moveMissionToFront(missionId); winMode ? await missionManager.moveMissionToFront(missionId, { windowMode: winMode }) :
const res = await promise.catch(err => { await missionManager.moveMissionToFront(missionId);
Log.showDebug(TAG, 'moveMissionToFront missionId end success');
} catch (err) {
Log.showError(TAG, `moveMissionToFront err: ${JSON.stringify(err)}`); Log.showError(TAG, `moveMissionToFront err: ${JSON.stringify(err)}`);
}); }
Log.showDebug(TAG, `moveMissionToFront missionId end: ${JSON.stringify(res)}`);
return res;
} }
} }

View File

@ -72,14 +72,9 @@ class CommonBundleManager {
entities : ['entity.system.home'] entities : ['entity.system.home']
}; };
try { try {
await bundleManager.queryAbilityInfo(want, bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION, this.mUserId) let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION;
.then((res: Array<bundleManager.AbilityInfo>) => { abilityList = await bundleManager.queryAbilityInfo(want, abilityFlags, this.mUserId);
Log.showInfo(TAG, `getAllAbilityList res length: ${res.length}`); Log.showInfo(TAG, `getAllAbilityList success, abilityList length: ${abilityList.length}`);
abilityList = res;
})
.catch((err) => {
Log.showError(TAG, `getAllAbilityList error: ${JSON.stringify(err)}`);
});
} catch (err) { } catch (err) {
Log.showError(TAG, `getAllAbilityList bundleManager.queryAbilityInfo error: ${JSON.stringify(err)}`); Log.showError(TAG, `getAllAbilityList bundleManager.queryAbilityInfo error: ${JSON.stringify(err)}`);
} }
@ -107,18 +102,12 @@ class CommonBundleManager {
} }
let bundleInfo: bundleManager.BundleInfo = undefined; let bundleInfo: bundleManager.BundleInfo = undefined;
try { try {
await bundleManager.getBundleInfo(bundleName, bundleInfo = await bundleManager.getBundleInfo(bundleName,
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE |
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY,
this.mUserId) this.mUserId);
.then((res: bundleManager.BundleInfo) => { Log.showInfo(TAG, `getBundleInfoByBundleName success, bundleInfo length:${bundleInfo?.hapModulesInfo.length}`);
Log.showInfo(TAG, `getBundleInfoByBundleName res:${JSON.stringify(res.hapModulesInfo.length)}`);
bundleInfo = res;
})
.catch((err) => {
Log.showError(TAG, `getBundleInfoByBundleName error: ${JSON.stringify(err)}, bundleName:${bundleName}`);
});
} catch (err) { } catch (err) {
Log.showError(TAG, `getBundleInfoByBundleName bundleManager.getBundleInfo error: ${JSON.stringify(err)}, bundleName:${bundleName}`); Log.showError(TAG, `getBundleInfoByBundleName bundleManager.getBundleInfo error: ${JSON.stringify(err)}, bundleName:${bundleName}`);
} }
@ -152,16 +141,13 @@ class CommonBundleManager {
abilityName: abilityName abilityName: abilityName
}; };
try { try {
await bundleManager.queryAbilityInfo(want, bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION, this.mUserId) let res: Array<bundleManager.AbilityInfo>;
.then((res: Array<bundleManager.AbilityInfo>)=>{ let abilityFlags: bundleManager.AbilityFlag = bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION;
if (res !== undefined) { res = await bundleManager.queryAbilityInfo(want, abilityFlags, this.mUserId);
Log.showInfo(TAG, `getAbilityInfoByAbilityName res length: ${res.length}`); if (res !== undefined) {
abilityList = res; Log.showInfo(TAG, `getAbilityInfoByAbilityName success, res length: ${res.length}`);
} abilityList = res;
}) }
.catch((err)=>{
Log.showError(TAG, `getAbilityInfoByAbilityName error: ${JSON.stringify(err)}`);
});
} catch (err) { } catch (err) {
Log.showError(TAG, `getAbilityInfoByAbilityName bundleManager.queryAbilityInfo error: ${JSON.stringify(err)}`); Log.showError(TAG, `getAbilityInfoByAbilityName bundleManager.queryAbilityInfo error: ${JSON.stringify(err)}`);
} }

View File

@ -48,7 +48,7 @@ export class DisplayManager {
} }
private async loadAllDisplays() { private async loadAllDisplays() {
let displays: Array<display.Display> = await display.getAllDisplays() let displays: Array<display.Display> = await display.getAllDisplays();
for (let display of displays) { for (let display of displays) {
if (this.displayDevices.findIndex(item => item.id === display.id) < 0) { if (this.displayDevices.findIndex(item => item.id === display.id) < 0) {
Log.showInfo(TAG, 'new display added. detail: ' + JSON.stringify(display)); Log.showInfo(TAG, 'new display added. detail: ' + JSON.stringify(display));

View File

@ -35,13 +35,13 @@ export default class FileManager {
private async getBaseDir(): Promise<void> { private async getBaseDir(): Promise<void> {
const context = featureAbility.getContext(); const context = featureAbility.getContext();
await context.getFilesDir() try {
.then((data) => { let data: string = await context.getFilesDir();
Log.showDebug(TAG, `getFilesDir File directory obtained. Data: ${JSON.stringify(data)}`); Log.showDebug(TAG, `getFilesDir File directory obtained. Data: ${JSON.stringify(data)}`);
this.baseDir = data + '/'; this.baseDir = data + '/';
}).catch((error) => { } catch (err) {
Log.showError(TAG, `getFilesDir Failed to obtain the file directory. Cause: ${JSON.stringify(error)}`); Log.showError(TAG, `getFilesDir Failed to obtain the file directory. Cause: ${JSON.stringify(err)}`);
}); }
} }
async getFileContent(fpath: string): Promise<string> { async getFileContent(fpath: string): Promise<string> {

View File

@ -178,13 +178,11 @@ class LauncherAbilityManager {
*/ */
async getLauncherAbilityList(): Promise<AppItemInfo[]> { async getLauncherAbilityList(): Promise<AppItemInfo[]> {
let abilityList = null; let abilityList = null;
await launcherBundleManager.getAllLauncherAbilityInfo(LauncherAbilityManager.CURRENT_USER_ID) try {
.then((res) => { abilityList = await launcherBundleManager.getAllLauncherAbilityInfo(LauncherAbilityManager.CURRENT_USER_ID);
abilityList = res; } catch (err) {
}) Log.showError(TAG, `getLauncherAbilityList error: ${JSON.stringify(err)}`);
.catch((err) => { }
Log.showError(TAG, `getLauncherAbilityList error: ${JSON.stringify(err)}`);
});
const appItemInfoList = new Array<AppItemInfo>(); const appItemInfoList = new Array<AppItemInfo>();
if (CheckEmptyUtils.isEmpty(abilityList)) { if (CheckEmptyUtils.isEmpty(abilityList)) {
Log.showDebug(TAG, 'getLauncherAbilityList Empty'); Log.showDebug(TAG, 'getLauncherAbilityList Empty');
@ -205,13 +203,11 @@ class LauncherAbilityManager {
*/ */
async getLauncherAbilityInfo(bundleName: string): Promise<AppItemInfo[]> { async getLauncherAbilityInfo(bundleName: string): Promise<AppItemInfo[]> {
let abilityInfos: launcherBundleManager.LauncherAbilityInfo[]; let abilityInfos: launcherBundleManager.LauncherAbilityInfo[];
await launcherBundleManager.getLauncherAbilityInfo(bundleName, this.mUserId) try {
.then((res) => { abilityInfos = await launcherBundleManager.getLauncherAbilityInfo(bundleName, this.mUserId);
abilityInfos = res; } catch (err) {
}) Log.showError(TAG, `getLauncherAbilityInfo error: ${JSON.stringify(err)}`);
.catch((err) => { }
Log.showError(TAG, `getLauncherAbilityInfo error: ${JSON.stringify(err)}`);
});
const appItemInfoList = new Array<AppItemInfo>(); const appItemInfoList = new Array<AppItemInfo>();
if (CheckEmptyUtils.isEmpty(abilityInfos) || abilityInfos.length === 0) { if (CheckEmptyUtils.isEmpty(abilityInfos) || abilityInfos.length === 0) {
Log.showDebug(TAG, 'getLauncherAbilityInfo Empty'); Log.showDebug(TAG, 'getLauncherAbilityInfo Empty');
@ -240,15 +236,15 @@ class LauncherAbilityManager {
} }
// get from system // get from system
let abilityInfos = new Array<launcherBundleManager.LauncherAbilityInfo>(); let abilityInfos = new Array<launcherBundleManager.LauncherAbilityInfo>();
await launcherBundleManager.getLauncherAbilityInfo(bundleName, LauncherAbilityManager.CURRENT_USER_ID) try {
.then((res)=>{ let res: launcherBundleManager.LauncherAbilityInfo[];
if (res && res.length) { res = await launcherBundleManager.getLauncherAbilityInfo(bundleName, LauncherAbilityManager.CURRENT_USER_ID);
abilityInfos = res; if (res && res.length) {
} abilityInfos = res;
}) }
.catch((err)=>{ } catch (err) {
Log.showError(TAG, `getAppInfoByBundleName getLauncherAbilityInfo error: ${JSON.stringify(err)}`); Log.showError(TAG, `getAppInfoByBundleName getLauncherAbilityInfo error: ${JSON.stringify(err)}`);
}); }
if (!abilityInfos || abilityInfos.length === 0) { if (!abilityInfos || abilityInfos.length === 0) {
Log.showDebug(TAG, `${bundleName} has no launcher ability`); Log.showDebug(TAG, `${bundleName} has no launcher ability`);
return undefined; return undefined;

View File

@ -83,19 +83,17 @@ export class FormModel {
*/ */
async getFormsInfoByBundleName(bundleName: string, callback?) { async getFormsInfoByBundleName(bundleName: string, callback?) {
Log.showDebug(TAG, `getFormsInfoByBundleName bundleName: ${bundleName}`); Log.showDebug(TAG, `getFormsInfoByBundleName bundleName: ${bundleName}`);
let currentBundleFormsInfo: any; let currentBundleFormsInfo: CardItemInfo[];
await this.mFormManager.getFormsInfoByApp(bundleName) try {
.then(bundleFormsInfo => { currentBundleFormsInfo = await this.mFormManager.getFormsInfoByApp(bundleName);
currentBundleFormsInfo = bundleFormsInfo; if (callback != undefined) {
if (callback != undefined) { callback(bundleName, currentBundleFormsInfo);
callback(bundleName, bundleFormsInfo); }
} AppStorage.setOrCreate('formMgrItem', currentBundleFormsInfo);
}) return currentBundleFormsInfo;
.catch(err => { } catch (err) {
Log.showError(TAG, `getFormsInfoByBundleName err: ${JSON.stringify(err)}`); Log.showError(TAG, `getFormsInfoByBundleName bundleName:${bundleName} err: ${JSON.stringify(err)}`);
}); }
AppStorage.setOrCreate('formMgrItem', currentBundleFormsInfo);
return currentBundleFormsInfo;
} }
/** /**

View File

@ -295,7 +295,7 @@ export default class SmartDockModel {
*/ */
addToPageDesk(appInfo: DockItemInfo): void { addToPageDesk(appInfo: DockItemInfo): void {
if (appInfo.itemType == CommonConstants.TYPE_APP) { if (appInfo.itemType == CommonConstants.TYPE_APP) {
localEventManager.sendLocalEventSticky(EventConstants.EVENT_REQUEST_PAGEDESK_ITEM_ADD, appInfo).then(()=>{}, ()=>{}); localEventManager.sendLocalEventSticky(EventConstants.EVENT_REQUEST_PAGEDESK_ITEM_ADD, appInfo);
} else { } else {
Prompt.showToast({ Prompt.showToast({
message: $r('app.string.disable_add_to_dock') message: $r('app.string.disable_add_to_dock')