From 5d933194f8aac95605ec269b3ae4b010c582e9b2 Mon Sep 17 00:00:00 2001 From: Christian Helbig Date: Thu, 1 Sep 2016 15:07:47 +0200 Subject: [PATCH 1/5] add Support for windows10 --- .gitignore | 2 + examples/demo/config.xml | 3 + plugin.xml | 19 +++-- src/windows/NativeStorage.js | 138 +++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 src/windows/NativeStorage.js diff --git a/.gitignore b/.gitignore index 9303c34..07d0608 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +examples/ +.idea/ node_modules/ npm-debug.log \ No newline at end of file diff --git a/examples/demo/config.xml b/examples/demo/config.xml index f4cac7d..5d18167 100644 --- a/examples/demo/config.xml +++ b/examples/demo/config.xml @@ -4,6 +4,9 @@ A demo application for the NativeStorage plugin + + Example Company + diff --git a/plugin.xml b/plugin.xml index 9359a43..57c4af9 100644 --- a/plugin.xml +++ b/plugin.xml @@ -43,12 +43,19 @@ - - - - - - + + + + + + + + + + + + + diff --git a/src/windows/NativeStorage.js b/src/windows/NativeStorage.js new file mode 100644 index 0000000..da9d455 --- /dev/null +++ b/src/windows/NativeStorage.js @@ -0,0 +1,138 @@ +/** + * Created by Christian on 30.08.2016. + */ + +var package = Windows.ApplicationModel.Package.current; +var service = package.id.name + +var NativeStorageProxy = { + getItem: function (win, fail, args) { + try { + var key = args[0]; + var vault = new Windows.Security.Credentials.PasswordVault(); + var passwordCredential = vault.retrieve(service, key); + win(passwordCredential.password); + } catch (e) { + fail('failed to get Item from NativeStorage - ' + e.message); + } + }, + setItem: function (win, fail, args) { + try { + var key = args[0]; + var value = args[1]; + var vault = new Windows.Security.Credentials.PasswordVault(); + vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); + win(key); + } catch (e) { + fail('failed to set Item in NativeStorage - ' + e.message); + } + }, + clear: function (win, fail, args) { + try { + var service = packageId.name; + var vault = new Windows.Security.Credentials.PasswordVault(); + var iVectorView = passwordVault.retrieveAll(); + } catch (e) { + fail('Failed to clear Storage variable - ' + e.message); + } + }, + putString: function (win, fail, args) { + try { + var key = args[0]; + var value = args[1]; + var vault = new Windows.Security.Credentials.PasswordVault(); + vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); + win(key); + } catch (e) { + fail('failed to put String in NativeStorage - ' + e.message); + } + }, + getString: function (win, fail, args) { + try { + var key = args[0]; + var vault = new Windows.Security.Credentials.PasswordVault(); + var passwordCredential = vault.retrieve(service, key); + win(passwordCredential.password); + } catch (e) { + fail('failed to get String from NativeStorage - ' + e.message); + } + }, + putBoolean: function (win, fail, args) { + try { + var key = args[0]; + var value = args[1]; + var vault = new Windows.Security.Credentials.PasswordVault(); + vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); + win(value); + } catch (e) { + fail('failed to put Boolean in NativeStorage - ' + e.message); + } + }, + getBoolean: function (win, fail, args) { + try { + var key = args[0]; + var vault = new Windows.Security.Credentials.PasswordVault(); + var passwordCredential = vault.retrieve(service, key); + win(passwordCredential.password); + } catch (e) { + fail('failed to get Boolen from NativeStorage - ' + e.message); + } + }, + putInt: function (win, fail, args) { + try { + var key = args[0]; + var value = args[1]; + var vault = new Windows.Security.Credentials.PasswordVault(); + vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); + win(value); + } catch (e) { + fail('failed to set Int in NativeStorage - ' + e.message); + } + }, + getInt: function (win, fail, args) { + try { + var key = args[0]; + var vault = new Windows.Security.Credentials.PasswordVault(); + var passwordCredential = vault.retrieve(service, key); + win(passwordCredential.password); + } catch (e) { + fail('failed to get Int from NativeStorage - ' + e.message); + } + }, + putDouble: function (win, fail, args) { + try { + var key = args[0]; + var value = args[1]; + var vault = new Windows.Security.Credentials.PasswordVault(); + vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); + win(value); + } catch (e) { + fail('failed to set Double in NativeStorage - ' + e.message); + } + }, + getDouble: function (win, fail, args) { + try { + var key = args[0]; + var vault = new Windows.Security.Credentials.PasswordVault(); + var passwordCredential = vault.retrieve(service, key); + win(passwordCredential.password); + } catch (e) { + fail('failed to get Double from NativeStorage - ' + e.message); + } + }, + remove: function (win, fail, args) { + try { + var key = args[0]; + var vault = new Windows.Security.Credentials.PasswordVault(); + var passwordCredential = vault.retrieve(service, key); + if (passwordCredential) { + vault.remove(passwordCredential); + } + win(key); + } catch (e) { + fail('failed to remove from NativeStorage - ' + e.message); + } + }, +}; + +require("cordova/exec/proxy").add("NativeStorage", NativeStorageProxy); \ No newline at end of file From bb65d9aca3dfca4c924c16b327f4a53c8a6103c9 Mon Sep 17 00:00:00 2001 From: Christian Helbig Date: Thu, 1 Sep 2016 15:10:14 +0200 Subject: [PATCH 2/5] add Support for windows10 --- src/windows/NativeStorage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/windows/NativeStorage.js b/src/windows/NativeStorage.js index da9d455..04efab1 100644 --- a/src/windows/NativeStorage.js +++ b/src/windows/NativeStorage.js @@ -1,5 +1,6 @@ /** * Created by Christian on 30.08.2016. + * christian@helbighof.de */ var package = Windows.ApplicationModel.Package.current; From 8d2b3ffe18cb7670529882cee19f2c6ed38a1651 Mon Sep 17 00:00:00 2001 From: Christian Helbig Date: Thu, 1 Sep 2016 16:38:48 +0200 Subject: [PATCH 3/5] returning value in successcallback instead of key --- src/windows/NativeStorage.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/windows/NativeStorage.js b/src/windows/NativeStorage.js index 04efab1..922a0e7 100644 --- a/src/windows/NativeStorage.js +++ b/src/windows/NativeStorage.js @@ -23,12 +23,13 @@ var NativeStorageProxy = { var value = args[1]; var vault = new Windows.Security.Credentials.PasswordVault(); vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); - win(key); + win(value); } catch (e) { fail('failed to set Item in NativeStorage - ' + e.message); } }, clear: function (win, fail, args) { + //todo: Clear all values in NativeStorage try { var service = packageId.name; var vault = new Windows.Security.Credentials.PasswordVault(); @@ -43,7 +44,7 @@ var NativeStorageProxy = { var value = args[1]; var vault = new Windows.Security.Credentials.PasswordVault(); vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); - win(key); + win(value); } catch (e) { fail('failed to put String in NativeStorage - ' + e.message); } From 83f2993fa0c105a01e1e54e6b0bd1590da84081b Mon Sep 17 00:00:00 2001 From: Christian Helbig Date: Mon, 5 Sep 2016 14:12:33 +0200 Subject: [PATCH 4/5] getInt returns now Integer --- src/windows/NativeStorage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/NativeStorage.js b/src/windows/NativeStorage.js index 922a0e7..506bbe8 100644 --- a/src/windows/NativeStorage.js +++ b/src/windows/NativeStorage.js @@ -95,7 +95,7 @@ var NativeStorageProxy = { try { var key = args[0]; var vault = new Windows.Security.Credentials.PasswordVault(); - var passwordCredential = vault.retrieve(service, key); + var passwordCredential = parseInt(vault.retrieve(service, key)); win(passwordCredential.password); } catch (e) { fail('failed to get Int from NativeStorage - ' + e.message); From c8cdb4d39770f63ad727d40327c76637df56c42f Mon Sep 17 00:00:00 2001 From: Christian Helbig Date: Mon, 5 Sep 2016 15:57:43 +0200 Subject: [PATCH 5/5] return right failure code tests from tests/main.js passed in my run --- src/windows/NativeStorage.js | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/windows/NativeStorage.js b/src/windows/NativeStorage.js index 506bbe8..04f2854 100644 --- a/src/windows/NativeStorage.js +++ b/src/windows/NativeStorage.js @@ -14,7 +14,7 @@ var NativeStorageProxy = { var passwordCredential = vault.retrieve(service, key); win(passwordCredential.password); } catch (e) { - fail('failed to get Item from NativeStorage - ' + e.message); + fail(2); } }, setItem: function (win, fail, args) { @@ -25,17 +25,22 @@ var NativeStorageProxy = { vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); win(value); } catch (e) { - fail('failed to set Item in NativeStorage - ' + e.message); + fail(1); } }, clear: function (win, fail, args) { //todo: Clear all values in NativeStorage try { - var service = packageId.name; var vault = new Windows.Security.Credentials.PasswordVault(); - var iVectorView = passwordVault.retrieveAll(); + var iVectorView = vault.retrieveAll(); + if (iVectorView == null) + win(); + for (var i = 0; i < iVectorView.size; i++) { + vault.remove(iVectorView[i]); + } + win(); } catch (e) { - fail('Failed to clear Storage variable - ' + e.message); + fail(); } }, putString: function (win, fail, args) { @@ -46,7 +51,7 @@ var NativeStorageProxy = { vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); win(value); } catch (e) { - fail('failed to put String in NativeStorage - ' + e.message); + fail(1); } }, getString: function (win, fail, args) { @@ -56,7 +61,7 @@ var NativeStorageProxy = { var passwordCredential = vault.retrieve(service, key); win(passwordCredential.password); } catch (e) { - fail('failed to get String from NativeStorage - ' + e.message); + fail(2); } }, putBoolean: function (win, fail, args) { @@ -67,7 +72,7 @@ var NativeStorageProxy = { vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); win(value); } catch (e) { - fail('failed to put Boolean in NativeStorage - ' + e.message); + fail(1); } }, getBoolean: function (win, fail, args) { @@ -77,7 +82,7 @@ var NativeStorageProxy = { var passwordCredential = vault.retrieve(service, key); win(passwordCredential.password); } catch (e) { - fail('failed to get Boolen from NativeStorage - ' + e.message); + fail(2); } }, putInt: function (win, fail, args) { @@ -88,17 +93,17 @@ var NativeStorageProxy = { vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); win(value); } catch (e) { - fail('failed to set Int in NativeStorage - ' + e.message); + fail(1); } }, getInt: function (win, fail, args) { try { var key = args[0]; var vault = new Windows.Security.Credentials.PasswordVault(); - var passwordCredential = parseInt(vault.retrieve(service, key)); - win(passwordCredential.password); + var passwordCredential = vault.retrieve(service, key); + win(parseInt(passwordCredential.password)); } catch (e) { - fail('failed to get Int from NativeStorage - ' + e.message); + fail(2); } }, putDouble: function (win, fail, args) { @@ -109,7 +114,7 @@ var NativeStorageProxy = { vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value)); win(value); } catch (e) { - fail('failed to set Double in NativeStorage - ' + e.message); + fail(1); } }, getDouble: function (win, fail, args) { @@ -119,7 +124,7 @@ var NativeStorageProxy = { var passwordCredential = vault.retrieve(service, key); win(passwordCredential.password); } catch (e) { - fail('failed to get Double from NativeStorage - ' + e.message); + fail(2); } }, remove: function (win, fail, args) { @@ -132,7 +137,7 @@ var NativeStorageProxy = { } win(key); } catch (e) { - fail('failed to remove from NativeStorage - ' + e.message); + fail(2); } }, };