-
Notifications
You must be signed in to change notification settings - Fork 2
/
localstorage.js
46 lines (40 loc) · 1.09 KB
/
localstorage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* eslint-disable no-underscore-dangle, no-console */
let retries = 0;
/**
* Fetches local storage data from the meteor-desktop-localstorage plugin.
* Retries 5 times, then fails.
*/
function load() {
Desktop.fetch('localStorage', 'getAll').then((storage) => {
Meteor._localStorage.storage = storage;
}).catch(() => {
retries += 1;
if (retries < 5) {
load();
} else {
console.error('failed to load localStorage contents');
}
});
}
if (Meteor.isDesktop) {
// Replace Meteor's localStorage with ours.
Meteor._localStorage = {
storage: {},
getItem(key) {
return this.storage[key];
},
setItem(key, value) {
this.storage[key] = value;
Desktop.send('localStorage', 'set', key, value);
},
clear() {
this.storage = {};
Desktop.send('localStorage', 'clear');
},
removeItem(key) {
delete this.storage[key];
Desktop.send('localStorage', 'remove', key);
}
};
load();
}