forked from cnwangjie/better-onetab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: send extra message and error occur & migrate
- Loading branch information
Showing
14 changed files
with
114 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import browser from 'webextension-polyfill' | ||
|
||
export const clearStorage = () => browser.storage.local.get() | ||
.then(Object.keys).then(browser.storage.local.remove) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
import _ from 'lodash' | ||
import {normalizeList} from './list' | ||
import options from './options' | ||
import {genObjectId} from './utils' | ||
import logger from './logger' | ||
import {genObjectId, compareVersion} from './utils' | ||
import listManager from './listManager' | ||
import browser from 'webextension-polyfill' | ||
listManager.init() | ||
const migrate = async () => { | ||
const {version} = await browser.storage.local.get('version') | ||
const {version: currentVersion} = browser.runtime.getManifest() | ||
if (version !== currentVersion) await browser.storage.local.set({version: currentVersion}) | ||
if (version >= '1.4.0') return | ||
// every list need an ID | ||
const {lists} = await browser.storage.local.get('lists') | ||
if (lists) { | ||
const {0: listsWithoutId, 1: listsWithId} = _.groupBy(lists.map(normalizeList), list => +!!list._id) | ||
if (listsWithId) await browser.storage.local.set({lists: listsWithId}) | ||
|
||
for (const list of listsWithoutId.reverse()) { | ||
list._id = genObjectId() | ||
await listManager.addList(list) | ||
const migrations = { | ||
'1.4.0': async () => { | ||
// every list need an ID | ||
const {lists} = await browser.storage.local.get('lists') | ||
if (lists) { | ||
const {0: listsWithoutId, 1: listsWithId} = _.groupBy(lists.map(normalizeList), list => +!!list._id) | ||
if (listsWithId) await browser.storage.local.set({lists: listsWithId}) | ||
|
||
for (const list of listsWithoutId.reverse()) { | ||
list._id = genObjectId() | ||
await listManager.addList(list) | ||
} | ||
} | ||
// remove deprecated storage keys | ||
await browser.storage.local.remove(['conflict']) | ||
} | ||
// remove depracated options | ||
const {opts} = await browser.storage.local.get('opts') | ||
if (opts) { | ||
await browser.storage.local.set({opts: _.pick(opts, _.keys(options.getDefaultOptions()))}) | ||
} | ||
|
||
const migrate = async () => { | ||
const {version: dataVersion} = await browser.storage.local.get('version') | ||
const {version: currentVersion} = browser.runtime.getManifest() | ||
if (dataVersion === currentVersion) return | ||
const sorted = Object.keys(migrations).sort(compareVersion) | ||
for (const v of sorted) { | ||
if (compareVersion(currentVersion, v) > 0) continue | ||
try { | ||
console.debug('[migrate] migrating:', v) | ||
await migrations[v]() | ||
await browser.storage.local.set({version: v}) | ||
console.debug('[migrate] migrated to:', v) | ||
} catch (err) { | ||
logger.error('[migrate] migrate failed') | ||
logger.error(err) | ||
throw err | ||
} | ||
} | ||
// remove deprecated storage keys | ||
await browser.storage.local.remove(['conflict']) | ||
} | ||
|
||
export default migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters