1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { config } from './Config'; 17import { taskpool } from '@kit.ArkTS'; 18 19@Concurrent 20async function download() { 21 if (!await config.isWifiOn()) { 22 console.info('wifi is off'); 23 return false; 24 } 25 if (!await config.getIsLogin()) { 26 console.info('not login'); 27 return false; 28 } 29 console.info(`User[${await config.getUser()}] start download ...`); 30 return true; 31} 32 33@Entry 34@Component 35struct Index { 36 @State message: string = 'not login'; 37 @State wifiState: string = 'wifi off'; 38 @State downloadResult: string = ''; 39 input: string = ''; 40 41 build() { 42 Row() { 43 Column() { 44 Text(this.message) 45 .fontSize(50) 46 .fontWeight(FontWeight.Bold) 47 .alignRules({ 48 center: { anchor: '__container__', align: VerticalAlign.Center }, 49 middle: { anchor: '__container__', align: HorizontalAlign.Center } 50 }) 51 TextInput({ placeholder: '请输入用户名' }) 52 .id('textInput') 53 .fontSize(20) 54 .fontWeight(FontWeight.Bold) 55 .alignRules({ 56 center: { anchor: '__container__', align: VerticalAlign.Center }, 57 middle: { anchor: '__container__', align: HorizontalAlign.Center } 58 }) 59 .onChange((value) => { 60 this.input = value; 61 }) 62 Text('login') 63 .fontSize(50) 64 .fontWeight(FontWeight.Bold) 65 .alignRules({ 66 center: { anchor: '__container__', align: VerticalAlign.Center }, 67 middle: { anchor: '__container__', align: HorizontalAlign.Center } 68 }) 69 .onClick(async () => { 70 if (!await config.getIsLogin() && this.input) { 71 this.message = 'login: ' + this.input; 72 config.login(this.input); 73 } 74 }) 75 .backgroundColor(0xcccccc) 76 Text('logout') 77 .fontSize(50) 78 .fontWeight(FontWeight.Bold) 79 .alignRules({ 80 center: { anchor: '__container__', align: VerticalAlign.Center }, 81 middle: { anchor: '__container__', align: HorizontalAlign.Center } 82 }) 83 .onClick(async () => { 84 if (await config.getIsLogin()) { 85 this.message = 'not login'; 86 config.logout(); 87 } 88 }) 89 .backgroundColor(0xcccccc) 90 Text(this.wifiState) 91 .fontSize(50) 92 .fontWeight(FontWeight.Bold) 93 .alignRules({ 94 center: { anchor: '__container__', align: VerticalAlign.Center }, 95 middle: { anchor: '__container__', align: HorizontalAlign.Center } 96 }) 97 Toggle({ type: ToggleType.Switch }) 98 .onChange(async (isOn: boolean) => { 99 await config.setWifiState(isOn) 100 this.wifiState = isOn ? 'wifi on' : 'wifi off'; 101 }) 102 Text('download') 103 .fontSize(50) 104 .fontWeight(FontWeight.Bold) 105 .alignRules({ 106 center: { anchor: '__container__', align: VerticalAlign.Center }, 107 middle: { anchor: '__container__', align: HorizontalAlign.Center } 108 }) 109 .onClick(async () => { 110 let ret = await taskpool.execute(download); 111 this.downloadResult = ret ? 'download success' : 'download fail'; 112 }) 113 Text(this.downloadResult) 114 .fontSize(20) 115 .fontWeight(FontWeight.Bold) 116 .alignRules({ 117 center: { anchor: '__container__', align: VerticalAlign.Center }, 118 middle: { anchor: '__container__', align: HorizontalAlign.Center } 119 }) 120 } 121 .width('100%') 122 } 123 .height('100%') 124 } 125} 126