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
*/
async getOriginRecentMissionsList(): Promise<Array<missionManager.MissionInfo>> {
let missionInfos = new Array<missionManager.MissionInfo>();
await missionManager.getMissionInfos('', AmsMissionManager.RECENT_MISSIONS_LIMIT_NUM)
.then((res) => {
if (!CheckEmptyUtils.isEmptyArr(res)) {
Log.showDebug(TAG, `getOriginRecentMissionsList res.length: ${res.length}`);
missionInfos = res;
}
})
.catch((err) => {
Log.showError(TAG, `getOriginRecentMissionsList error: ${JSON.stringify(err)}`);
});
return missionInfos;
try {
let arrayMissionInfo = new Array<missionManager.MissionInfo>();
let res = await missionManager.getMissionInfos('', AmsMissionManager.RECENT_MISSIONS_LIMIT_NUM);
if (!CheckEmptyUtils.isEmptyArr(res)) {
Log.showDebug(TAG, `getOriginRecentMissionsList res.length: ${res.length}`);
arrayMissionInfo = res;
return arrayMissionInfo;
}
} catch (err) {
Log.showError(TAG, `getOriginRecentMissionsList error: ${JSON.stringify(err)}`);
}
}
/**
@ -149,13 +148,12 @@ class AmsMissionManager {
*/
async clearMission(missionId: number): Promise<void> {
Log.showInfo(TAG, `clearMission Id:${missionId}`);
await missionManager.clearMission(missionId)
.then((data) => {
Log.showDebug(TAG, `clearMission data:${JSON.stringify(data)}`);
})
.catch((err) => {
Log.showError(TAG, `clearMission err:${JSON.stringify(err)}`);
});
try {
await missionManager.clearMission(missionId);
Log.showDebug(TAG, 'clearMission success');
} catch (err) {
Log.showError(TAG, `clearMission err:${JSON.stringify(err)}`);
}
}
/**
@ -165,13 +163,12 @@ class AmsMissionManager {
* @return nothing.
*/
async clearAllMissions(): Promise<void> {
await missionManager.clearAllMissions()
.then((data) => {
Log.showDebug(TAG, `clearAllMissions data: ${JSON.stringify(data)}`);
})
.catch((err) => {
Log.showError(TAG, `clearAllMissions err: ${JSON.stringify(err)}`);
});
try {
await missionManager.clearAllMissions();
Log.showDebug(TAG, 'clearAllMissions success');
} catch (err) {
Log.showError(TAG, `clearAllMissions err: ${JSON.stringify(err)}`);
}
}
/**
@ -227,22 +224,15 @@ class AmsMissionManager {
Log.showInfo(TAG, `getMissionSnapShot start! missionId: ${missionId}`);
try {
let missionSnapshot: missionManager.MissionSnapshot = null;
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)}`);
});
missionSnapshot = await missionManager.getMissionSnapShot('', missionId);
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.snapShotImage = missionSnapshot.snapshot;
snapShotInfo.snapShotImageWidth = imageInfo.size.width;
snapShotInfo.snapShotImageHeight = imageInfo.size.height;
} catch (err) {
Log.showError(TAG, `missionManager.getMissionSnapShot err: ${err}`);
Log.showError(TAG, `missionManager.getMissionSnapShot err: ${JSON.stringify(err)}`);
}
return snapShotInfo;
}
@ -254,13 +244,13 @@ class AmsMissionManager {
*/
async moveMissionToFront(missionId: number, winMode?: number) {
Log.showInfo(TAG, `moveMissionToFront missionId: ${missionId}`);
let promise = winMode ? missionManager.moveMissionToFront(missionId, { windowMode: winMode }) :
missionManager.moveMissionToFront(missionId);
const res = await promise.catch(err => {
try {
winMode ? await missionManager.moveMissionToFront(missionId, { windowMode: winMode }) :
await missionManager.moveMissionToFront(missionId);
Log.showDebug(TAG, 'moveMissionToFront missionId end success');
} catch (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']
};
try {
await bundleManager.queryAbilityInfo(want, bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION, this.mUserId)
.then((res: Array<bundleManager.AbilityInfo>) => {
Log.showInfo(TAG, `getAllAbilityList res length: ${res.length}`);
abilityList = res;
})
.catch((err) => {
Log.showError(TAG, `getAllAbilityList error: ${JSON.stringify(err)}`);
});
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION;
abilityList = await bundleManager.queryAbilityInfo(want, abilityFlags, this.mUserId);
Log.showInfo(TAG, `getAllAbilityList success, abilityList length: ${abilityList.length}`);
} catch (err) {
Log.showError(TAG, `getAllAbilityList bundleManager.queryAbilityInfo error: ${JSON.stringify(err)}`);
}
@ -107,18 +102,12 @@ class CommonBundleManager {
}
let bundleInfo: bundleManager.BundleInfo = undefined;
try {
await bundleManager.getBundleInfo(bundleName,
bundleInfo = await bundleManager.getBundleInfo(bundleName,
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE |
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY,
this.mUserId)
.then((res: bundleManager.BundleInfo) => {
Log.showInfo(TAG, `getBundleInfoByBundleName res:${JSON.stringify(res.hapModulesInfo.length)}`);
bundleInfo = res;
})
.catch((err) => {
Log.showError(TAG, `getBundleInfoByBundleName error: ${JSON.stringify(err)}, bundleName:${bundleName}`);
});
this.mUserId);
Log.showInfo(TAG, `getBundleInfoByBundleName success, bundleInfo length:${bundleInfo?.hapModulesInfo.length}`);
} catch (err) {
Log.showError(TAG, `getBundleInfoByBundleName bundleManager.getBundleInfo error: ${JSON.stringify(err)}, bundleName:${bundleName}`);
}
@ -152,16 +141,13 @@ class CommonBundleManager {
abilityName: abilityName
};
try {
await bundleManager.queryAbilityInfo(want, bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION, this.mUserId)
.then((res: Array<bundleManager.AbilityInfo>)=>{
if (res !== undefined) {
Log.showInfo(TAG, `getAbilityInfoByAbilityName res length: ${res.length}`);
abilityList = res;
}
})
.catch((err)=>{
Log.showError(TAG, `getAbilityInfoByAbilityName error: ${JSON.stringify(err)}`);
});
let res: Array<bundleManager.AbilityInfo>;
let abilityFlags: bundleManager.AbilityFlag = bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION;
res = await bundleManager.queryAbilityInfo(want, abilityFlags, this.mUserId);
if (res !== undefined) {
Log.showInfo(TAG, `getAbilityInfoByAbilityName success, res length: ${res.length}`);
abilityList = res;
}
} catch (err) {
Log.showError(TAG, `getAbilityInfoByAbilityName bundleManager.queryAbilityInfo error: ${JSON.stringify(err)}`);
}

View File

@ -48,7 +48,7 @@ export class DisplayManager {
}
private async loadAllDisplays() {
let displays: Array<display.Display> = await display.getAllDisplays()
let displays: Array<display.Display> = await display.getAllDisplays();
for (let display of displays) {
if (this.displayDevices.findIndex(item => item.id === display.id) < 0) {
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> {
const context = featureAbility.getContext();
await context.getFilesDir()
.then((data) => {
Log.showDebug(TAG, `getFilesDir File directory obtained. Data: ${JSON.stringify(data)}`);
this.baseDir = data + '/';
}).catch((error) => {
Log.showError(TAG, `getFilesDir Failed to obtain the file directory. Cause: ${JSON.stringify(error)}`);
});
try {
let data: string = await context.getFilesDir();
Log.showDebug(TAG, `getFilesDir File directory obtained. Data: ${JSON.stringify(data)}`);
this.baseDir = data + '/';
} catch (err) {
Log.showError(TAG, `getFilesDir Failed to obtain the file directory. Cause: ${JSON.stringify(err)}`);
}
}
async getFileContent(fpath: string): Promise<string> {

View File

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

View File

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

View File

@ -295,7 +295,7 @@ export default class SmartDockModel {
*/
addToPageDesk(appInfo: DockItemInfo): void {
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 {
Prompt.showToast({
message: $r('app.string.disable_add_to_dock')