diff --git a/application/AppScope/app.json b/application/AppScope/app.json index d4da570775a2a010ac3eb152ed31526a40f8b6b1..0865a2a6ee6720c2eef74836c9f84aa4cedde888 100644 --- a/application/AppScope/app.json +++ b/application/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 10000031, - "versionName": "1.0.31", + "versionCode": 10000033, + "versionName": "1.0.33", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 12, diff --git a/application/AppScope/app.json5 b/application/AppScope/app.json5 index 0d683326abe5b455095be3a78515d6eb90fe7508..a186be395dd7e5947d46f14c713ed4c93fe18495 100644 --- a/application/AppScope/app.json5 +++ b/application/AppScope/app.json5 @@ -16,8 +16,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 10000031, - "versionName": "1.0.31", + "versionCode": 10000033, + "versionName": "1.0.33", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 12, diff --git a/application/entry/src/main/ets/pages/ContinueSwitch.ets b/application/entry/src/main/ets/pages/ContinueSwitch.ets index c56637109b0fbbe48fe607a3195362815fbe6fe5..9aea8b80fb20e1f505aa696374ecb012057fd032 100644 --- a/application/entry/src/main/ets/pages/ContinueSwitch.ets +++ b/application/entry/src/main/ets/pages/ContinueSwitch.ets @@ -203,6 +203,27 @@ struct ContinueSwitch { } } + initSwitchStatus(): void { + logger.info(`${TAG} initSwitchStatus in`); + try { + let value = settings.getValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, switchState.open, + settings.domainName.USER_SECURITY); + this.isSwitchOn = value != switchState.close ? true : false; + logger.info(`${TAG} this.isSwitchOn : ${this.isSwitchOn}; value: ${value}`); + + AppStorage.setOrCreate('isSwitchOn', this.isSwitchOn); + logger.info(`${TAG} AppStorage.get(isSwitchOn) : ${AppStorage.get('isSwitchOn')}`); + + if (this.isSwitchOn) { + let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, switchState.open, + settings.domainName.USER_SECURITY); + logger.info(`${TAG} set value success :${status}; set:Continue_Switch_Status is 1`); + } + } catch (error) { + logger.error(`${TAG} settings set or get failed. error.message: ${error.message}`); + } + } + onPageShow() { logger.info(`${TAG} onPageShow in`); this.getGapLength(); @@ -217,21 +238,7 @@ struct ContinueSwitch { aboutToAppear() { logger.info(`${TAG} aboutToAppear in`); - // Switch State Initialization - let value = settings.getValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, switchState.open, - settings.domainName.USER_SECURITY); - this.isSwitchOn = value != switchState.close ? true : false; - logger.info(`${TAG} this.isSwitchOn : ${this.isSwitchOn}; value: ${value}`); - - AppStorage.setOrCreate('isSwitchOn', this.isSwitchOn); - logger.info(`${TAG} AppStorage.get(isSwitchOn) : ${AppStorage.get('isSwitchOn')}`); - - if (this.isSwitchOn) { - let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, switchState.open, - settings.domainName.USER_SECURITY); - logger.info(`${TAG} set value success :${status}; set:Continue_Switch_Status is 1`); - } - + this.initSwitchStatus(); this.getStringSync(); this.getImageArray(); this.getForegroundOsAccountLocalId(); @@ -374,14 +381,18 @@ struct ContinueSwitch { logger.info(`${TAG} isOn: ${isOn}`); this.isSwitchOn = isOn; AppStorage.setAndLink('isSwitchOn', isOn); - if (isOn) { - let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, - switchState.open, settings.domainName.USER_SECURITY); - logger.info(`${TAG} is set success :${status}; set:Continue_Switch_Status is open`); - } else { - let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, - switchState.close, settings.domainName.USER_SECURITY); - logger.info(`${TAG} is set success :${status}; set:Continue_Switch_Status is close`); + try { + if (isOn) { + let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, + switchState.open, settings.domainName.USER_SECURITY); + logger.info(`${TAG} is set success :${status}; set:Continue_Switch_Status is open`); + } else { + let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, + switchState.close, settings.domainName.USER_SECURITY); + logger.info(`${TAG} is set success :${status}; set:Continue_Switch_Status is close`); + } + } catch (error) { + logger.error(`${TAG} settings.setValueSync failed. error.message: ${error.message}`); } }) } @@ -547,8 +558,8 @@ struct ContinueSwitch { private checkFoldBackButton(): void { logger.info(`${TAG} checkFoldBackButton in`); - if (display.isFoldable()) { - try { + try { + if (display.isFoldable()) { display.on('foldStatusChange', (foldStatus: display.FoldStatus) => { let foldStatusValue = foldStatus.valueOf(); logger.info(`${TAG} checkFoldBackButton: foldStatusValue is ${foldStatusValue}`); @@ -556,9 +567,9 @@ struct ContinueSwitch { }) let data: display.FoldStatus = display.getFoldStatus(); this.refreshFoldStatus(data); - } catch (err) { - logger.error(`${TAG} Register failed. exception: ${err.message}`); } + } catch (err) { + logger.error(`${TAG} display.isFoldable,on failed. exception: ${err.message}`); } }