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 type { MenuOperation } from '../view/browserOperation/MenuOperation'; 17import { MenuContext } from '../view/browserOperation/MenuContext'; 18import { Log } from '../utils/Log'; 19import { Constants } from '../model/common/Constants'; 20 21const TAG: string = 'common_MenuOperationFactory'; 22 23export class MenuOperationFactory { 24 private constructor() { 25 Log.info(TAG, 'constructor'); 26 } 27 28 public static getInstance(): MenuOperationFactory { 29 if (AppStorage.Get(Constants.APP_KEY_MENU_OPERATION_FACTORY) == null) { 30 AppStorage.setOrCreate(Constants.APP_KEY_MENU_OPERATION_FACTORY, new MenuOperationFactory()); 31 } 32 return AppStorage.Get(Constants.APP_KEY_MENU_OPERATION_FACTORY); 33 } 34 35 public createMenuOperation<T extends MenuOperation> 36 (operation: { new(menuContext: MenuContext): T }, menuContext: MenuContext): T { 37 Log.info(TAG, `createMenuOperation: ${operation.name}`); 38 return new operation(menuContext); 39 } 40}