2024-11-28 08:12:37 +08:00
|
|
|
|
<template>
|
2025-01-01 02:25:18 +08:00
|
|
|
|
<n-modal
|
|
|
|
|
|
v-model:show="showModal"
|
|
|
|
|
|
preset="dialog"
|
|
|
|
|
|
:show-icon="false"
|
|
|
|
|
|
:mask-closable="true"
|
|
|
|
|
|
class="install-app-modal"
|
|
|
|
|
|
>
|
2024-11-28 08:12:37 +08:00
|
|
|
|
<div class="modal-content">
|
|
|
|
|
|
<div class="modal-header">
|
|
|
|
|
|
<div class="app-icon">
|
|
|
|
|
|
<img src="@/assets/logo.png" alt="App Icon" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="app-info">
|
2024-12-15 13:00:20 +08:00
|
|
|
|
<h2 class="app-name">Alger Music Player {{ config.version }}</h2>
|
2024-12-08 21:50:58 +08:00
|
|
|
|
<p class="app-desc mb-2">在桌面安装应用,获得更好的体验</p>
|
|
|
|
|
|
<n-checkbox v-model:checked="noPrompt">不再提示</n-checkbox>
|
2024-11-28 08:12:37 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="modal-actions">
|
|
|
|
|
|
<n-button class="cancel-btn" @click="closeModal">暂不安装</n-button>
|
|
|
|
|
|
<n-button type="primary" class="install-btn" @click="handleInstall">立即安装</n-button>
|
|
|
|
|
|
</div>
|
2024-12-16 20:40:57 +08:00
|
|
|
|
<div class="modal-desc mt-4 text-center">
|
|
|
|
|
|
<p class="text-xs text-gray-400">
|
|
|
|
|
|
下载遇到问题?去
|
2025-01-01 02:25:18 +08:00
|
|
|
|
<a
|
|
|
|
|
|
class="text-green-500"
|
|
|
|
|
|
target="_blank"
|
|
|
|
|
|
href="https://github.com/algerkong/AlgerMusicPlayer/releases"
|
2024-12-16 20:40:57 +08:00
|
|
|
|
>GitHub</a
|
|
|
|
|
|
>
|
|
|
|
|
|
下载最新版本
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
2024-11-28 08:12:37 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</n-modal>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { onMounted, ref } from 'vue';
|
2025-01-10 22:49:55 +08:00
|
|
|
|
|
2025-01-01 02:25:18 +08:00
|
|
|
|
import { isElectron, isMobile } from '@/utils';
|
2025-01-01 22:42:25 +08:00
|
|
|
|
import { getLatestReleaseInfo } from '@/utils/update';
|
2024-12-15 13:00:20 +08:00
|
|
|
|
|
2025-01-10 22:49:55 +08:00
|
|
|
|
import config from '../../../../package.json';
|
|
|
|
|
|
|
2024-11-28 08:12:37 +08:00
|
|
|
|
const showModal = ref(false);
|
2024-12-08 21:50:58 +08:00
|
|
|
|
const noPrompt = ref(false);
|
2025-01-01 22:42:25 +08:00
|
|
|
|
const releaseInfo = ref<any>(null);
|
2024-11-28 08:12:37 +08:00
|
|
|
|
|
|
|
|
|
|
const closeModal = () => {
|
|
|
|
|
|
showModal.value = false;
|
2024-12-08 21:50:58 +08:00
|
|
|
|
if (noPrompt.value) {
|
|
|
|
|
|
localStorage.setItem('installPromptDismissed', 'true');
|
|
|
|
|
|
}
|
2024-11-28 08:12:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-01-01 22:42:25 +08:00
|
|
|
|
onMounted(async () => {
|
2024-11-28 08:12:37 +08:00
|
|
|
|
// 如果是 electron 环境,不显示安装提示
|
2025-01-01 02:25:18 +08:00
|
|
|
|
if (isElectron || isMobile.value) {
|
2024-11-28 08:12:37 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已经点击过"暂不安装"
|
|
|
|
|
|
const isDismissed = localStorage.getItem('installPromptDismissed') === 'true';
|
|
|
|
|
|
if (isDismissed) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-01-01 22:42:25 +08:00
|
|
|
|
|
|
|
|
|
|
// 获取最新版本信息
|
|
|
|
|
|
releaseInfo.value = await getLatestReleaseInfo();
|
2024-11-28 08:12:37 +08:00
|
|
|
|
showModal.value = true;
|
|
|
|
|
|
});
|
2024-12-15 13:00:20 +08:00
|
|
|
|
|
|
|
|
|
|
const handleInstall = async (): Promise<void> => {
|
2025-01-01 22:42:25 +08:00
|
|
|
|
const assets = releaseInfo.value?.assets || [];
|
2024-12-15 13:00:20 +08:00
|
|
|
|
const { userAgent } = navigator;
|
2025-01-01 22:42:25 +08:00
|
|
|
|
const isMac = userAgent.toLowerCase().includes('mac');
|
|
|
|
|
|
const isWindows = userAgent.toLowerCase().includes('win');
|
|
|
|
|
|
const isLinux = userAgent.toLowerCase().includes('linux');
|
2025-01-10 22:49:55 +08:00
|
|
|
|
const isX64 =
|
|
|
|
|
|
userAgent.includes('x86_64') || userAgent.includes('Win64') || userAgent.includes('WOW64');
|
2024-12-15 13:00:20 +08:00
|
|
|
|
|
2025-01-01 22:42:25 +08:00
|
|
|
|
let downloadUrl = '';
|
2024-12-15 13:00:20 +08:00
|
|
|
|
|
2025-01-01 22:42:25 +08:00
|
|
|
|
// 根据平台和架构选择对应的安装包
|
|
|
|
|
|
if (isMac) {
|
|
|
|
|
|
// macOS
|
2025-01-10 22:49:55 +08:00
|
|
|
|
const macAsset = assets.find((asset) => asset.name.includes('mac'));
|
2025-01-01 22:42:25 +08:00
|
|
|
|
downloadUrl = macAsset?.browser_download_url || '';
|
|
|
|
|
|
} else if (isWindows) {
|
|
|
|
|
|
// Windows
|
2025-01-10 22:49:55 +08:00
|
|
|
|
let winAsset = assets.find(
|
|
|
|
|
|
(asset) =>
|
|
|
|
|
|
asset.name.includes('win') &&
|
|
|
|
|
|
(isX64 ? asset.name.includes('x64') : asset.name.includes('ia32'))
|
2025-01-01 22:42:25 +08:00
|
|
|
|
);
|
2025-01-10 22:49:55 +08:00
|
|
|
|
if (!winAsset) {
|
|
|
|
|
|
winAsset = assets.find((asset) => asset.name.includes('win.exe'));
|
2025-01-01 22:42:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
downloadUrl = winAsset?.browser_download_url || '';
|
|
|
|
|
|
} else if (isLinux) {
|
|
|
|
|
|
// Linux
|
2025-01-10 22:49:55 +08:00
|
|
|
|
const linuxAsset = assets.find(
|
|
|
|
|
|
(asset) =>
|
|
|
|
|
|
(asset.name.endsWith('.AppImage') || asset.name.endsWith('.deb')) &&
|
|
|
|
|
|
asset.name.includes('x64')
|
2025-01-01 22:42:25 +08:00
|
|
|
|
);
|
|
|
|
|
|
downloadUrl = linuxAsset?.browser_download_url || '';
|
|
|
|
|
|
}
|
2024-12-15 13:00:20 +08:00
|
|
|
|
|
2025-01-01 22:42:25 +08:00
|
|
|
|
if (downloadUrl) {
|
|
|
|
|
|
window.open(`https://ghproxy.cn/${downloadUrl}`, '_blank');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 如果没有找到对应的安装包,跳转到 release 页面
|
|
|
|
|
|
window.open('https://github.com/algerkong/AlgerMusicPlayer/releases/latest', '_blank');
|
|
|
|
|
|
}
|
|
|
|
|
|
closeModal();
|
2024-12-15 13:00:20 +08:00
|
|
|
|
};
|
2024-11-28 08:12:37 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.install-app-modal {
|
|
|
|
|
|
:deep(.n-modal) {
|
|
|
|
|
|
@apply max-w-sm;
|
|
|
|
|
|
}
|
|
|
|
|
|
.modal-content {
|
2024-12-16 20:40:57 +08:00
|
|
|
|
@apply p-4 pb-0;
|
2024-11-28 08:12:37 +08:00
|
|
|
|
.modal-header {
|
|
|
|
|
|
@apply flex items-center mb-6;
|
|
|
|
|
|
.app-icon {
|
2024-12-16 20:40:57 +08:00
|
|
|
|
@apply w-20 h-20 mr-4 rounded-2xl overflow-hidden;
|
2024-11-28 08:12:37 +08:00
|
|
|
|
img {
|
|
|
|
|
|
@apply w-full h-full object-cover;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
.app-info {
|
|
|
|
|
|
@apply flex-1;
|
|
|
|
|
|
.app-name {
|
|
|
|
|
|
@apply text-xl font-bold mb-1;
|
|
|
|
|
|
}
|
|
|
|
|
|
.app-desc {
|
|
|
|
|
|
@apply text-sm text-gray-400;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
.modal-actions {
|
2024-12-16 20:40:57 +08:00
|
|
|
|
@apply flex gap-3 mt-4;
|
2024-11-28 08:12:37 +08:00
|
|
|
|
.n-button {
|
|
|
|
|
|
@apply flex-1;
|
|
|
|
|
|
}
|
|
|
|
|
|
.cancel-btn {
|
|
|
|
|
|
@apply bg-gray-800 text-gray-300 border-none;
|
|
|
|
|
|
&:hover {
|
|
|
|
|
|
@apply bg-gray-700;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
.install-btn {
|
|
|
|
|
|
@apply bg-green-600 border-none;
|
|
|
|
|
|
&:hover {
|
|
|
|
|
|
@apply bg-green-500;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|