define([], function() { // filesystem feature function fileExists(path) { if (!globalThis.NativeAppHost.supports('filesystem')) { return Promise.reject(); } return globalThis.NativeFeature.fileExists(path); } function directoryExists(path) { if (!globalThis.NativeAppHost.supports('filesystem')) { return Promise.reject(); } return globalThis.NativeFeature.directoryExists(path); } // wakeonlan feature function send(info) { if (!globalThis.NativeAppHost.supports('wakeonlan')) { return Promise.reject(); } globalThis.NativeFeatures.sendPacket(info.BroadcastAddress || "255.255.255.255", info.MacAddress, info.Port); return Promise.resolve(); } function isSupported() { return globalThis.NativeAppHost.supports('wakeonlan'); } // serverdiscovery feature function findServers(timeoutMs) { if (!window.ServerDiscovery) { window.ServerDiscovery = this; } if (!globalThis.NativeAppHost.supports('serverlocator')) { return Promise.reject(); } return globalThis.NativeFeatures.findServersAsync(timeoutMs).then(function(servers) { let typedServers = servers.map((e) => JSON.parse(e)); return Promise.resolve(typedServers); }); } // shell feature function openUrl(url) { if (!globalThis.NativeAppHost.supports('shellopenurl')) { window.open(url, '_blank'); } globalThis.NativeFeatures.shellOpenUrl(url); }; function canExec(url) { return globalThis.NativeAppHost.supports('shellexec'); }; function exec(options) { // options.path // options.arguments if (!globalThis.NativeAppHost.supports('shellexec')) { return Promise.reject(); } return globalThis.NativeFeatures.shellExecAsync(options); }; return { // filesystem feature fileExists: fileExists, directoryExists: directoryExists, // wakeonlan feature send: send, isSupported: isSupported, // serverdiscovery feature findServers: findServers, // shell feature openUrl: openUrl, canExec: canExec, exec: exec }; });