diff --git a/common/src/main/ets/default/manager/AmsMissionManager.ts b/common/src/main/ets/default/manager/AmsMissionManager.ts index 5a7120d9..0bf85e0d 100644 --- a/common/src/main/ets/default/manager/AmsMissionManager.ts +++ b/common/src/main/ets/default/manager/AmsMissionManager.ts @@ -50,18 +50,17 @@ class AmsMissionManager { * @return {Array} missions */ async getOriginRecentMissionsList(): Promise> { - let missionInfos = new Array(); - 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(); + 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 { 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 { - 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; + } } } diff --git a/common/src/main/ets/default/manager/CommonBundleManager.ts b/common/src/main/ets/default/manager/CommonBundleManager.ts index f40d7946..d1fb87cc 100644 --- a/common/src/main/ets/default/manager/CommonBundleManager.ts +++ b/common/src/main/ets/default/manager/CommonBundleManager.ts @@ -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) => { - 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)=>{ - 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; + 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)}`); } diff --git a/common/src/main/ets/default/manager/DisplayManager.ts b/common/src/main/ets/default/manager/DisplayManager.ts index 6e4dcc84..ded751d0 100644 --- a/common/src/main/ets/default/manager/DisplayManager.ts +++ b/common/src/main/ets/default/manager/DisplayManager.ts @@ -48,7 +48,7 @@ export class DisplayManager { } private async loadAllDisplays() { - let displays: Array = await display.getAllDisplays() + let displays: Array = 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)); diff --git a/common/src/main/ets/default/manager/FileManager.ts b/common/src/main/ets/default/manager/FileManager.ts index 707a1864..facb892a 100644 --- a/common/src/main/ets/default/manager/FileManager.ts +++ b/common/src/main/ets/default/manager/FileManager.ts @@ -35,13 +35,13 @@ export default class FileManager { private async getBaseDir(): Promise { 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 { diff --git a/common/src/main/ets/default/manager/LauncherAbilityManager.ts b/common/src/main/ets/default/manager/LauncherAbilityManager.ts index 2b7c06ad..d99d28f3 100644 --- a/common/src/main/ets/default/manager/LauncherAbilityManager.ts +++ b/common/src/main/ets/default/manager/LauncherAbilityManager.ts @@ -178,13 +178,11 @@ class LauncherAbilityManager { */ async getLauncherAbilityList(): Promise { 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(); if (CheckEmptyUtils.isEmpty(abilityList)) { Log.showDebug(TAG, 'getLauncherAbilityList Empty'); @@ -205,13 +203,11 @@ class LauncherAbilityManager { */ async getLauncherAbilityInfo(bundleName: string): Promise { 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(); 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(); - 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; diff --git a/common/src/main/ets/default/model/FormModel.ts b/common/src/main/ets/default/model/FormModel.ts index 77b0ea9e..7bb1bf6b 100644 --- a/common/src/main/ets/default/model/FormModel.ts +++ b/common/src/main/ets/default/model/FormModel.ts @@ -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)}`); + } } /** diff --git a/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts b/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts index fa9f012b..f9828a58 100644 --- a/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts +++ b/feature/smartdock/src/main/ets/default/model/SmartDockModel.ts @@ -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')