-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the updating of
Profiles
view's list by making fs
checks …
…asynchronous - Changes have been made to `updateProfileList()` function. - End results have not been changed, only getting there has been improved.
- Loading branch information
1 parent
d8074d4
commit 7889a82
Showing
4 changed files
with
54 additions
and
44 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
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,25 +1,51 @@ | ||
import FileUtils from "../../utils/FileUtils"; | ||
import R2Error from "../../model/errors/R2Error"; | ||
import { ActionTree, Store } from "vuex"; | ||
import { State as RootState } from "../../store"; | ||
import Profile from "../../model/Profile"; | ||
import FsProvider from "../../providers/generic/file/FsProvider"; | ||
|
||
interface State { | ||
profileList: string[]; | ||
} | ||
|
||
/** | ||
* State for Profiles, i.e. list for profiles in a single game/community. | ||
*/ | ||
export default { | ||
export const ProfilesModule = { | ||
namespaced: true, | ||
|
||
state: (): State => ({ | ||
profileList: ['Default'], | ||
}), | ||
mutations: { | ||
pushToProfileList(state: State, profile: string) { | ||
state.profileList.push(profile); | ||
}, | ||
spliceProfileList(state: State, index: number) { | ||
state.profileList.splice(index, 1); | ||
setProfileList(state: State, profileList: string[]) { | ||
state.profileList = profileList; | ||
}, | ||
setProfileList(state: State, list: string[]) { | ||
state.profileList = list; | ||
}, | ||
actions: <ActionTree<State, RootState>>{ | ||
async removeSelectedProfile({commit, rootGetters, state, dispatch}, params: {fs: FsProvider, store: Store<any>}) { | ||
const activeProfile: Profile = rootGetters['profile/activeProfile']; | ||
const path = activeProfile.getPathOfProfile(); | ||
const profileName = activeProfile.getProfileName(); | ||
|
||
try { | ||
await FileUtils.emptyDirectory(path); | ||
await params.fs.rmdir(path); | ||
} catch (e) { | ||
const err = R2Error.fromThrownValue(e, 'Error whilst deleting profile from disk'); | ||
await params.store.dispatch('error/handleError', err); | ||
} | ||
|
||
if (profileName.toLowerCase() !== 'default') { | ||
try { | ||
state.profileList = state.profileList.filter((p: string) => p !== profileName) | ||
await params.store.dispatch('profile/updateActiveProfile', 'Default'); | ||
} catch (e) { | ||
const err = R2Error.fromThrownValue(e, 'Error whilst deleting profile from vuex storage'); | ||
await params.store.dispatch('error/handleError', err); | ||
} | ||
} | ||
}, | ||
}, | ||
} |