• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WallpaperExtension {
24  createWallpaperWin() {
25    console.log(WindowName + ' createWallpaperWin');
26    console.log(this.context);
27    console.log(WindowName + JSON.stringify(this.context));
28    console.log(windowType);
29    console.log(WindowName + JSON.stringify(windowType));
30
31    WindowManager.create(this.context, WindowName, windowType).then((win) => {
32      console.log(WindowName + 'wallpaperWindow');
33      this.wallpaperWindow = win;
34      console.log(WindowName + JSON.stringify(this.wallpaperWindow));
35      console.log(this.wallpaperWindow);
36      console.log(WindowName + 'moveTo');
37      this.wallpaperWindow.moveTo(0, 0).then(() => {
38        console.log(WindowName + 'resetSize');
39        this.wallpaperWindow.resetSize(WIDTH, HEIGHT).then(() => {
40          console.log(WindowName + ' resetSize' + JSON.stringify(this.wallpaperURL));
41          this.loadUiContent(this.wallpaperURL);
42          console.log(WindowName + ' window created');
43          windowsCreated = true;
44        });
45      });
46    }, (error) => {
47      console.log(WindowName + ' window createFailed, error.code = ' + error.code);
48    });
49  }
50  onCreated(want) {
51    console.log(WindowName + 'onWallpaperExtensionCreated');
52  }
53
54  setUiContent(url) {
55    console.log(WindowName + ' setUiContent');
56    if (windowsCreated) {
57      console.log(WindowName + ' loadUiContent');
58      loadUiContent(url);
59    } else {
60      console.log(WindowName + ' save wallpaperURL');
61      this.wallpaperURL = url;
62    }
63  }
64
65  loadUiContent(url) {
66    console.log(WindowName + 'initUiContent' + url);
67    console.log(WindowName + JSON.stringify(this.wallpaperWindow));
68    console.log(WindowName + JSON.stringify(this.wallpaperWindow.loadContent));
69    console.log(WindowName + JSON.stringify(this.wallpaperWindow.loadContent(url)));
70    this.wallpaperWindow.loadContent(url).then(() => {
71      console.log(WindowName + ' loadContent');
72      this.wallpaperWindow.show().then(() => {
73        console.log(WindowName + ' window is show');
74      });
75    });
76  }
77
78  onWallpaperChanged(wallpaperType) {
79    console.log(WindowName + 'onWallpaperChanged' + JSON.stringify(wallpaperType));
80  }
81
82  onDestroy() {
83    console.log(WindowName + 'onWallpaperExtensionDestroy');
84  }
85}
86
87export default WallpaperExtension;