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): void { 29 WorkerHandler.socketHandler(result); 30}; 31 32let abilityWindowStage; 33export default class MainAbility extends Ability { 34 onCreate(): void { 35 console.log('cm-MainAbility-onCreate'); 36 globalThis.showFloatingWindow = false; 37 BundleManager.getAppList().then((appList) => { 38 globalThis.appList = appList; 39 }); 40 } 41 onDestroy(): void { 42 console.log('cm-MainAbility-onDestroy'); 43 MainWorker.terminate(); 44 } 45 onWindowStageCreate(windowStage): void { 46 globalThis.abilityContext = this.context; 47 abilityWindowStage = windowStage; 48 abilityWindowStage.setUIContent(this.context, 'pages/LoginPage', null); 49 globalThis.useDaemon = false; 50 display.getDefaultDisplay().then( 51 (disp) => { 52 globalThis.screenWith = disp.width; 53 if (globalThis.screenWith > 1400) { 54 globalThis.coefficient = 1; 55 console.log( 56 'globalThis.screenWith :coefficient-- ' + globalThis.coefficient 57 ); 58 } else if ( 59 globalThis.screenWith > 800 && 60 globalThis.screenWith < 1400 61 ) { 62 globalThis.coefficient = 1.8; 63 console.log( 64 'globalThis.screenWith :coefficient-- ' + globalThis.coefficient 65 ); 66 } else { 67 globalThis.coefficient = 1; 68 console.log( 69 'globalThis.screenWith :coefficient-- ' + globalThis.coefficient 70 ); 71 } 72 console.log('globalThis.screenWith : ' + globalThis.screenWith); 73 }, 74 (err) => { 75 console.log( 76 'display.getDefaultDisplay failed, error : ' + JSON.stringify(err) 77 ); 78 } 79 ); 80 } 81 onWindowStageDestroy(): void {} 82 onForeground(): void { 83 console.log('cm-MainAbility-onForeground'); 84 initDb(); 85 FloatWindowFun.initAllFun(); 86 //NetWork.getInstance().init() 87 MainWorker.postMessage({ testConnection: true }); 88 } 89 onBackground(): void {} 90} 91