-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
migration.js
44 lines (41 loc) · 1.16 KB
/
migration.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
/* global browser */
const defaultPreference = {
version: 5,
mode: 'day',
list: [{
content: '',
time: (new Date()).getTime()
}],
showcredits: true,
darktoggleonnotes: true
}
; (() => {
window.migration = async (results, syncResult) => {
if (results.version === 2) {
results.list = [{
content: results.content || ''
}]
results.version = defaultPreference.version
delete results.content
await browser.storage.local.set(results)
browser.storage.local.remove('content')
}
if (results.version === 3) {
results.list = results.list.map(note => {
return {
...note,
time: (new Date()).getTime()
}
})
results.version = defaultPreference.version
await browser.storage.local.set(results)
}
if (syncResult.version === 4 && results.version !== 5) {
// migrate from storage.sync to storage.local
results.list = syncResult.list,
results.mode = syncResult.mode,
results.version = defaultPreference.version
await browser.storage.local.set(results)
}
}
})()