Skip to content

Commit

Permalink
feat(download): support bmcl api toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Sep 4, 2019
1 parent 69be34c commit e3080a9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/main/store/modules/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,25 @@ const mod = {

async installLibraries(context, { libraries }) {
let option = {};
if (await inGFW().catch(_ => false)) {
if (await inGFW().catch(_ => false) && context.rootState.setting.useBmclAPI) {
option = { libraryHost: lib => `https://http://bmclapi.bangbang93.com/maven/${lib.path}` };
}

const task = Installer.installLibrariesDirectTask(Version.resolveLibraries(libraries), context.rootState.root, option);
return context.dispatch('executeTask', task);
const handle = await context.dispatch('executeTask', task);
context.dispatch('waitTask', handle).catch((e) => {
if ('libraryHost' in option) {
return Installer.installLibrariesDirectTask(Version.resolveLibraries(libraries), context.rootState.root);
}
throw e;
});
return handle;
},

async installAssets(context, version) {
const ver = await Version.parse(context.rootState.root, version);
let option = {};
if (await inGFW().catch(_ => false)) {
if (await inGFW().catch(_ => false) && context.rootState.setting.useBmclAPI) {
option = { assetsHost: 'http://bmclapi2.bangbang93.com/assets' };
}
const task = Installer.installAssetsTask(ver, option);
Expand All @@ -224,7 +231,7 @@ const mod = {
const id = meta.id;

let option = {};
if (await inGFW().catch(_ => false)) {
if (await inGFW().catch(_ => false) && context.rootState.setting.useBmclAPI) {
option = { client: `https://bmclapi2.bangbang93.com/version/${meta.id}/client` };
}

Expand Down
15 changes: 14 additions & 1 deletion src/renderer/windows/main/SettingPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<v-container grid-list-md fluid>
<v-container grid-list-md fluid style="z-index: 1">
<v-layout wrap style="padding: 6px; 8px; overflow: auto; max-height: 95vh" fill-height>
<v-flex d-flex xs12 tag="h1" style="margin-bottom: 20px; " class="white--text">
<span class="headline">{{ $tc('setting.name', 2) }}</span>
Expand Down Expand Up @@ -36,6 +36,15 @@
</v-btn>
</v-list-tile-action>
</v-list-tile>
<v-list-tile>
<v-list-tile-action>
<v-checkbox v-model="useBmclAPI" />
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title> {{ $t('setting.useBmclAPI') }} </v-list-tile-title>
<v-list-tile-sub-title> {{ $t('setting.useBmclAPIDescription') }} </v-list-tile-sub-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-flex>
<v-divider dark />
Expand Down Expand Up @@ -195,6 +204,10 @@ export default {
get() { return this.$repo.state.setting.autoDownload; },
set(v) { this.$repo.commit('autoDownload', v); },
},
useBmclAPI: {
get() { return this.$repo.state.setting.useBmclAPI; },
set(v) { this.$repo.commit('useBmclApi', v); },
},
readyToUpdate() { return this.$repo.state.setting.readyToUpdate; },
downloadingUpdate() { return this.$repo.state.setting.downloadingUpdate; },
checkingUpdate() { return this.$repo.state.setting.checkingUpdate; },
Expand Down
6 changes: 6 additions & 0 deletions src/universal/store/modules/setting.config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ export interface SettingConfig {
* @default 0
*/
defaultBlur: number;

/**
* Use bmcl API in China Mainland
* @default true
*/
useBmclAPI: boolean;
}
3 changes: 2 additions & 1 deletion src/universal/store/modules/setting.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export declare namespace SettingModule {
}

interface Mutations {
config(state: State, payload: Pick<State, 'locale' | 'settings' | 'autoDownload' | 'autoInstallOnAppQuit' | 'allowPrerelease' | 'locales'>): void;
config(state: State, payload: SettingConfig): void;
locale(state: State, locale: string): void;
allowPrerelease(state: State, allow: boolean): void;
autoInstallOnAppQuit(state: State, autoInstallOnAppQuit: boolean): void;
Expand All @@ -27,6 +27,7 @@ export declare namespace SettingModule {
settings(state: State, settings: { [key: string]: number | string | boolean | object }): void;
defaultBackgroundImage(state: State, img: string | null): void;
defaultBlur(state: State, blur: number): void;
useBmclApi(state: State, use: boolean): void;
}
type C = Context<State, {}, Mutations, Actions>;
interface Actions {
Expand Down
6 changes: 5 additions & 1 deletion src/universal/store/modules/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const mod = {
autoDownload: false,
defaultBackgroundImage: null,
defaultBlur: 0,
useBmclAPI: true,
},
mutations: {
downloadingUpdate(state, d) { state.downloadingUpdate = !!d; },
Expand All @@ -36,10 +37,10 @@ const mod = {
},
config(state, config) {
state.locale = config.locale;
state.locales = config.locales;
state.autoDownload = config.autoDownload || false;
state.autoInstallOnAppQuit = config.autoDownload || false;
state.allowPrerelease = config.allowPrerelease || false;
state.useBmclAPI = typeof config.useBmclAPI === 'boolean' ? config.useBmclAPI : true;
},
settings(state, settings) {
// Object.assign(state.settings, settings);
Expand All @@ -50,6 +51,9 @@ const mod = {
defaultBlur(state, blur) {
if (typeof blur === 'number') state.defaultBlur = blur;
},
useBmclApi(state, use) {
state.useBmclAPI = use;
},
},
};

Expand Down
2 changes: 2 additions & 0 deletions static/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@
"showRoot": "Show",
"theme": "Theme",
"update": "Update",
"useBmclAPI": "Use BMCL API",
"useBmclAPIDescription": "Use BMCLAPI to download Minecraft when you are in China Mainland. (This won't affect if you're not in China mainland)",
"updateToThisVersion": "Download and Install",
"viewUpdate": "View Update Detail",
"waitReload": "Migrating data. Please don't close the Launcher or you will lose your data."
Expand Down
2 changes: 2 additions & 0 deletions static/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@
"theme": "外观主题",
"update": "升级设置",
"updateToThisVersion": "下载并安装",
"useBmclAPI": "使用 BMCL API",
"useBmclAPIDescription": "当你在大陆时,优先使用 BMCLAPI 来下载 Minecraft",
"viewUpdate": "详细信息",
"waitReload": "迁移数据中。请勿在此时关闭启动器,否则你将可能失去一部分数据。"
},
Expand Down

0 comments on commit e3080a9

Please sign in to comment.