/* * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import router from '@ohos.router' import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; import dataStorage from '@ohos.data.storage'; import common from '@ohos.app.ability.common'; @Entry @Component struct indexPage { @State currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT; private storage: dataStorage.Storage | undefined = undefined; async aboutToAppear() { try { const context = getContext(this) as common.UIAbilityContext; this.storage = await dataStorage.getStorage(context.cacheDir); if (this.storage) { const colorMode = await this.storage.get('currentColorMode', this.currentMode); this.currentMode = colorMode as number; this.updateUI(); } } catch (err) { console.error('Failed to get color mode:', err); } } updateUI() { if (this.currentMode == ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) { console.info('当前为浅色模式'); } else { console.info('当前为深色模式'); } } build() { Column() { Button($r('app.string.video_demo')) .margin({ bottom: 20 }) .width(200) .onClick(() => { router.pushUrl({ url: 'pages/SampleVideoListPage' }) }) Button($r('app.string.audio_demo')) .width(200) .onClick(() => { router.pushUrl({ url: 'pages/SampleAudioListPage' }) }) } .width('100%') .height('100%') .backgroundColor(this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT ? Color.Gray : '#121212') .justifyContent(FlexAlign.Center) } }