1/* 2 * Copyright (C) 2022 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 Ability from '@ohos.app.ability.UIAbility' 17import { initDb } from '../common/database/LocalRepository' 18import { FloatWindowFun } from '../common/ui/floatwindow/FloatWindowFun' 19import { NetWork } from '../common/profiler/item/NetWork'; 20import BundleManager from '../common/utils/BundleMangerUtils'; 21import display from '@ohos.display' // 导入模块 22import WorkerHandler from '../common/profiler/WorkerHandler'; 23import worker from '@ohos.worker'; 24 25let MainWorker = new worker.Worker("entry/ets/workers/worker.js") 26globalThis.MainWorker = MainWorker 27 28MainWorker.onmessage = function (result) { 29 WorkerHandler.socketHandler(result) 30} 31 32let abilityWindowStage; 33export default class MainAbility extends Ability { 34 35 onCreate(want, launchParam) { 36 globalThis.showFloatingWindow=false 37 BundleManager.getAppList().then(appList => { 38 globalThis.appList = appList 39 }) 40 } 41 onDestroy() { 42 MainWorker.terminate() 43 } 44 onWindowStageCreate(windowStage) { 45 globalThis.abilityContext = this.context 46 abilityWindowStage = windowStage; 47 abilityWindowStage.setUIContent(this.context, "pages/LoginPage", null) 48 globalThis.useDaemon = false 49 display.getDefaultDisplay().then((disp) => { 50 globalThis.screenWith = disp.width 51 if(globalThis.screenWith>1400){ 52 globalThis.coefficient=1 53 console.log('globalThis.screenWith :coefficient-- ' + globalThis.coefficient); 54 }else if( globalThis.screenWith>800&&globalThis.screenWith<1400){ 55 globalThis.coefficient=1.8 56 console.log('globalThis.screenWith :coefficient-- ' + globalThis.coefficient); 57 }else{ 58 globalThis.coefficient=1 59 console.log('globalThis.screenWith :coefficient-- ' + globalThis.coefficient); 60 } 61 console.log('globalThis.screenWith : ' + globalThis.screenWith); 62 }, (err) => { 63 console.log('display.getDefaultDisplay failed, error : ' + JSON.stringify(err)); 64 }) 65 } 66 onWindowStageDestroy() {} 67 onForeground() { 68 initDb() 69 FloatWindowFun.initAllFun() 70 //NetWork.getInstance().init() 71 MainWorker.postMessage({ "testConnection": true }) 72 } 73 onBackground() {} 74}; 75 76 77 78 79