1/* 2 * Copyright (c) 2021 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 16let WindowManager = requireNapi('window'); 17let WindowName = 'wallpaper'; 18let windowType = 2000; 19let windowsCreated = false; 20let WIDTH = 480; 21let HEIGHT = 960; 22 23class WallpaperExtensionAbility { 24 createWallpaperWin() { 25 console.log(`${WindowName} createWallpaperWin`); 26 27 WindowManager.create(this.context, WindowName, windowType).then((win) => { 28 console.log(`${WindowName} wallpaperWindow`); 29 this.wallpaperWindow = win; 30 console.log(this.wallpaperWindow); 31 this.wallpaperWindow.moveTo(0, 0).then(() => { 32 this.wallpaperWindow.resetSize(WIDTH, HEIGHT).then(() => { 33 console.log(`${WindowName} resetSize ${this.wallpaperURI}`); 34 this.loadUiContent(this.wallpaperURI); 35 console.log(`${WindowName} window created`); 36 windowsCreated = true; 37 }); 38 }); 39 }, (error) => { 40 console.log(`${WindowName} window createFailed, error.code = ${error.code}`); 41 }); 42 } 43 44 onCreate(want) { 45 console.log(`${WindowName} onWallpaperExtensionAbilityCreate`); 46 } 47 48 setUiContent(uri) { 49 console.log(`${WindowName} setUiContent`); 50 if (windowsCreated) { 51 console.log(`${WindowName} loadUiContent`); 52 loadUiContent(uri); 53 } else { 54 console.log(`${WindowName} save wallpaperURI`); 55 this.wallpaperURI = uri; 56 } 57 } 58 59 loadUiContent(uri) { 60 console.log(`${WindowName} initUiContent ${uri}`); 61 this.wallpaperWindow.loadContent(uri).then(() => { 62 console.log(`${WindowName} loadContent`); 63 this.wallpaperWindow.show().then(() => { 64 console.log(`${WindowName} window is show`); 65 }); 66 }); 67 } 68 69 onWallpaperChange(wallpaperType) { 70 console.log(`${WindowName} onWallpaperChange ${wallpaperType}`); 71 } 72 73 onDestroy() { 74 console.log(`${WindowName} onWallpaperExtensionAbilityDestroy`); 75 } 76} 77 78export default WallpaperExtensionAbility;