Skip to content

Commit 7b4b2c3

Browse files
committed
fix: duplicate tabs failed & cannot set options in FF
1 parent 9f90941 commit 7b4b2c3

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

src/background.js

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import storage from './common/storage'
66
import options from './common/options'
77
import migrate from './common/migrate'
88
import boss from './common/service/boss'
9+
import {normalizeList} from './common/list'
910
import listManager from './common/listManager'
1011
import browser from 'webextension-polyfill'
1112
import {sendMessage} from './common/utils'
@@ -213,6 +214,14 @@ const commandHandler = command => {
213214
if (PRODUCTION) ga('send', 'event', 'Command used', command)
214215
}
215216

217+
const fixDirtyData = async () => {
218+
const {lists} = await browser.storage.local.get('lists')
219+
if (lists) {
220+
const cleanLists = lists.filter(_.isPlainObject).map(normalizeList)
221+
await browser.storage.local.set({lists: cleanLists})
222+
}
223+
}
224+
216225
const init = async () => {
217226
logger.init()
218227
await listManager.init()
@@ -305,6 +314,7 @@ const init = async () => {
305314
}
306315
})
307316
await migrate()
317+
await fixDirtyData()
308318
await boss.init()
309319
}
310320

src/common/listManager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ const compressOps = ops => {
7171
console.debug('[listManager] compress ops: (after)', finalOps)
7272
return finalOps
7373
}
74-
const saveStorage = _.debounce(async () => {
74+
const saveStorage = _.throttle(async () => {
7575
cache.ops = compressOps(cache.ops)
7676
await browser.storage.local.set(cache)
7777
cache.lists = cache.ops = null
7878
await sendMessage({refresh: true})
79-
}, 5000)
79+
}, 1000)
8080
const manager = {}
8181
// lists modifier (return true if need to add ops)
8282
manager.modifiers = {

src/common/tabs.js

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const storeTabs = async (tabs, listIndex) => {
6969
if (listIndex == null) {
7070
const newList = createNewTabList({tabs})
7171
if (opts.pinNewList) newList.pinned = true
72-
lists.unshift(newList)
7372
await listManager.addList(newList)
7473
} else {
7574
const list = lists[listIndex]

src/page/main/DetailList.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ export default {
525525
const changedLists = []
526526
items.forEach(({listIndex, tabIndex}) => {
527527
changedLists.push(listIndex)
528-
this.addTab([listIndex, tabIndex, this.lists[listIndex].tabs[tabIndex]])
528+
this.addTab([listIndex, this.lists[listIndex].tabs[tabIndex]])
529529
})
530530
this.tabMoved(changedLists)
531531
},

src/page/main/Options.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ export default {
128128
console.log(1)
129129
console.log(key, value)
130130
// when type of option is string options can not be set correctly after first storage.setOptions() called
131-
await storage.setOptions(this.opts) // eslint-disable-line
132-
await storage.setOptions(this.opts) // eslint-disable-line
131+
const opts = _.clone(this.opts) // eslint-disable-line
132+
await storage.setOptions(opts)
133+
await storage.setOptions(opts)
133134
console.log(2)
134135
await sendMessage({optionsChanged: {[key]: value}})
135136
}, 100),

webpack.config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const opts = module.exports = {
2121
content: './src/content.js',
2222
exchanger: './src/exchanger.js',
2323
},
24+
devtool: 'source-map',
2425
output: {
2526
path: resolve('dist'),
2627
filename : '[name].js',
@@ -67,6 +68,7 @@ const opts = module.exports = {
6768
name: true,
6869
minChunks: Infinity,
6970
},
71+
minimizer: [],
7072
},
7173
resolve: {
7274
extensions: ['.js', '.vue', '.json'],
@@ -132,12 +134,10 @@ const opts = module.exports = {
132134
}
133135

134136
if (opts.mode === 'production') {
135-
opts.plugins.push(new UglifyJsPlugin({
137+
opts.optimization.minimizer.push(new UglifyJsPlugin({
136138
uglifyOptions: {
137-
parallel: 4,
138-
compress: {
139-
drop_console: true,
140-
}
139+
parallel: true,
140+
cache: true,
141141
}
142142
}))
143143
}

0 commit comments

Comments
 (0)