diff --git a/.gitignore b/.gitignore index d6377cd5fdfc1d1fcb812650c4e43f12360e6e0c..14d103fc6a684c45e5084a5c9f29bb5e9c02cf05 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ /local.properties /.idea **/build -/signature \ No newline at end of file +/signature +/build-profile.json5 +/package.json +/package-lock.json diff --git a/common/src/main/ets/default/featurecommon/cameraswitcher/CameraSwitchButton.ets b/common/src/main/ets/default/featurecommon/cameraswitcher/CameraSwitchButton.ets index adb21bd16fdbbc04e38ce491ce6748a1c96ce863..1406e2d16c1e752479d62c0f312c888f1ede7d02 100644 --- a/common/src/main/ets/default/featurecommon/cameraswitcher/CameraSwitchButton.ets +++ b/common/src/main/ets/default/featurecommon/cameraswitcher/CameraSwitchButton.ets @@ -42,12 +42,14 @@ let localDispatcher = (dispatch) => { } } +let storageCameraId = AppStorage.Link('storageCameraId') + @Component export struct CameraSwitchButton { private TAG: string = '[CameraSwitchButton]:' @State state: any = {} @State deviceType: string = deviceInfo.deviceType - + @StorageLink('storageCameraId') storageCameraId: string = '' icon: Resource = $r('app.media.small_switch_camera') width: number height: number @@ -107,9 +109,11 @@ export struct CameraSwitchButton { } else { this.state.updateXComponentChangeFlag(!this.state.xComponentChangeFlag) if (this.state.cameraPosition !== 'BACK') { - this.state.changeCameraPosition('BACK') + this.state.changeCameraPosition('BACK') + this.storageCameraId = 'BACK' } else { this.state.changeCameraPosition('FRONT') + this.storageCameraId = 'FRONT' } } } diff --git a/common/src/main/ets/default/function/CameraBasicFunction.ts b/common/src/main/ets/default/function/CameraBasicFunction.ts index de4bd13ca479fe9fd4765a4c2b7e43c3131819bc..c2324204d4d2422485cdad53f1f0d14e1809134b 100644 --- a/common/src/main/ets/default/function/CameraBasicFunction.ts +++ b/common/src/main/ets/default/function/CameraBasicFunction.ts @@ -52,6 +52,10 @@ export class CameraBasicFunction extends Function { private async initCamera(data) { Log.info(`${this.TAG} initCamera ${JSON.stringify(data)} E`) + let curStorageCameraId = AppStorage.Get('storageCameraId') + if (curStorageCameraId){ + data.cameraId = curStorageCameraId + } this.mCameraId = data.cameraId this.mCurrentMode = data.mode let mCameraCount = await this.mCameraService.initCamera(this.mCameraId) diff --git a/product/phone/src/main/ets/pages/index.ets b/product/phone/src/main/ets/pages/index.ets index 51325194f97c7dbf05f3f33b872978e39ae313ba..5fe4edf4ed1be219600492969b475d9530aa7fdd 100644 --- a/product/phone/src/main/ets/pages/index.ets +++ b/product/phone/src/main/ets/pages/index.ets @@ -84,6 +84,8 @@ let indexDispatcher = (dispatch) => { } } +PersistentStorage.PersistProp("storageCameraId", "") + @Entry @Component struct Index { @@ -159,6 +161,8 @@ struct Index { onPageShow(): void { Log.info(`${this.TAG} onPageShow this.permissionFlag: ${this.state.permissionFlag} globalThis.permissionFlag: ${globalThis.permissionFlag}`) this.state.setPermissionFlag(globalThis.permissionFlag) + let curCameraId = AppStorage.Get('storageCameraId') + if(curCameraId) this.state.initCameraPosition(curCameraId) } aboutToDisappear(): void { diff --git a/product/tablet/src/main/ets/pages/indexLand.ets b/product/tablet/src/main/ets/pages/indexLand.ets index 7a5462f629f420b356eb1f7c54110ef7201b4160..75dda95cb6900fed23d09f797c35a1007b32e053 100644 --- a/product/tablet/src/main/ets/pages/indexLand.ets +++ b/product/tablet/src/main/ets/pages/indexLand.ets @@ -84,6 +84,8 @@ let indexDispatcher = (dispatch) => { } } +PersistentStorage.PersistProp("storageCameraId", "") + @Entry @Component struct Index { @@ -157,6 +159,8 @@ struct Index { onPageShow(): void { Log.info(`${this.TAG} onPageShow this.permissionFlag: ${this.state.permissionFlag} globalThis.permissionFlag: ${globalThis.permissionFlag}`) this.state.setPermissionFlag(globalThis.permissionFlag) + let curCameraId = AppStorage.Get('storageCameraId') + if(curCameraId) this.state.initCameraPosition(curCameraId) } aboutToDisappear(): void {