-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
194 changed files
with
2,445 additions
and
1,330 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,91 @@ | ||
import path from 'path' | ||
import pogobuf from 'pogobuf' | ||
import { | ||
remote | ||
} from 'electron' | ||
import { | ||
createAction | ||
} from 'redux-actions' | ||
|
||
import * as fs from 'async-file' | ||
|
||
import client from '../client' | ||
|
||
import { | ||
getTrainerInfo, | ||
getTrainerPokemon | ||
} from './trainer' | ||
|
||
const saveAccountCredentialsFailed = createAction('SAVE_ACCOUNT_CREDENTIALS_FAILED') | ||
const saveAccountCredentialsSuccess = createAction('SAVE_ACCOUNT_CREDENTIALS_SUCCESS') | ||
|
||
const checkAndDeleteCredentialsFailed = createAction('CHECK_AND_DELETE_CREDENTIALS_FAILED') | ||
const checkAndDeleteCredentialsSuccess = createAction('CHECK_AND_DELETE_CREDENTIALS_SUCCESS') | ||
|
||
const userLoginStarted = createAction('USER_LOGIN_STARTED') | ||
const userLoginSuccess = createAction('USER_LOGIN_SUCCESS') | ||
const userLoginFailed = createAction('USER_LOGIN_FAILED') | ||
|
||
const accountPath = path.join(remote.app.getPath('appData'), '/pokenurse/account.json') | ||
|
||
export default { | ||
client, | ||
|
||
login({ method, username, password }) { | ||
return async (dispatch) => { | ||
dispatch(userLoginStarted()) | ||
|
||
let login | ||
if (method === 'google') { | ||
login = new pogobuf.GoogleLogin() | ||
} else { | ||
login = new pogobuf.PTCLogin() | ||
} | ||
|
||
try { | ||
const token = await login.login(username, password) | ||
|
||
client.setAuthInfo(method, token) | ||
client.init() | ||
|
||
// TODO display a loading spinner | ||
// then fetch all necessary things | ||
await Promise.all([ | ||
dispatch(getTrainerInfo()), | ||
dispatch(getTrainerPokemon()) | ||
]) | ||
|
||
dispatch(userLoginSuccess()) | ||
} catch (error) { | ||
console.error(error) // eslint-disable-line | ||
dispatch(userLoginFailed({ error })) | ||
} | ||
} | ||
}, | ||
|
||
logout: createAction('USER_LOGOUT'), | ||
|
||
checkAndDeleteCredentials() { | ||
return async (dispatch) => { | ||
try { | ||
if (await fs.exists(accountPath)) { | ||
await fs.unlink(accountPath) | ||
} | ||
dispatch(checkAndDeleteCredentialsSuccess()) | ||
} catch (error) { | ||
dispatch(checkAndDeleteCredentialsFailed()) | ||
} | ||
} | ||
}, | ||
|
||
saveAccountCredentials(credentials) { | ||
return async (dispatch) => { | ||
try { | ||
const response = await fs.writeFile(accountPath, JSON.stringify(credentials)) | ||
dispatch(saveAccountCredentialsSuccess({ response, credentials })) | ||
} catch (error) { | ||
dispatch(saveAccountCredentialsFailed(error)) | ||
} | ||
} | ||
} | ||
} |
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,5 +1,11 @@ | ||
import * as statusActions from './status' | ||
import * as authenticateActions from './authenticate' | ||
import * as trainerActions from './trainer' | ||
import * as settingsActions from './settings' | ||
|
||
export default { | ||
...statusActions | ||
...statusActions, | ||
...authenticateActions, | ||
...trainerActions, | ||
...settingsActions, | ||
} |
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,13 @@ | ||
import { | ||
createAction | ||
} from 'redux-actions' | ||
|
||
export default { | ||
toggleShowSpeciesWithZeroPokemon: createAction('TOGGLE_SHOW_SPECIES_WITH_ZERO_POKEMON'), | ||
toggleAutoLogin: createAction('TOGGLE_AUTO_LOGIN'), | ||
resetAllSettings: createAction('RESET_ALL_SETTINGS'), | ||
changeDefaultPokedexSortBy: createAction('CHANGE_DEFAULT_POKEDEX_SORT_BY'), | ||
changeDefaultPokedexSortDirection: createAction('CHANGE_DEFAULT_POKEDEX_SORT_DIRECTION'), | ||
changeDefaultSpecieSortBy: createAction('CHANGE_DEFAULT_SPECIE_SORT_BY'), | ||
changeDefaultSpecieSortDirection: createAction('CHANGE_DEFAULT_SPECIE_SORT_DIRECTION'), | ||
} |
Oops, something went wrong.