cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/2] cordova-plugin-device git commit: CB-10238 Move device-plugin out from cordovalib to the plugin repository
Date Mon, 04 Jan 2016 22:16:05 GMT
Repository: cordova-plugin-device
Updated Branches:
  refs/heads/master e009fbaf4 -> 64956bb66


CB-10238 Move device-plugin out from cordovalib to the plugin repository


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/commit/dfc8211d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/tree/dfc8211d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/diff/dfc8211d

Branch: refs/heads/master
Commit: dfc8211dd26ab6171e8e9724e31589f99e819213
Parents: e009fba
Author: Tobias Bocanegra <tripod@adobe.com>
Authored: Mon Dec 21 16:06:13 2015 -0800
Committer: Tobias Bocanegra <tripod@adobe.com>
Committed: Mon Dec 21 16:06:13 2015 -0800

----------------------------------------------------------------------
 README.md           |  20 ++++++++-
 package.json        |   6 ++-
 plugin.xml          |  13 ++++++
 src/osx/CDVDevice.h |  30 ++++++++++++++
 src/osx/CDVDevice.m | 106 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 172 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/dfc8211d/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 6dc4384..6550210 100644
--- a/README.md
+++ b/README.md
@@ -59,6 +59,7 @@ Get the version of Cordova running on the device.
 - Tizen
 - Windows Phone 7 and 8
 - Windows 8
+- OSX
 
 ## device.model
 
@@ -75,6 +76,7 @@ different across versions of the same product.
 - Tizen
 - Windows Phone 7 and 8
 - Windows 8
+- OSX
 
 ### Quick Example
 
@@ -84,7 +86,8 @@ different across versions of the same product.
     // Browser:    Google Chrome   returns "Chrome"
     //             Safari          returns "Safari"
     // iOS:     for the iPad Mini, returns iPad2,5; iPhone 5 is iPhone 5,1. See http://theiphonewiki.com/wiki/index.php?title=Models
-    //
+    // OSX:                        returns "x86_64"
+    // 
     var model = device.model;
 
 ### Android Quirks
@@ -115,6 +118,7 @@ Get the device's operating system name.
 - Tizen
 - Windows Phone 7 and 8
 - Windows 8
+- OSX
 
 ### Quick Example
 
@@ -125,6 +129,7 @@ Get the device's operating system name.
     //   - "iOS"
     //   - "WinCE"
     //   - "Tizen"
+    //   - "Max OS X"
     var devicePlatform = device.platform;
 
 ### Windows Phone 7 Quirks
@@ -153,6 +158,7 @@ The details of how a UUID is generated are determined by the device manufacturer
 - Tizen
 - Windows Phone 7 and 8
 - Windows 8
+- OSX
 
 ### Quick Example
 
@@ -176,6 +182,10 @@ The `uuid` on iOS uses the identifierForVendor property. It is unique
to the dev
 See https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/#//apple_ref/occ/instp/UIDevice/identifierForVendor
 The UUID will be the same if app is restored from a backup or iCloud as it is saved in preferences.
Users using older versions of this plugin will still receive the same previous UUID generated
by another means as it will be retrieved from preferences.
 
+### OSX Quirk
+
+The `uuid` on OSX is generated automatically if it does not exist yet and is stored in the
`standardUserDefaults` in the `CDVUUID` property. 
+
 ### Windows Phone 7 and 8 Quirks
 
 The `uuid` for Windows Phone 7 requires the permission
@@ -199,6 +209,7 @@ Get the operating system version.
 - Tizen
 - Windows Phone 7 and 8
 - Windows 8
+- OSX
 
 ### Quick Example
 
@@ -215,6 +226,8 @@ Get the operating system version.
     // Windows Phone 7: returns current OS version number, ex. on Mango returns 7.10.7720
     // Windows 8: return the current OS version, ex on Windows 8.1 returns 6.3.9600.16384
     // Tizen: returns "TIZEN_20120425_2"
+    // OSX:        El Capitan would return "10.11.2"
+    //
     var deviceVersion = device.version;
 
 ## device.isVirtual
@@ -229,7 +242,11 @@ whether the device is running on a simulator.
 - iOS
 - Windows Phone 8
 - Windows 8
+- OSX 
+
+### OSX Quirk
 
+The `isVirtual` property on OS X always returns false.
 
 ## device.serial
 
@@ -240,4 +257,5 @@ Get the device hardware serial number ([SERIAL](http://developer.android.com/ref
 ### Supported Platforms
 
 - Android
+- OSX
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/dfc8211d/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 136ee50..ce2f481 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,8 @@
       "wp8",
       "windows8",
       "windows",
-      "browser"
+      "browser",
+      "osx"
     ]
   },
   "repository": {
@@ -38,7 +39,8 @@
     "cordova-wp8",
     "cordova-windows8",
     "cordova-windows",
-    "cordova-browser"
+    "cordova-browser",
+    "cordova-osx"
   ],
   "author": "Apache Software Foundation",
   "license": "Apache 2.0"

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/dfc8211d/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 5bc3f78..fbb1470 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -158,4 +158,17 @@
         </js-module>
     </platform>
 
+    <!-- osx -->
+    <platform name="osx">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Device">
+                <param name="ios-package" value="CDVDevice"/>
+            </feature>
+        </config-file>
+
+        <header-file src="src/osx/CDVDevice.h" />
+        <source-file src="src/osx/CDVDevice.m" />
+    </platform>
+
+
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/dfc8211d/src/osx/CDVDevice.h
----------------------------------------------------------------------
diff --git a/src/osx/CDVDevice.h b/src/osx/CDVDevice.h
new file mode 100644
index 0000000..a146d88
--- /dev/null
+++ b/src/osx/CDVDevice.h
@@ -0,0 +1,30 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <UIKit/UIKit.h>
+#import <Cordova/CDVPlugin.h>
+
+@interface CDVDevice : CDVPlugin
+{}
+
++ (NSString*)cordovaVersion;
+
+- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/dfc8211d/src/osx/CDVDevice.m
----------------------------------------------------------------------
diff --git a/src/osx/CDVDevice.m b/src/osx/CDVDevice.m
new file mode 100644
index 0000000..f58c321
--- /dev/null
+++ b/src/osx/CDVDevice.m
@@ -0,0 +1,106 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include "TargetConditionals.h"
+
+#import <Cordova/CDV.h>
+#import "CDVDevice.h"
+
+@implementation UIDevice (ModelVersion)
+
+- (NSString*)modelVersion
+{
+    size_t size;
+
+    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+    char* machine = malloc(size);
+    sysctlbyname("hw.machine", machine, &size, NULL, 0);
+    NSString* platform = [NSString stringWithUTF8String:machine];
+    free(machine);
+
+    return platform;
+}
+
+@end
+
+@interface CDVDevice () {}
+@end
+
+@implementation CDVDevice
+
+- (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device
+{
+    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
+    static NSString* UUID_KEY = @"CDVUUID";
+    
+    // Check user defaults first to maintain backwards compaitibility with previous versions
+    // which didn't user identifierForVendor
+    NSString* app_uuid = [userDefaults stringForKey:UUID_KEY];
+    if (app_uuid == nil) {
+        app_uuid = [[device identifierForVendor] UUIDString];
+        [userDefaults setObject:app_uuid forKey:UUID_KEY];
+        [userDefaults synchronize];
+    }
+    
+    return app_uuid;
+}
+
+- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
+{
+    NSDictionary* deviceProperties = [self deviceProperties];
+    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:deviceProperties];
+
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+- (NSDictionary*)deviceProperties
+{
+    UIDevice* device = [UIDevice currentDevice];
+    NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
+
+    [devProps setObject:@"Apple" forKey:@"manufacturer"];
+    [devProps setObject:[device modelVersion] forKey:@"model"];
+    [devProps setObject:@"iOS" forKey:@"platform"];
+    [devProps setObject:[device systemVersion] forKey:@"version"];
+    [devProps setObject:[self uniqueAppInstanceIdentifier:device] forKey:@"uuid"];
+    [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"];
+    [devProps setObject:@([self isVirtual]) forKey:@"isVirtual"];
+    NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
+    return devReturn;
+}
+
++ (NSString*)cordovaVersion
+{
+    return CDV_VERSION;
+}
+
+- (BOOL)isVirtual
+{
+    #if TARGET_OS_SIMULATOR
+        return true;
+    #elif TARGET_IPHONE_SIMULATOR
+        return true;
+    #else
+        return false;
+    #endif
+}
+
+@end


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message