Skip to content

Commit

Permalink
fix: java install from china download
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jul 14, 2020
1 parent 016388e commit 47a7af5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 116 deletions.
25 changes: 14 additions & 11 deletions src/main/service/DiagnoseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,6 @@ export default class DiagnoseService extends Service {
() => this.instanceService.editInstance({ java: this.getters.defaultJava.path }),
// here the editInstance will automatically diagnose for java
'');

this.registerMatchedFix(['incompatibleJava'],
async () => {
let internalLocation = this.javaService.getInternalJavaLocation();
if (!this.state.java.all.find(j => j.path === internalLocation)) {
await this.javaService.installDefaultJava();
}
await this.instanceService.editInstance({ java: this.javaService.getInternalJavaLocation() });
},
// here the editInstance will automatically diagnose for java
'');
}

@MutationTrigger('instanceSelect')
Expand Down Expand Up @@ -641,4 +630,18 @@ export default class DiagnoseService extends Service {
this.release('diagnose');
}
}

@Singleton()
async fixNoJava() {
this.aquire('diagnose');
try {
let internalLocation = this.javaService.getInternalJavaLocation();
if (!this.state.java.all.find(j => j.path === internalLocation)) {
await this.javaService.installDefaultJava();
}
await this.instanceService.editInstance({ java: this.javaService.getInternalJavaLocation() });
} finally {
this.release('diagnose');
}
}
}
29 changes: 20 additions & 9 deletions src/main/service/JavaService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { missing } from '@main/util/fs';
import { getTsingHuaMirror } from '@main/util/jreTsingHuaMirror';
import { unpack7z } from '@main/util/zip';
import { MutationKeys } from '@universal/store';
import { JavaRecord } from '@universal/store/modules/java';
Expand Down Expand Up @@ -72,19 +71,30 @@ export default class JavaService extends Service {
return task('installJre', async (c) => {
let system = this.app.platform.name === 'osx' ? 'mac' as const : this.app.platform.name;
let arch = this.app.platform.arch === 'x64' ? '64' as const : '32' as const;
if (system === 'unknown') { throw new Error(`Cannot install jre in system ${system}`); }
let [url, sha256Url] = getTsingHuaMirror(system, arch);
let sha256 = await this.networkManager.request(sha256Url).text();
sha256 = sha256.split(' ')[0];
let list = (await this.networkManager.request.get('https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/filelist').text())
.split('\n')
.map(l => l.split('/').slice(5));
const zipFile = list
.find(l => l[0] === 'jre' && l[1] === `x${arch}` && l[2] === system && (l[3].endsWith('.zip') || l[3].endsWith('.tar.gz')));
if (!zipFile) {
throw new Error(`Cannot find jre for ${system} x${arch}`);
}
let sha256File = list.find(l => l[3] === `${zipFile[3]}.sha256.txt`);
let url = `https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/${zipFile.join('/')}`;
let sha256Url = `https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/${sha256File?.join('/')}`;
let sha256 = await this.networkManager.request(sha256Url).text().then((s) => s.split(' ')[0]).catch(e => '');
let dest = join(this.state.root, 'jre');
let tempZip = join(this.state.root, 'temp', 'java-temp');
let checksum = sha256 ? {
algorithm: 'sha256',
hash: sha256,
} : undefined;

this.log(`Install jre for ${system} x${arch} from tsing hua mirror ${url}`);
await c.execute(task('download', downloadFileTask({
destination: tempZip,
url,
checksum: {
algorithm: 'sha256',
hash: sha256,
},
checksum,
}, this.networkManager.getDownloaderOption())), 90);

await c.execute(task('decompress', async () => {
Expand All @@ -104,6 +114,7 @@ export default class JavaService extends Service {
}
await unlink(tempZip);
}), 10);
this.log('Install jre for from tsing hua mirror success!');
});
}

Expand Down
32 changes: 0 additions & 32 deletions src/main/util/jreTsingHuaMirror.spec.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/util/jreTsingHuaMirror.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/renderer/assets/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
},
"missingJava": {
"": "没有分配Java",
"switch": {
"": "切换到 Java 8",
"message": "启动器将使用您现在安装的 Java 8",
"disabled": "在电脑中没有检测到 Java,无法切换"
},
"autoDownload": {
"": "自动下载",
"message": "启动器将从Mojang源下载并安装Java"
Expand Down
52 changes: 9 additions & 43 deletions src/renderer/windows/main/dialog/BaseJavaWizardDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,15 @@
</template>
</v-list>
</v-window-item>

<v-window-item :value="1">
<!-- <v-card-text>{{ $t('java.selectJava') }}</v-card-text>
<v-list style="width: 100%" class="grey darken-4" dark>
<template v-for="(java, i) in externalJavas">
<v-list-tile :key="i" ripple @click="selectJava(java)">
<v-list-tile-content>
<v-list-tile-title>{{ java.path }}</v-list-tile-title>
<v-list-tile-sub-title>{{ java.path }}</v-list-tile-sub-title>
</v-list-tile-content>
<v-list-tile-action>
<v-progress-circular v-if="java.loading" indeterminate small :width="3" />
<v-icon v-else :color="{ green: java.valid, red: !java.valid }">{{ java.valid ? 'check' : 'stop' }}</v-icon>
</v-list-tile-action>
</v-list-tile>
</template>
</v-list>-->

<v-card-actions>
<v-btn
flat
@click="back"
>
{{ $t('back') }}
<v-icon right>arrow_left</v-icon>
</v-btn>
</v-card-actions>
</v-window-item>
</v-window>
</v-card>
</v-dialog>
</template>

<script lang=ts>
import { reactive, computed, toRefs, onMounted, onUnmounted, watch, defineComponent } from '@vue/composition-api';
import { reactive, computed, toRefs, defineComponent } from '@vue/composition-api';
import { useI18n, useStore, useJava, useNativeDialog, useServiceOnly, useInstance } from '@/hooks';
import { useDialog, useJavaWizardDialog, useNotifier } from '../hooks';
import { useJavaWizardDialog, useNotifier } from '../hooks';
export default defineComponent({
props: {
Expand All @@ -88,15 +60,16 @@ export default defineComponent({
},
},
setup() {
const dialog = useNativeDialog();
const { showOpenDialog } = useNativeDialog();
const { state } = useStore();
const { $t } = useI18n();
const { show, isShown, javaIssue } = useJavaWizardDialog();
const { add, refreshLocalJava } = useJava();
const { editInstance } = useInstance();
const { fix } = useServiceOnly('DiagnoseService', 'fix');
const java8 = computed(() => state.java.all.find(j => j.majorVersion === 8 && j.valid));
const { fixNoJava } = useServiceOnly('DiagnoseService', 'fixNoJava');
const { subscribeTask } = useNotifier();
const java8 = computed(() => state.java.all.find(j => j.majorVersion === 8 && j.valid));
const data = reactive({
step: 0,
Expand All @@ -115,7 +88,7 @@ export default defineComponent({
autofix: true,
title: $t('diagnosis.missingJava.autoDownload'),
message: $t('diagnosis.missingJava.autoDownload.message'),
disabled: java8.value !== undefined,
disabled: false,
}, {
title: $t('diagnosis.missingJava.selectJava'),
message: $t('diagnosis.missingJava.selectJava.message'),
Expand All @@ -133,16 +106,12 @@ export default defineComponent({
if (missing.value) {
data.status = 'error';
show();
} else {
// reason.value = '';
// hint.value = '';
}
});
}
function selectJava(java: { path: string }) {
editInstance({ java: java.path });
}
return {
...toRefs(data),
isShown,
Expand All @@ -156,10 +125,10 @@ export default defineComponent({
subscribeTask(editInstance({ java: java8.value!.path }), $t('java.modifyInstance'));
isShown.value = false;
} else if (index === 1) {
await fix([{ id: 'incompatibleJava', multi: false, arguments: {} }]);
fixNoJava();
isShown.value = false;
} else if (index === 2) {
const { filePaths, canceled } = await dialog.showOpenDialog({
const { filePaths, canceled } = await showOpenDialog({
title: $t('java.browse'),
});
Expand All @@ -172,9 +141,6 @@ export default defineComponent({
isShown.value = false;
}
},
back() {
data.step = 0;
},
};
},
});
Expand Down

0 comments on commit 47a7af5

Please sign in to comment.