Skip to content

Commit d87aed2

Browse files
authored
Merge pull request #38 from 3h3c/master
add support for windows10 platform
2 parents 1a0b96b + c8cdb4d commit d87aed2

File tree

4 files changed

+163
-6
lines changed

4 files changed

+163
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
examples/
2+
.idea/
13
node_modules/
24
npm-debug.log

examples/demo/config.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<description>
55
A demo application for the NativeStorage plugin
66
</description>
7+
<author email="[email protected]" href="http://example.com/">
8+
Example Company
9+
</author>
710
<content src="index.html" />
811
<plugin name="cordova-plugin-whitelist" spec="1" />
912
<access origin="*" />

plugin.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@
4343

4444
<!-- Browser -->
4545
<platform name="browser">
46-
<config-file target="config.xml" parent="/*">
47-
<feature name="NativeStorage">
48-
<param name="browser-package" value="NativeStorage" />
49-
</feature>
50-
</config-file>
51-
</platform>
46+
<config-file target="config.xml" parent="/*">
47+
<feature name="NativeStorage">
48+
<param name="browser-package" value="NativeStorage" />
49+
</feature>
50+
</config-file>
51+
</platform>
52+
53+
<!-- windows -->
54+
<platform name="windows">
55+
<js-module src="src/windows/NativeStorage.js" name="NativeStorage">
56+
<runs />
57+
</js-module>
58+
</platform>
5259

5360

5461
</plugin>

src/windows/NativeStorage.js

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/**
2+
* Created by Christian on 30.08.2016.
3+
4+
*/
5+
6+
var package = Windows.ApplicationModel.Package.current;
7+
var service = package.id.name
8+
9+
var NativeStorageProxy = {
10+
getItem: function (win, fail, args) {
11+
try {
12+
var key = args[0];
13+
var vault = new Windows.Security.Credentials.PasswordVault();
14+
var passwordCredential = vault.retrieve(service, key);
15+
win(passwordCredential.password);
16+
} catch (e) {
17+
fail(2);
18+
}
19+
},
20+
setItem: function (win, fail, args) {
21+
try {
22+
var key = args[0];
23+
var value = args[1];
24+
var vault = new Windows.Security.Credentials.PasswordVault();
25+
vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value));
26+
win(value);
27+
} catch (e) {
28+
fail(1);
29+
}
30+
},
31+
clear: function (win, fail, args) {
32+
//todo: Clear all values in NativeStorage
33+
try {
34+
var vault = new Windows.Security.Credentials.PasswordVault();
35+
var iVectorView = vault.retrieveAll();
36+
if (iVectorView == null)
37+
win();
38+
for (var i = 0; i < iVectorView.size; i++) {
39+
vault.remove(iVectorView[i]);
40+
}
41+
win();
42+
} catch (e) {
43+
fail();
44+
}
45+
},
46+
putString: function (win, fail, args) {
47+
try {
48+
var key = args[0];
49+
var value = args[1];
50+
var vault = new Windows.Security.Credentials.PasswordVault();
51+
vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value));
52+
win(value);
53+
} catch (e) {
54+
fail(1);
55+
}
56+
},
57+
getString: function (win, fail, args) {
58+
try {
59+
var key = args[0];
60+
var vault = new Windows.Security.Credentials.PasswordVault();
61+
var passwordCredential = vault.retrieve(service, key);
62+
win(passwordCredential.password);
63+
} catch (e) {
64+
fail(2);
65+
}
66+
},
67+
putBoolean: function (win, fail, args) {
68+
try {
69+
var key = args[0];
70+
var value = args[1];
71+
var vault = new Windows.Security.Credentials.PasswordVault();
72+
vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value));
73+
win(value);
74+
} catch (e) {
75+
fail(1);
76+
}
77+
},
78+
getBoolean: function (win, fail, args) {
79+
try {
80+
var key = args[0];
81+
var vault = new Windows.Security.Credentials.PasswordVault();
82+
var passwordCredential = vault.retrieve(service, key);
83+
win(passwordCredential.password);
84+
} catch (e) {
85+
fail(2);
86+
}
87+
},
88+
putInt: function (win, fail, args) {
89+
try {
90+
var key = args[0];
91+
var value = args[1];
92+
var vault = new Windows.Security.Credentials.PasswordVault();
93+
vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value));
94+
win(value);
95+
} catch (e) {
96+
fail(1);
97+
}
98+
},
99+
getInt: function (win, fail, args) {
100+
try {
101+
var key = args[0];
102+
var vault = new Windows.Security.Credentials.PasswordVault();
103+
var passwordCredential = vault.retrieve(service, key);
104+
win(parseInt(passwordCredential.password));
105+
} catch (e) {
106+
fail(2);
107+
}
108+
},
109+
putDouble: function (win, fail, args) {
110+
try {
111+
var key = args[0];
112+
var value = args[1];
113+
var vault = new Windows.Security.Credentials.PasswordVault();
114+
vault.add(new Windows.Security.Credentials.PasswordCredential(service, key, value));
115+
win(value);
116+
} catch (e) {
117+
fail(1);
118+
}
119+
},
120+
getDouble: function (win, fail, args) {
121+
try {
122+
var key = args[0];
123+
var vault = new Windows.Security.Credentials.PasswordVault();
124+
var passwordCredential = vault.retrieve(service, key);
125+
win(passwordCredential.password);
126+
} catch (e) {
127+
fail(2);
128+
}
129+
},
130+
remove: function (win, fail, args) {
131+
try {
132+
var key = args[0];
133+
var vault = new Windows.Security.Credentials.PasswordVault();
134+
var passwordCredential = vault.retrieve(service, key);
135+
if (passwordCredential) {
136+
vault.remove(passwordCredential);
137+
}
138+
win(key);
139+
} catch (e) {
140+
fail(2);
141+
}
142+
},
143+
};
144+
145+
require("cordova/exec/proxy").add("NativeStorage", NativeStorageProxy);

0 commit comments

Comments
 (0)