Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

device.js 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. cordova.define("cordova-plugin-device.device", function(require, exports, module) {
  2. /*
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. */
  22. var argscheck = require('cordova/argscheck');
  23. var channel = require('cordova/channel');
  24. var utils = require('cordova/utils');
  25. var exec = require('cordova/exec');
  26. var cordova = require('cordova');
  27. channel.createSticky('onCordovaInfoReady');
  28. // Tell cordova channel to wait on the CordovaInfoReady event
  29. channel.waitForInitialization('onCordovaInfoReady');
  30. /**
  31. * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
  32. * phone, etc.
  33. * @constructor
  34. */
  35. function Device () {
  36. this.available = false;
  37. this.platform = null;
  38. this.version = null;
  39. this.uuid = null;
  40. this.cordova = null;
  41. this.model = null;
  42. this.manufacturer = null;
  43. this.isVirtual = null;
  44. this.serial = null;
  45. var me = this;
  46. channel.onCordovaReady.subscribe(function () {
  47. me.getInfo(function (info) {
  48. // ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
  49. // TODO: CB-5105 native implementations should not return info.cordova
  50. var buildLabel = cordova.version;
  51. me.available = true;
  52. me.platform = info.platform;
  53. me.version = info.version;
  54. me.uuid = info.uuid;
  55. me.cordova = buildLabel;
  56. me.model = info.model;
  57. me.isVirtual = info.isVirtual;
  58. me.manufacturer = info.manufacturer || 'unknown';
  59. me.serial = info.serial || 'unknown';
  60. channel.onCordovaInfoReady.fire();
  61. }, function (e) {
  62. me.available = false;
  63. utils.alert('[ERROR] Error initializing Cordova: ' + e);
  64. });
  65. });
  66. }
  67. /**
  68. * Get device info
  69. *
  70. * @param {Function} successCallback The function to call when the heading data is available
  71. * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
  72. */
  73. Device.prototype.getInfo = function (successCallback, errorCallback) {
  74. argscheck.checkArgs('fF', 'Device.getInfo', arguments);
  75. exec(successCallback, errorCallback, 'Device', 'getDeviceInfo', []);
  76. };
  77. module.exports = new Device();
  78. });