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 { paramMock } from "../../utils" 17import { ContextClass } from "./Context" 18 19export const ApplicationContextClass = class ApplicationContext extends ContextClass { 20 constructor() { 21 super(); 22 console.warn('ApplicationContext.constructor interface mocked in the Previewer. How this interface works on' + 23 ' the Previewer may be different from that on a real device.'); 24 this.registerAbilityLifecycleCallback = function (...args) { 25 console.warn("ApplicationContext.registerAbilityLifecycleCallback interface mocked in the Previewer." + 26 " How this interface works on the Previewer may be different from that on a real device.") 27 return paramMock.paramNumberMock 28 }; 29 this.unregisterAbilityLifecycleCallback = function (...args) { 30 console.warn("ApplicationContext.unregisterAbilityLifecycleCallback interface mocked in the Previewer." + 31 " How this interface works on the Previewer may be different from that on a real device.") 32 const len = args.length 33 if (len > 0 && typeof args[len - 1] === 'function') { 34 args[len - 1].call(this, paramMock.businessErrorMock); 35 } else { 36 return new Promise((resolve, reject) => { 37 resolve(); 38 }) 39 } 40 }; 41 this.registerEnvironmentCallback = function (...args) { 42 console.warn("ApplicationContext.registerEnvironmentCallback interface mocked in the Previewer." + 43 " How this interface works on the Previewer may be different from that on a real device.") 44 return paramMock.paramNumberMock 45 }; 46 this.unregisterEnvironmentCallback = function (...args) { 47 console.warn("ApplicationContext.unregisterEnvironmentCallback interface mocked in the Previewer." + 48 " How this interface works on the Previewer may be different from that on a real device.") 49 const len = args.length 50 if (len > 0 && typeof args[len - 1] === 'function') { 51 args[len - 1].call(this, paramMock.businessErrorMock); 52 } else { 53 return new Promise((resolve, reject) => { 54 resolve(); 55 }) 56 } 57 }; 58 } 59 }