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

[14/25] js commit: save device UUID in a file

save device UUID in a file

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/81c951b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/81c951b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/81c951b8

Branch: refs/heads/master
Commit: 81c951b8baec4f0247b11adccca2e92bd3de80ad
Parents: 2148b3e
Author: wangmingfeng <mi...@gmail.com>
Authored: Mon Oct 29 10:24:20 2012 +0800
Committer: wangmingfeng <mi...@gmail.com>
Committed: Mon Oct 29 10:24:20 2012 +0800

----------------------------------------------------------------------
 lib/windows8/plugin/windows8/DeviceProxy.js |   46 ++++++++++++++++++++-
 1 files changed, 43 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/81c951b8/lib/windows8/plugin/windows8/DeviceProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/DeviceProxy.js b/lib/windows8/plugin/windows8/DeviceProxy.js
index 9d06c9c..88d88c9 100644
--- a/lib/windows8/plugin/windows8/DeviceProxy.js
+++ b/lib/windows8/plugin/windows8/DeviceProxy.js
@@ -20,6 +20,7 @@
 */
 
 var cordova = require('cordova');
+var utils = require('cordova/utils');
 
 
 module.exports = {
@@ -37,9 +38,48 @@ module.exports = {
                 }
             });
 
-            setTimeout(function(){
-                win({platform:"windows8", version:"8", name:name, uuid:"TODO", cordova:"2.2.0"});
-            },0);
+            // 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: "TODO", cordova: "2.2.0" });
+                                        }, 0)
+                                    } else {
+                                        deviceId = utils.createUUID();
+                                        Windows.Storage.FileIO.writeTextAsync(storageFile, deviceId, Windows.Storage.Streams.UnicodeEncoding.utf8).done(
+                                            function () {
+                                                setTimeout(function () {
+                                                    win({ platform: "windows8", version: "8", name: name, uuid: "TODO", cordova: "2.2.0" });
+                                                }, 0)
+                                            }, function () {
+                                                fail(FileError.INVALID_MODIFICATION_ERR);
+                                            }
+
+                                        );
+                                    }
+                                },
+                                function () {
+                                    fail(FileError.ENCODING_ERR);
+                                }
+                            );
+                        }, function () {
+                            fail(FileError.NOT_FOUND_ERR);
+                        }
+                    );
+                
+            }, fail && fail());
         }
 };