Skip to content

Commit

Permalink
Merge pull request #38 from 3h3c/master
Browse files Browse the repository at this point in the history
add support for windows10 platform
  • Loading branch information
GillesC authored Sep 5, 2016
2 parents 1a0b96b + c8cdb4d commit d87aed2
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
examples/
.idea/
node_modules/
npm-debug.log
3 changes: 3 additions & 0 deletions examples/demo/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<description>
A demo application for the NativeStorage plugin
</description>
<author email="[email protected]" href="http://example.com/">
Example Company
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
Expand Down
19 changes: 13 additions & 6 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@

<!-- Browser -->
<platform name="browser">
<config-file target="config.xml" parent="/*">
<feature name="NativeStorage">
<param name="browser-package" value="NativeStorage" />
</feature>
</config-file>
</platform>
<config-file target="config.xml" parent="/*">
<feature name="NativeStorage">
<param name="browser-package" value="NativeStorage" />
</feature>
</config-file>
</platform>

<!-- windows -->
<platform name="windows">
<js-module src="src/windows/NativeStorage.js" name="NativeStorage">
<runs />
</js-module>
</platform>


</plugin>
145 changes: 145 additions & 0 deletions src/windows/NativeStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* Created by Christian on 30.08.2016.
* [email protected]
*/

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);

0 comments on commit d87aed2

Please sign in to comment.