You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/11/06 01:38:28 UTC

[3/25] js commit: various W8 tweaks.

various W8 tweaks.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/58aa9b9d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/58aa9b9d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/58aa9b9d

Branch: refs/heads/master
Commit: 58aa9b9dc1425047e8a4905c8857acaaddf9d0bc
Parents: 0919268
Author: purplecabbage <pu...@gmail.com>
Authored: Mon Nov 5 15:29:44 2012 -0800
Committer: purplecabbage <pu...@gmail.com>
Committed: Mon Nov 5 15:29:44 2012 -0800

----------------------------------------------------------------------
 lib/windows8/platform.js                      |    6 ++
 lib/windows8/plugin/windows8/CaptureProxy.js  |    2 +-
 lib/windows8/plugin/windows8/ContactsProxy.js |   48 +++++++++++++
 lib/windows8/plugin/windows8/DeviceProxy.js   |   74 ++++++++++++++-----
 lib/windows8/plugin/windows8/FileProxy.js     |    4 +-
 lib/windows8/plugin/windows8/MediaProxy.js    |    7 ++-
 6 files changed, 116 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/58aa9b9d/lib/windows8/platform.js
----------------------------------------------------------------------
diff --git a/lib/windows8/platform.js b/lib/windows8/platform.js
index cc107b9..5742dc4 100755
--- a/lib/windows8/platform.js
+++ b/lib/windows8/platform.js
@@ -33,6 +33,7 @@ require('cordova/plugin/windows8/AccelerometerProxy');
 require('cordova/plugin/windows8/CameraProxy');
 require('cordova/plugin/windows8/CaptureProxy');
 require('cordova/plugin/windows8/CompassProxy');
+require('cordova/plugin/windows8/ContactsProxy');
 require('cordova/plugin/windows8/FileProxy');
 
 require('cordova/plugin/windows8/FileTransferProxy');
@@ -40,6 +41,7 @@ require('cordova/plugin/windows8/MediaProxy');
 require('cordova/plugin/windows8/NotificationProxy');
 
 
+
 module.exports = {
     id: "windows8",
     initialize:function() {
@@ -57,6 +59,7 @@ module.exports = {
             app.addEventListener("checkpoint", checkpointHandler);
             Windows.UI.WebUI.WebUIApplication.addEventListener("resuming", resumingHandler, false);
             app.start();
+
         };
 
         if (!window.WinJS) {
@@ -106,6 +109,9 @@ module.exports = {
         },
         File: {
             path: 'cordova/plugin/File'
+        },
+        MediaError: {
+            path: 'cordova/plugin/MediaError'
         }
     },
     merges: {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/58aa9b9d/lib/windows8/plugin/windows8/CaptureProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/CaptureProxy.js b/lib/windows8/plugin/windows8/CaptureProxy.js
index 6e5f3f0..1e76ddb 100644
--- a/lib/windows8/plugin/windows8/CaptureProxy.js
+++ b/lib/windows8/plugin/windows8/CaptureProxy.js
@@ -128,7 +128,7 @@ module.exports = {
     getFormatData: function (successCallback, errorCallback, args) {
         Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
             function (storageFile) {
-                var mediaTypeFlag = String(args[1]).split("/")[0].toLowerCase();
+                var mediaTypeFlag = String(storageFile.contentType).split("/")[0].toLowerCase();
                 if (mediaTypeFlag === "audio") {
                     storageFile.properties.getMusicPropertiesAsync().then(function (audioProperties) {
                         successCallback(new MediaFileData(null, audioProperties.bitrate, 0, 0, audioProperties.duration / 1000));

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/58aa9b9d/lib/windows8/plugin/windows8/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/ContactsProxy.js b/lib/windows8/plugin/windows8/ContactsProxy.js
new file mode 100644
index 0000000..629dbca
--- /dev/null
+++ b/lib/windows8/plugin/windows8/ContactsProxy.js
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+var cordova = require('cordova');
+
+module.exports = {
+    search: function (win, fail, args) {
+        var fields = args[0];
+        var options = args[1];
+        var picker = Windows.ApplicationModel.Contacts.ContactPicker();
+        picker.commitButtonText = "Select";
+        picker.selectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.contacts;
+
+        picker.desiredFields.push.apply(picker.desiredFields, fields);
+
+        if (options.multiple) {
+            picker.pickMultipleContactsAsync().then(function (contacts) {
+                win(contacts);
+            });
+        }
+        else {
+            picker.pickSingleContactAsync().then(function (contact) {
+                win([contact]);
+            });
+        }
+    }
+
+};
+
+require("cordova/commandProxy").add("Contacts",module.exports);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/58aa9b9d/lib/windows8/plugin/windows8/DeviceProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/DeviceProxy.js b/lib/windows8/plugin/windows8/DeviceProxy.js
index 8d5f0b2..305cc33 100644
--- a/lib/windows8/plugin/windows8/DeviceProxy.js
+++ b/lib/windows8/plugin/windows8/DeviceProxy.js
@@ -21,29 +21,63 @@
 
 var cordova = require('cordova');
 var utils = require('cordova/utils');
+var FileError = require('cordova/plugin/FileError');
+
 
 module.exports = {
 
-    getDeviceInfo:function(win,fail,args){
-        console.log("NativeProxy::getDeviceInfo");
-
-        // get the name ( hostName of the machine )
-        var hostNames = Windows.Networking.Connectivity.NetworkInformation.getHostNames();
-        var name = "unknown";
-        hostNames.some(function (nm) {
-            if (nm.displayName.indexOf(".local") > -1) {
-                name = nm.displayName.split(".local")[0];
-                return true;
-            }
-        });
-
-        // deviceId aka uuid
-        var deviceId = localStorage.deviceId;
-        if(!deviceId) {
-            deviceId = utils.createUUID();
-            console.log(deviceId);
-            localStorage.deviceId = deviceId;
-        }
+        getDeviceInfo:function(win,fail,args){
+            //console.log("NativeProxy::getDeviceInfo");
+
+            var hostNames = Windows.Networking.Connectivity.NetworkInformation.getHostNames();
+
+            var name = "unknown";
+            hostNames.some(function (nm) {
+                if (nm.displayName.indexOf(".local") > -1) {
+                    name = nm.displayName.split(".local")[0];
+                    return true;
+                }
+            });
+
+            // deviceId aka uuid
+
+            var deviceId = "";
+            Windows.System.UserProfile.UserInformation.getFirstNameAsync().then(function (fileName) {
+                var path = "C:\\Users\\" + fileName + "\\Documents";
+                Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(function (storageFolder) {
+                    return storageFolder.createFileAsync("appDeviceIdentifier.txt", Windows.Storage.CreationCollisionOption.openIfExists);
+                }).then(function (storageFile) {
+                    var value = Windows.Storage.Streams.UnicodeEncoding.utf8;
+                    Windows.Storage.FileIO.readTextAsync(storageFile, value).then(function (fileContent) {
+                        if (fileContent) {
+                            deviceId = fileContent;
+                            setTimeout(function () {
+                                win({ platform: "windows8", version: "8", name: name, uuid: deviceId, cordova: "2.2.0" });
+                            }, 0);
+                        } else {
+                            deviceId = utils.createUUID();
+                            var fileIO = Windows.Storage.FileIO;
+                            fileIO.writeTextAsync(storageFile, deviceId, Windows.Storage.Streams.UnicodeEncoding.utf8).done(
+                                function () {
+                                    setTimeout(function () {
+                                        win({ platform: "windows8", version: "8", name: name, uuid: deviceId, cordova: "2.2.0" });
+                                    }, 0);
+                                },
+                                function () {
+                                    fail(FileError.INVALID_MODIFICATION_ERR);
+                                }
+                            );
+                        }
+                    },
+                    function () {
+                        fail(FileError.ENCODING_ERR);
+                    });
+                }, function () {
+                    fail(FileError.NOT_FOUND_ERR);
+                });
+
+            },
+            fail && fail());
 
         setTimeout(function(){
             win({platform:"windows8", version:"8", name:name, uuid:deviceId, cordova:"2.2.0"});

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/58aa9b9d/lib/windows8/plugin/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/FileProxy.js b/lib/windows8/plugin/windows8/FileProxy.js
index 2e6f50c..fba3b83 100644
--- a/lib/windows8/plugin/windows8/FileProxy.js
+++ b/lib/windows8/plugin/windows8/FileProxy.js
@@ -286,7 +286,7 @@ module.exports = {
                                         fail && fail(FileError.INVALID_MODIFICATION_ERR);
                                     }
                                 }
-                                
+
                             });
                         };
                         removeEntry();
@@ -317,7 +317,7 @@ module.exports = {
                 Windows.Storage.StorageFolder.getFolderFromPathAsync(path).then(
                     function (storageFolder) {
                         var fileListPromise = storageFolder.createFileQuery().getFilesAsync();
-                        
+
                         storageFolderTop = storageFolder;
                         return fileListPromise;
                     }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/58aa9b9d/lib/windows8/plugin/windows8/MediaProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/MediaProxy.js b/lib/windows8/plugin/windows8/MediaProxy.js
index 2f03382..5b8e7ef 100644
--- a/lib/windows8/plugin/windows8/MediaProxy.js
+++ b/lib/windows8/plugin/windows8/MediaProxy.js
@@ -24,6 +24,8 @@
 var cordova = require('cordova'),
     Media = require('cordova/plugin/Media');
 
+var MediaError = require('cordova/plugin/MediaError');
+
 module.exports = {
     mediaCaptureMrg:null,
 
@@ -48,8 +50,9 @@ module.exports = {
                     dur = -1;
                 }
                 Media.onStatus(id, Media.MEDIA_DURATION, dur);
-            } else {
-                lose("Invalid file type");
+            }
+            else {
+                lose && lose({code:MediaError.MEDIA_ERR_ABORTED});
             }
         }
     },