Skip to content

Commit 09bec52

Browse files
author
sakuraash
committed
fix plugin config persist bug
1 parent 1b0ae77 commit 09bec52

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

app/initialize/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ async function initialize () {
8484
return true
8585
})
8686

87-
await step(`[${stepNum++}] Persist Store.`, () => {
88-
persistTask()
87+
await step(`[${stepNum++}] Persist Store.`, async () => {
88+
await persistTask()
89+
8990
return true
9091
})
9192

app/persist.js

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,44 @@ const mainStore = localforage.createInstance({
1717
// the delay to set
1818

1919
function persistStore (store, transform) {
20-
autorunAsync(() => {
21-
const customTransform = transform || createTransformer(store => mobxToJS(store))
22-
const transformedPluginStore = mobxToJS(pluginSettingStore)
23-
const transformedStore = customTransform(store)
24-
// 初次等spacekey出现存
25-
if (config.spaceKey && !mainStore._config.storeName) {
26-
mainStore.config({ storeName: config.spaceKey })
27-
} else if (mainStore._config.storeName && (config.globalKey || !config.isPlatform)) {
28-
if (config.hasRehydrated) {
29-
mainStore.setItem(`${config.spaceKey}.${config.globalKey}`, transformedStore)
30-
mainStore.setItem(`${config.spaceKey}.${config.globalKey}.plugins`, transformedPluginStore)
31-
} else {
32-
mainStore.getItem(`${config.spaceKey}.${config.globalKey}`).then((store) => {
33-
if (store) {
34-
autoRehydrate(store)
35-
} else {
36-
dispatchCommand('global:show_env')
37-
dispatchCommand('file:open_welcome')
38-
}
39-
fileState.initData.set('_init', false)
40-
config.hasRehydrated = true
41-
})
42-
mainStore.getItem(`${config.spaceKey}.${config.globalKey}.plugins`).then((plugins) => {
43-
for (const plugin in plugins) {
44-
pluginSettingStore[plugin] = observable(plugins[plugin])
45-
}
46-
if (!config.hasRehydrated) {
47-
config.hasRehydrated = true
48-
}
49-
})
20+
return new Promise((resolve, reject) => {
21+
autorunAsync(() => {
22+
const customTransform = transform || createTransformer(store => mobxToJS(store))
23+
const transformedPluginStore = mobxToJS(pluginSettingStore)
24+
const transformedStore = customTransform(store)
25+
// 初次等spacekey出现存
26+
if (config.spaceKey && !mainStore._config.storeName) {
27+
mainStore.config({ storeName: config.spaceKey })
28+
} else if (mainStore._config.storeName && (config.globalKey || !config.isPlatform)) {
29+
if (config.hasRehydrated) {
30+
mainStore.setItem(`${config.spaceKey}.${config.globalKey}`, transformedStore)
31+
mainStore.setItem(`${config.spaceKey}.${config.globalKey}.plugins`, transformedPluginStore)
32+
} else {
33+
const tasks = [
34+
mainStore.getItem(`${config.spaceKey}.${config.globalKey}`),
35+
mainStore.getItem(`${config.spaceKey}.${config.globalKey}.plugins`)
36+
]
37+
Promise.all(tasks)
38+
.then(([store, pluginsStore]) => {
39+
if (store) {
40+
autoRehydrate(store)
41+
} else {
42+
dispatchCommand('global:show_env')
43+
dispatchCommand('file:open_welcome')
44+
}
45+
fileState.initData.set('_init', false)
46+
47+
for (const plugin in pluginsStore) {
48+
pluginSettingStore[plugin] = observable(pluginsStore[plugin])
49+
}
50+
51+
config.hasRehydrated = true
52+
resolve(true)
53+
})
54+
}
5055
}
51-
}
52-
}, 200)
56+
}, 200)
57+
})
5358
}
5459

5560
export const clearPersist = (key) => {

0 commit comments

Comments
 (0)