|
1 |
| -<script> |
2 |
| - import Button from '$lib/components/Button.svelte'; |
| 1 | +<script lang="ts"> |
| 2 | +import Button from "$lib/components/Button.svelte"; |
| 3 | +import { queries } from "$data/api"; |
| 4 | +import { onMount } from "svelte"; |
| 5 | +import { createQuery } from "@tanstack/svelte-query"; |
| 6 | +import Query from "$lib/components/Query.svelte"; |
| 7 | +import Dialogue from "$lib/components/Dialogue.svelte"; |
| 8 | +
|
| 9 | +const query = createQuery(["manager"], queries.manager); |
| 10 | +
|
| 11 | +let warning: string; |
| 12 | +let warningDialogue = false; |
| 13 | +
|
| 14 | +let userAgent: string; |
| 15 | +let isAndroid: boolean; |
| 16 | +let androidVersionMatch: RegExpExecArray | null; |
| 17 | +let androidVersion: number; |
| 18 | +let managerUrl: string; |
| 19 | +
|
| 20 | +onMount(() => { |
| 21 | + userAgent = navigator.userAgent; |
| 22 | + androidVersionMatch = /Android\s([\d.]+)/i.exec(userAgent); |
| 23 | + androidVersion = androidVersionMatch ? parseInt(androidVersionMatch[1]) : 0; |
| 24 | + isAndroid = !!androidVersion; |
| 25 | +}); |
| 26 | +
|
| 27 | +query.subscribe((val) => { |
| 28 | + if (val.data) managerUrl = val.data.assets[0].browser_download_url; |
| 29 | +}); |
| 30 | +
|
| 31 | +function handleClick() { |
| 32 | + if (!isAndroid) { |
| 33 | + warning = "Your device is not running Android."; |
| 34 | + warningDialogue = true; |
| 35 | + } else if (androidVersion < 8) { |
| 36 | + warning = `Your device is running ${androidVersion}. ReVanced Manager only supports Android versions 8 and above.`; |
| 37 | + warningDialogue = true; |
| 38 | + } |
| 39 | +} |
3 | 40 | </script>
|
4 | 41 |
|
| 42 | +<Dialogue bind:modalOpen={warningDialogue}> |
| 43 | + <svelte:fragment slot="title">Device unsupported</svelte:fragment> |
| 44 | + <svelte:fragment slot="description">{warning} Do you still want to download ReVanced Manager?</svelte:fragment> |
| 45 | + <svelte:fragment slot="buttons"> |
| 46 | + <Button |
| 47 | + type="text" |
| 48 | + href={managerUrl} |
| 49 | + on:click={() => (warningDialogue = false)}>Download</Button |
| 50 | + > |
| 51 | + <Button type="text" on:click={() => (warningDialogue = false)}>Cancel</Button> |
| 52 | + </svelte:fragment> |
| 53 | +</Dialogue> |
| 54 | + |
5 | 55 | <section class="hero">
|
6 | 56 | <div class="hero-text">
|
7 | 57 | <h1>Continuing the <br />legacy of <span>Vanced.</span></h1>
|
8 | 58 | <p>
|
9 | 59 | Customize your mobile experience through ReVanced <br /> by applying patches to your applications.
|
10 | 60 | </p>
|
11 | 61 | <div class="hero-buttons">
|
12 |
| - <Button icon="download" type="filled" href="download">Download</Button> |
| 62 | + <Button |
| 63 | + on:click={handleClick} |
| 64 | + type="filled" |
| 65 | + icon="download" |
| 66 | + > |
| 67 | + Download Manager |
| 68 | + </Button> |
13 | 69 | <Button icon="docs" type="tonal" href="patches">View patches</Button>
|
14 | 70 | </div>
|
15 | 71 | </div>
|
|
0 commit comments