|
| 1 | +"use strict"; |
| 2 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 | +var contacts_1 = require("../../test/mock/contacts"); |
| 4 | +var accelerometer_1 = require("../../test/mock/accelerometer"); |
| 5 | +var camera_1 = require("../../test/mock/camera"); |
| 6 | +var compass_1 = require("../../test/mock/compass"); |
| 7 | +var geolocation_1 = require("../../test/mock/geolocation"); |
| 8 | +var media_1 = require("../../test/mock/media"); |
| 9 | +var capture_1 = require("../../test/mock/capture"); |
| 10 | +var notifications_1 = require("../../test/mock/notifications"); |
| 11 | +var connection_1 = require("../../test/mock/connection"); |
| 12 | +var vibrate_1 = require("../../test/mock/vibrate"); |
| 13 | +var local_file_system_1 = require("../plugins/file/local-file-system"); |
| 14 | +var file_transfer_1 = require("../../test/mock/file-transfer"); |
| 15 | +var util_1 = require("./util"); |
| 16 | +var storage_1 = require("../plugins/storage/storage"); |
| 17 | +var on_device_storage_1 = require("../plugins/storage/on-device-storage"); |
| 18 | +var persistent_storage_1 = require("../../test/mock/persistent-storage"); |
| 19 | +var desktop_storage_1 = require("../plugins/storage/desktop-storage"); |
| 20 | +var desktop_webview_1 = require("../plugins/webview/desktop-webview"); |
| 21 | +var AWProxy = (function () { |
| 22 | + function AWProxy() { |
| 23 | + } |
| 24 | + AWProxy.exec = function (successHandler, errorHandler, name, method, args) { |
| 25 | + if (typeof exports.cordova !== 'undefined') { |
| 26 | + exports.cordova.exec(successHandler, errorHandler, name, method, args); |
| 27 | + } |
| 28 | + else if (AWProxy.isDesktopEnv()) { |
| 29 | + exports.__aw_plugin_proxy.exec(successHandler, errorHandler, name, method, args); |
| 30 | + } |
| 31 | + else { |
| 32 | + console.error('No proxy objects defined - tried [Cordova, __aw_plugin_proxy]'); |
| 33 | + if (typeof errorHandler === 'function') { |
| 34 | + errorHandler('No proxy objects defined - tried [Cordova, __aw_plugin_proxy]'); |
| 35 | + } |
| 36 | + } |
| 37 | + }; |
| 38 | + AWProxy.accelerometer = function () { |
| 39 | + return typeof 'navigator' !== undefined ? exports.navigator.accelerometer : new accelerometer_1.MockAccelerometer(); |
| 40 | + }; |
| 41 | + AWProxy.camera = function () { |
| 42 | + return typeof exports.navigator !== 'undefined' ? exports.navigator.camera : new camera_1.MockCamera(); |
| 43 | + }; |
| 44 | + AWProxy.Camera = function () { |
| 45 | + return (typeof exports.Camera !== 'undefined') ? exports.Camera : { |
| 46 | + DestinationType: { |
| 47 | + DATA_URL: null, |
| 48 | + FILE_URI: null, |
| 49 | + NATIVE_URI: null, |
| 50 | + }, |
| 51 | + Direction: { |
| 52 | + BACK: null, |
| 53 | + FRONT: null, |
| 54 | + }, |
| 55 | + EncodingType: { |
| 56 | + JPEG: null, |
| 57 | + PNG: null, |
| 58 | + }, |
| 59 | + MediaType: { |
| 60 | + PICTURE: null, |
| 61 | + VIDEO: null, |
| 62 | + ALLMEDIA: null, |
| 63 | + }, |
| 64 | + PictureSourceType: { |
| 65 | + PHOTOLIBRARY: null, |
| 66 | + CAMERA: null, |
| 67 | + SAVEDPHOTOALBUM: null, |
| 68 | + }, |
| 69 | + // Used only on iOS |
| 70 | + PopoverArrowDirection: { |
| 71 | + ARROW_UP: null, |
| 72 | + ARROW_DOWN: null, |
| 73 | + ARROW_LEFT: null, |
| 74 | + ARROW_RIGHT: null, |
| 75 | + ARROW_ANY: null |
| 76 | + } |
| 77 | + }; |
| 78 | + }; |
| 79 | + AWProxy.compass = function () { |
| 80 | + return typeof exports.navigator !== 'undefined' ? exports.navigator.compass : new compass_1.MockCompass(); |
| 81 | + }; |
| 82 | + AWProxy.connection = function () { |
| 83 | + return typeof exports.navigator !== 'undefined' ? exports.navigator.connection : new connection_1.MockConnection(); |
| 84 | + }; |
| 85 | + AWProxy.Connection = function () { |
| 86 | + return (typeof exports.Connection !== 'undefined') ? exports.Connection : { |
| 87 | + UNKNOWN: null, |
| 88 | + ETHERNET: null, |
| 89 | + WIFI: null, |
| 90 | + CELL_2G: null, |
| 91 | + CELL_3G: null, |
| 92 | + CELL_4G: null, |
| 93 | + CELL: null, |
| 94 | + NONE: null |
| 95 | + }; |
| 96 | + }; |
| 97 | + AWProxy.contacts = function () { |
| 98 | + return typeof exports.navigator !== 'undefined' ? exports.navigator.contacts : new contacts_1.MockContacts(); |
| 99 | + }; |
| 100 | + AWProxy.device = function () { |
| 101 | + var _device = (typeof exports.device !== 'undefined') ? exports.device : { |
| 102 | + cordova: null, |
| 103 | + available: true, |
| 104 | + model: null, |
| 105 | + platform: null, |
| 106 | + uuid: null, |
| 107 | + version: null, |
| 108 | + manufacturer: null, |
| 109 | + isVirtual: null, |
| 110 | + serial: null, |
| 111 | + capture: null |
| 112 | + }; |
| 113 | + if (typeof exports.navigator !== 'undefined' && exports.navigator.device && exports.navigator.device.capture) { |
| 114 | + _device.capture = exports.navigator.device.capture; |
| 115 | + } |
| 116 | + else { |
| 117 | + _device.capture = new capture_1.MockCapture(); |
| 118 | + } |
| 119 | + return _device; |
| 120 | + }; |
| 121 | + AWProxy.document = function () { |
| 122 | + return (typeof document !== 'undefined') ? document : { |
| 123 | + addEventListener: util_1.Util.noop |
| 124 | + }; |
| 125 | + }; |
| 126 | + AWProxy.file = function () { |
| 127 | + if (typeof exports.cordova !== 'undefined') { |
| 128 | + return exports.cordova.file; |
| 129 | + } |
| 130 | + else { |
| 131 | + return { |
| 132 | + documentsDirectory: '' |
| 133 | + }; |
| 134 | + } |
| 135 | + }; |
| 136 | + AWProxy.filetransfer = function () { |
| 137 | + return AWProxy.doGetFileTransfer(); |
| 138 | + }; |
| 139 | + // alias name |
| 140 | + AWProxy.fileTransfer = function () { |
| 141 | + return AWProxy.doGetFileTransfer(); |
| 142 | + }; |
| 143 | + AWProxy.doGetFileTransfer = function () { |
| 144 | + if (AWProxy.isDesktopEnv()) { |
| 145 | + var plugin = AWProxy.getDesktopPlugin('AWFileTransfer'); |
| 146 | + return (plugin !== null) ? plugin : new file_transfer_1.MockFileTransfer(); |
| 147 | + } |
| 148 | + return (typeof exports.FileTransfer !== 'undefined') ? new exports.FileTransfer() : new file_transfer_1.MockFileTransfer(); |
| 149 | + }; |
| 150 | + AWProxy.geolocation = function () { |
| 151 | + return (typeof exports.navigator !== 'undefined') ? exports.navigator.geolocation : new geolocation_1.MockGeolocation(); |
| 152 | + }; |
| 153 | + AWProxy.localFileSystem = function () { |
| 154 | + return local_file_system_1.LocalFileSystem; |
| 155 | + }; |
| 156 | + AWProxy.media = function (src, successHandler, errorHandler, statusChangeHandler) { |
| 157 | + if (typeof exports.Media !== 'undefined') { |
| 158 | + return new exports.Media(src, successHandler, errorHandler, statusChangeHandler); |
| 159 | + } |
| 160 | + else { |
| 161 | + return new media_1.MockMedia(src, successHandler, errorHandler, statusChangeHandler); |
| 162 | + } |
| 163 | + }; |
| 164 | + AWProxy.notification = function () { |
| 165 | + return (typeof exports.navigator !== 'undefined') ? exports.navigator.notification : new notifications_1.MockNotification(); |
| 166 | + }; |
| 167 | + AWProxy.requestFileSystem = function (type, size, successCallback, errorCallback) { |
| 168 | + if (exports.window.requestFileSystem) { |
| 169 | + return exports.window.requestFileSystem(type, size, successCallback, errorCallback); |
| 170 | + } |
| 171 | + }; |
| 172 | + AWProxy.vibrate = function (time) { |
| 173 | + if (typeof exports.navigator !== 'undefined' && exports.navigator.vibrate) { |
| 174 | + return exports.navigator.vibrate(time); |
| 175 | + } |
| 176 | + else { |
| 177 | + return new vibrate_1.MockVibrate().vibrate(time); |
| 178 | + } |
| 179 | + }; |
| 180 | + AWProxy.webview = function () { |
| 181 | + if (typeof exports.cordova !== 'undefined') { |
| 182 | + return exports.cordova.InAppBrowser; |
| 183 | + } |
| 184 | + else { |
| 185 | + return new desktop_webview_1.DesktopWebview(); |
| 186 | + } |
| 187 | + }; |
| 188 | + AWProxy.storage = function () { |
| 189 | + return new storage_1.AWStorage(); |
| 190 | + }; |
| 191 | + AWProxy.persistentStorage = function () { |
| 192 | + var desktopPlugin = AWProxy.getDesktopPlugin('AWStorage'); |
| 193 | + return desktopPlugin !== null ? |
| 194 | + new desktop_storage_1.DesktopStorage(desktopPlugin) : (AWProxy.isMobileEnv()) ? |
| 195 | + new on_device_storage_1.OnDeviceStorage() : new persistent_storage_1.PersistentStorageMock(); |
| 196 | + }; |
| 197 | + /** |
| 198 | + * Are we executing within the AppWorks Desktop context. |
| 199 | + * |
| 200 | + * @returns {boolean} true if this is a desktop environment, false otherwise |
| 201 | + */ |
| 202 | + AWProxy.isDesktopEnv = function () { |
| 203 | + return typeof exports.__aw_plugin_proxy !== 'undefined'; |
| 204 | + }; |
| 205 | + /** |
| 206 | + * Are we executing within the AppWorks mobile context. |
| 207 | + * |
| 208 | + * @return {boolean} true if Cordova is available, false otherwise |
| 209 | + */ |
| 210 | + AWProxy.isMobileEnv = function () { |
| 211 | + return typeof exports.cordova !== 'undefined'; |
| 212 | + }; |
| 213 | + /** |
| 214 | + * Ask the AppWorks desktop environment to retrieve an instance of a specific plugin. |
| 215 | + * |
| 216 | + * @param pluginName plugin identifier |
| 217 | + * @returns {any} plugin instance or null if no such plugin exists or the method was |
| 218 | + * called outside of the desktop client context |
| 219 | + */ |
| 220 | + AWProxy.getDesktopPlugin = function (pluginName) { |
| 221 | + if (!AWProxy.isDesktopEnv()) |
| 222 | + return null; |
| 223 | + // the proxy exposed by desktop has a method to allow retrieval of plugin instances |
| 224 | + return exports.__aw_plugin_proxy.getPlugin(pluginName); |
| 225 | + }; |
| 226 | + return AWProxy; |
| 227 | +}()); |
| 228 | +exports.AWProxy = AWProxy; |
0 commit comments