1/** 2 * Copyright (c) 2021-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 { ShortcutInfo } from 'bundle/shortcutInfo'; 17import launcherBundleManager from '@ohos.bundle.launcherBundleManager'; 18import { AppListViewModel } from './AppListViewModel'; 19 20const TAG = 'AppGridViewModel'; 21 22/** 23 * AppGridViewModel 24 */ 25export class AppGridViewModel extends AppListViewModel { 26 private constructor() { 27 super(); 28 } 29 30 /** 31 * get instance 32 */ 33 static getInstance(): AppGridViewModel { 34 if (globalThis.AppGridViewModel == null) { 35 globalThis.AppGridViewModel = new AppGridViewModel(); 36 } 37 return globalThis.AppGridViewModel; 38 } 39 40 /** 41 * Register to listen to events 42 */ 43 registerAppListChange() { 44 this.registerAppListChangeCallback(); 45 } 46 47 /** 48 * Unregister listener events 49 */ 50 unregisterAppListChange() { 51 this.unregisterAppListChangeCallback(); 52 } 53 54 registerEventListener() { 55 this.onAppListViewCreate(); 56 } 57 58 unregisterEventListener() { 59 this.onAppListViewDestroy(); 60 } 61 62 /** 63 * Get shortcut information by bundleName 64 */ 65 getShortcutInfo(bundleName: string): launcherBundleManager.ShortcutInfo[] | undefined { 66 return this.mAppModel.getShortcutInfo(bundleName); 67 } 68}