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..04f2854 --- /dev/null +++ b/src/windows/NativeStorage.js @@ -0,0 +1,145 @@ +/** + * Created by Christian on 30.08.2016. + * christian@helbighof.de + */ + +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(2); + } + }, + 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(value); + } catch (e) { + fail(1); + } + }, + clear: function (win, fail, args) { + //todo: Clear all values in NativeStorage + try { + var vault = new Windows.Security.Credentials.PasswordVault(); + var iVectorView = vault.retrieveAll(); + if (iVectorView == null) + win(); + for (var i = 0; i < iVectorView.size; i++) { + vault.remove(iVectorView[i]); + } + win(); + } catch (e) { + fail(); + } + }, + 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(value); + } catch (e) { + fail(1); + } + }, + 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(2); + } + }, + 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(1); + } + }, + 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(2); + } + }, + 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(1); + } + }, + getInt: function (win, fail, args) { + try { + var key = args[0]; + var vault = new Windows.Security.Credentials.PasswordVault(); + var passwordCredential = vault.retrieve(service, key); + win(parseInt(passwordCredential.password)); + } catch (e) { + fail(2); + } + }, + 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(1); + } + }, + 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(2); + } + }, + 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(2); + } + }, +}; + +require("cordova/exec/proxy").add("NativeStorage", NativeStorageProxy); \ No newline at end of file