diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index 162c8002..26489abc 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -72,7 +72,6 @@ import { mockDeviceManager } from './deviceManager' import { mockScreenshot } from './screenshot' import {mockContact} from './contact' import {mockScreenLock} from "./screenLock" -import {mockSettings} from "./settings" import { mockAppAccount} from './ohos/appAccount' import { mockOsAccount} from './ohos/osAccount' import { mockOhosGeolocation } from './ohos/geolocation' @@ -158,7 +157,6 @@ export function mockSystemPlugin() { mockStorageInfoManager() mockContact() mockScreenLock() - mockSettings() mockAppAbilityManager() mockAppAccount() mockOsAccount() diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index ad16e98c..a410417d 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -38,6 +38,7 @@ import { mockInnerBundle } from './innerBundleManager' import { mockUri } from './uri' import { mockXml } from './xml' import { mockStatfs } from './statfs' +import { mockSettings } from './settings' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -122,6 +123,8 @@ export function mockRequireNapiFun() { return mockXml(); case "statfs": return mockStatfs(); + case "settings": + return mockSettings(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/napi/settings.js b/runtime/main/extend/systemplugin/napi/settings.js new file mode 100644 index 00000000..8c00c530 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/settings.js @@ -0,0 +1,22 @@ +import { paramMock } from "../utils" + +export function mockSettings() { + const settingsMock = { + getUri: function (...args) { + console.warn("settings.getUri interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramStringMock; + }, + getValue: function (...args) { + console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramStringMock; + }, + setValue: function (...args) { + console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device."); + return paramMock.paramBooleanMock; + }, + }; + return settingsMock; +} diff --git a/runtime/main/extend/systemplugin/settings.js b/runtime/main/extend/systemplugin/settings.js deleted file mode 100644 index a1e008d1..00000000 --- a/runtime/main/extend/systemplugin/settings.js +++ /dev/null @@ -1,69 +0,0 @@ -import { paramMock } from "./utils" - -export function mockSettings () { - const mockInfo = { - URI : "[PC Preview] unknow string" - } - global.systemplugin.settings = { - getURI: function (...args) { - console.warn("settings.getURI interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, mockInfo) - } else { - return new Promise((resolve) => { - resolve(mockInfo); - }) - } - }, - getValue: function (...args) { - console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramStringMock); - }) - } - }, - setValue: function (...args) { - console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve(); - }) - } - }, - enableAirplaneMode: function (...args) { - console.warn("settings.enableAirplaneMode interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) - } else { - return new Promise((resolve) => { - resolve(); - }) - } - }, - canShowFloating: function (...args) { - console.warn("settings.canShowFloating interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length - if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) - } else { - return new Promise((resolve) => { - resolve(paramMock.paramBooleanMock); - }) - } - }, - } -} \ No newline at end of file