2024-11-28 08:12:37 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<n-modal v-model:show="showModal" preset="dialog" :show-icon="false" :mask-closable="true" class="install-app-modal">
|
|
|
|
|
|
<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>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</n-modal>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { onMounted, ref } from 'vue';
|
|
|
|
|
|
|
2024-12-15 13:00:20 +08:00
|
|
|
|
import config from '@/../package.json';
|
2024-12-15 14:35:18 +08:00
|
|
|
|
import { isMobile } from '@/utils';
|
2024-12-15 13:00:20 +08:00
|
|
|
|
|
2024-11-28 08:12:37 +08:00
|
|
|
|
const showModal = ref(false);
|
|
|
|
|
|
const isElectron = ref((window as any).electron !== undefined);
|
2024-12-08 21:50:58 +08:00
|
|
|
|
const noPrompt = ref(false);
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
// 如果是 electron 环境,不显示安装提示
|
2024-12-15 14:35:18 +08:00
|
|
|
|
if (isElectron.value || isMobile.value) {
|
2024-11-28 08:12:37 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已经点击过"暂不安装"
|
|
|
|
|
|
const isDismissed = localStorage.getItem('installPromptDismissed') === 'true';
|
|
|
|
|
|
if (isDismissed) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
showModal.value = true;
|
|
|
|
|
|
});
|
2024-12-15 13:00:20 +08:00
|
|
|
|
|
|
|
|
|
|
const handleInstall = async (): Promise<void> => {
|
|
|
|
|
|
const { userAgent } = navigator;
|
|
|
|
|
|
console.log('userAgent', userAgent);
|
|
|
|
|
|
const isMac: boolean = userAgent.includes('Mac');
|
|
|
|
|
|
const isWindows: boolean = userAgent.includes('Win');
|
|
|
|
|
|
const isARM: boolean = userAgent.includes('ARM') || userAgent.includes('arm') || userAgent.includes('OS X');
|
|
|
|
|
|
const isX64: boolean = userAgent.includes('x86_64') || userAgent.includes('Win64') || userAgent.includes('WOW64');
|
|
|
|
|
|
const isX86: boolean =
|
|
|
|
|
|
!isX64 && (userAgent.includes('i686') || userAgent.includes('i386') || userAgent.includes('Win32'));
|
|
|
|
|
|
|
|
|
|
|
|
const getDownloadUrl = (os: string, arch: string): string => {
|
|
|
|
|
|
const version = config.version as string;
|
|
|
|
|
|
return `https://github.com/algerkong/AlgerMusicPlayer/releases/download/${version}/AlgerMusic_${version}_${arch}.${os === 'mac' ? 'dmg' : 'exe'}`;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const osType: string | null = isMac ? 'mac' : isWindows ? 'windows' : null;
|
|
|
|
|
|
const archType: string | null = isARM ? 'arm64' : isX64 ? 'x64' : isX86 ? 'x86' : null;
|
|
|
|
|
|
|
|
|
|
|
|
const downloadUrl: string | null = osType && archType ? getDownloadUrl(osType, archType) : null;
|
|
|
|
|
|
|
|
|
|
|
|
window.open(downloadUrl || 'https://github.com/algerkong/AlgerMusicPlayer/releases', '_blank');
|
|
|
|
|
|
};
|
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 {
|
|
|
|
|
|
@apply p-4;
|
|
|
|
|
|
.modal-header {
|
|
|
|
|
|
@apply flex items-center mb-6;
|
|
|
|
|
|
.app-icon {
|
|
|
|
|
|
@apply w-16 h-16 mr-4 rounded-2xl overflow-hidden;
|
|
|
|
|
|
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 {
|
|
|
|
|
|
@apply flex gap-3;
|
|
|
|
|
|
.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>
|