Skip to content

Commit

Permalink
Add locale settings
Browse files Browse the repository at this point in the history
  • Loading branch information
remixz committed Jun 5, 2017
1 parent 5ccfb07 commit d5205dc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/Video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
data.append('event', 'playback_status')
data.append('playhead', time)
data.append('media_id', id || this.id)
data.append('locale', LOCALE)
data.append('locale', LOCALE())
data.append('version', VERSION)
api({
Expand Down
6 changes: 3 additions & 3 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, {CancelToken} from 'axios'

export const ACCESS_TOKEN = 'LNDJgOit5yaRIWN'
export const DEVICE_TYPE = 'com.crunchyroll.windows.desktop'
export const LOCALE = 'enUS'
export const LOCALE = () => localStorage.getItem('locale') || 'enUS'
export const VERSION = '1.1.20.0'
export const CONNECTIVITY_TYPE = 'ethernet'
export const UMI_SERVER = process.env.NODE_ENV === 'production' ? 'https://umi-watch-api.now.sh' : 'http://localhost:3001'
Expand All @@ -12,9 +12,9 @@ let source = CancelToken.source()
export default function api (opts) {
const config = {
method: opts.method || 'get',
url: `https://api.crunchyroll.com/${opts.route}.0.json`,
url: `https://api.crunchyroll.com/${opts.route}.${opts.version || '0'}.json`,
params: !opts.data ? Object.assign({}, opts.params, {
locale: LOCALE,
locale: LOCALE(),
version: VERSION,
connectivity_type: CONNECTIVITY_TYPE
}) : null,
Expand Down
30 changes: 29 additions & 1 deletion src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
<div class="green mt1 absolute save-message" :class="[savedName ? 'o-100' : 'o-0']">Saved!</div>
</form>
</div>
<div class="cf">
<div class="fl mt2">
<span class="fw5">Content language</span>
</div>
<div class="fr">
<select name="locale" class="h2 br1 ba b--black-20 bg-white mt3" v-model="selectedLocale">
<option v-for="locale in locales" :key="locale.locale_id" :value="locale.locale_id">{{locale.label}}</option>
</select>
<div class="green mt1 absolute save-message" :class="[savedLocale ? 'o-100' : 'o-0']">Saved!</div>
</div>
</div>
<h2 class="fw5 bb pb2 b--dark-gray"><i class="fa fa-link mr1"></i> Connections</h2>
<div class="cf">
<div class="fl pv2">
Expand All @@ -32,6 +43,8 @@
</template>

<script>
import {LOCALE} from 'lib/api'
export default {
name: 'settings',
metaInfo: {
Expand All @@ -44,12 +57,27 @@
malPassword: '',
malLoading: false,
malError: false,
savedName: false
savedName: false,
savedLocale: false,
selectedLocale: LOCALE()
}
},
computed: {
malAuth () {
return this.$store.state.malAuth
},
locales () {
return this.$store.state.locales
}
},
watch: {
selectedLocale (val) {
localStorage.setItem('locale', val)
if (this.savedLocale) return
this.savedLocale = true
setTimeout(() => {
this.savedLocale = false
}, 2000)
}
},
methods: {
Expand Down
12 changes: 10 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const store = new Vuex.Store({
) : (
{}
),
locales: [],
displayName: localStorage.getItem('displayName') || '',
series: {},
seriesCollections: {},
Expand Down Expand Up @@ -70,6 +71,9 @@ const store = new Vuex.Store({
expires: data.expires
})
resolve()
// fetch locales in the background
const localeResp = await api({route: 'list_locales', version: '1', params: {session_id: data.session_id}})
commit('UPDATE_LOCALES', localeResp.data.data.locales)
} catch (err) {
reject(err)
}
Expand All @@ -81,7 +85,7 @@ const store = new Vuex.Store({
form.append('account', username)
form.append('password', password)
form.append('session_id', state.auth.session_id)
form.append('locale', LOCALE)
form.append('locale', LOCALE())
form.append('version', VERSION)

return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -265,7 +269,7 @@ const store = new Vuex.Store({
updateSeriesQueue ({commit, state}, {id, queueStatus}) {
const form = new FormData()
form.append('session_id', state.auth.session_id)
form.append('locale', LOCALE)
form.append('locale', LOCALE())
form.append('version', VERSION)
form.append('series_id', id)

Expand Down Expand Up @@ -418,6 +422,10 @@ const store = new Vuex.Store({
Vue.set(state, 'auth', updated)
},

UPDATE_LOCALES (state, arr) {
state.locales = arr
},

REMOVE_AUTH (state) {
localStorage.removeItem('auth')
Vue.set(state, 'auth', {})
Expand Down

0 comments on commit d5205dc

Please sign in to comment.