feat: add beta download

This commit is contained in:
lisonge 2024-08-23 17:38:05 +08:00
parent 45978e3e2e
commit 5521c18eac
2 changed files with 40 additions and 21 deletions

View File

@ -1,6 +1,12 @@
<script setup lang="ts">
import { computed, shallowRef, onMounted } from 'vue';
import { saveAs } from 'file-saver';
import { computed, onMounted, shallowRef } from 'vue';
const props = withDefaults(
defineProps<{
beta?: boolean;
}>(),
{},
);
const apkUrl = shallowRef('');
const apkName = computed(() =>
@ -11,6 +17,7 @@ const loading = shallowRef(false);
const downloadApk = async () => {
if (!apkUrl.value || loading.value) return;
loading.value = true;
try {
const file = await fetch(apkUrl.value)
.then((r) => r.arrayBuffer())
.then(
@ -18,20 +25,29 @@ const downloadApk = async () => {
new File([b], apkName.value, {
type: 'application/vnd.android.package-archive',
}),
)
.finally(() => {
loading.value = false;
});
);
const { saveAs } = await import('file-saver');
saveAs(file, apkName.value);
} finally {
loading.value = false;
}
};
// preload file-saver in browser
if (globalThis.document) {
import('file-saver');
}
const pkg = computed(() => (props.beta ? 'app-beta' : 'app'));
const key = computed(() => `apkUrl-${pkg.value}`);
onMounted(async () => {
apkUrl.value = localStorage.getItem('apkUrl') || '';
const versionUrl = 'https://registry.npmmirror.com/@gkd-kit/app/latest/files';
apkUrl.value = localStorage.getItem(key.value) || '';
const versionUrl = `https://registry.npmmirror.com/@gkd-kit/${pkg.value}/latest/files`;
const r = await fetch(versionUrl);
const data = await r.json();
apkUrl.value = new URL(data.downloadUrl, r.url).href;
localStorage.setItem('apkUrl', apkUrl.value);
localStorage.setItem(key.value, apkUrl.value);
});
</script>
<template>

View File

@ -1,14 +1,17 @@
# 开始使用 {#title}
## 下载安装 {#install}
## 安装 {#install}
- 镜像加速 <ClientOnly><ApkDownloadButton /></ClientOnly>
| 版本 | 下载链接 | 备注 |
| ------ | -------------------------- | -------------- |
| 正式版 | <ApkDownloadButton /> | 稳定版 |
| 测试版 | <ApkDownloadButton beta /> | 更新快不稳定 |
- Github [releases](https://github.com/gkd-kit/gkd/releases/latest)
或前往 [Github Releases](https://github.com/gkd-kit/gkd/releases/latest) 下载
下载完毕后, 在您的 Android 手机上安装并打开
## 授权使用 {#usage}
## 使用 {#usage}
打开后进入 GKD 的首页, 要想 GKD 正常工作需要授权无障碍权限