Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for windows10 platform #38

Merged
merged 5 commits into from
Sep 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="example@example.com" 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.
* 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);