Skip to content

Commit

Permalink
fix save data initialization
Browse files Browse the repository at this point in the history
resolves Tarnadas#123
  • Loading branch information
Tarnadas committed Apr 14, 2020
1 parent b610e6c commit d6108e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "net64plus",
"version": "2.5.0",
"version": "2.5.1",
"compatVersion": "1.0.0",
"description": "Net64+ client",
"main": "index.js",
Expand Down
44 changes: 26 additions & 18 deletions src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ export let gamepadManager: GamepadManager
;(async () => {
const history: History = createHistory()
const save: SaveState = await loadSaveData()
connector.changeEmuChat(save.appSaveData.emuChat)
store = initReducer(history, save)

const saveState = store.getState().save
connector.changeEmuChat(saveState.appSaveData.emuChat)
connector.changeHotkeyBindings({
hotkeyBindings: save.appSaveData.hotkeyBindings || {},
globalHotkeysEnabled: !!save.appSaveData.globalHotkeysEnabled,
username: save.appSaveData.username
hotkeyBindings: saveState.appSaveData.hotkeyBindings,
globalHotkeysEnabled: saveState.appSaveData.globalHotkeysEnabled,
username: saveState.appSaveData.username
})
connector.changeCharacterCyclingOrder({ characterCyclingOrder: save.appSaveData.characterCylingOrder })
gamepadManager = new GamepadManager(window, connector, save.appSaveData.gamepadId)
store = initReducer(history, save)
connector.changeCharacterCyclingOrder({ characterCyclingOrder: saveState.appSaveData.characterCylingOrder })
gamepadManager = new GamepadManager(window, connector, saveState.appSaveData.gamepadId)

render(
<Provider store={store}>
Expand Down Expand Up @@ -64,20 +66,26 @@ async function loadSaveData (): Promise<SaveStateDraft<ElectronSaveData>> {
encoding: 'utf8'
}))
if (appSaveData == null) {
await new Promise(resolve => {
rimraf(appSavePath, err => {
if (err) {
console.error(err)
} else {
fs.mkdirSync(appSavePath)
}
resolve()
})
})
await clearAppData(appSavePath)
} else {
save.appSaveData = appSaveData
}
} catch (err) {}
} catch (err) {
await clearAppData(appSavePath)
}
}
return save
}

function clearAppData (appSavePath: string): Promise<void> {
return new Promise(resolve => {
rimraf(appSavePath, err => {
if (err) {
console.error(err)
} else {
fs.mkdirSync(appSavePath)
}
resolve()
})
})
}

0 comments on commit d6108e6

Please sign in to comment.