diff --git a/runtime/main/extend/systemplugin/napi/filemanager.js b/runtime/main/extend/systemplugin/napi/filemanager.js new file mode 100644 index 0000000000000000000000000000000000000000..27b6174f2097c2fe6d5375f901707c50e24ab261 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/filemanager.js @@ -0,0 +1,43 @@ +import { paramMock } from "../utils" + +export function mockFileManager() { + const filemanager = { + getRoot: function (...args) { + console.warn("filemanager.getRoot 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.paramArrayMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + listFile: function (...args) { + console.warn("filemanager.listFile 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.paramArrayMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramArrayMock); + }) + } + }, + createFile: function (...args) { + console.warn("filemanager.createFile 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, reject) => { + resolve(paramMock.paramStringMock); + }) + } + }, + } + return filemanager; +} diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index c7a588b2743bdf0c95d2ed5b2cc862fb46af5aab..eacdef4a8bc97b5245e4cc2d0c90bbf24c661c52 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -35,6 +35,7 @@ import { mockSettings } from './settings' import { mockUri } from './uri' import { mockXml } from './xml' import { mockStatfs } from './statfs' +import { mockFileManager } from "./filemanager" export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -113,6 +114,8 @@ export function mockRequireNapiFun() { return mockXml(); case "statfs": return mockStatfs(); + case "filemanager": + return mockFileManager(); default: return global.requireNapiPreview(...args); }