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 ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; 17import windowManager from '@ohos.window'; 18import display from '@ohos.display'; 19import Log from '../../../../../../common/src/main/ets/default/Log'; 20import Constants from '../../../../../../features/screenshot/src/main/ets/com/ohos/common/constants'; 21import ScreenShotModel from '../../../../../../features/screenshot/src/main/ets/com/ohos/model/screenShotModel'; 22 23const TAG = "ScreenShot-ScreenShotServiceAbility"; 24const INDEX_PAGE = "pages/index"; 25const ZOOM_RATIO = 0.4; 26const SHOT_WINDOW_TYPE = 2111; 27const WINDOW_Y = 300; 28 29class ServiceExtAbility extends ServiceExtensionAbility { 30 onCreate(want) { 31 Log.showInfo(TAG, 'api8New onCreate, want:' + want.abilityName); 32 globalThis.shotScreenContext = this.context; 33 windowManager.create(this.context, Constants.WIN_NAME, SHOT_WINDOW_TYPE).then((win) => { 34 Log.showInfo(TAG, "create window finish!") 35 win.moveTo(0, WINDOW_Y).then(() => { 36 Log.showInfo(TAG, " window moveTo finish") 37 display.getDefaultDisplay().then(dis => { 38 Log.showInfo(TAG, " dis.width = " + dis.width + " dis.height = " + dis.height) 39 win.resetSize(dis.width * ZOOM_RATIO, dis.height * ZOOM_RATIO).then(() => { 40 Log.showInfo(TAG, " window reset size finish") 41 win.loadContent(INDEX_PAGE).then(() => { 42 ScreenShotModel.shotScreen(); 43 Log.showInfo(TAG, "then begin window loadContent in then! "); 44 }) 45 }) 46 }) 47 }) 48 }, (error) => { 49 Log.showInfo(TAG, " window createFailed, error.code = " + error.code) 50 }) 51 Log.showInfo(TAG, " after window create") 52 } 53 54 onDestroy() { 55 Log.showInfo(TAG, `onDestroy`); 56 } 57} 58 59export default ServiceExtAbility