Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add mobile links #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

59 changes: 43 additions & 16 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,60 @@
name: Pages
name: Deploy

on:
push:
branches:
- 'main'
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
pages: write
id-token: write

jobs:
pages:
build:
runs-on: ubuntu-latest
environment: github_pages
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Enable corepack
run: corepack enable pnpm

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Setup node env
uses: actions/setup-node@v3
- name: Restore cache
uses: actions/cache@v4
with:
node-version: '16.20.0'
path: |
dist
.nuxt
key: ${{ runner.os }}-nuxt-build-${{ hashFiles('dist') }}
restore-keys: |
${{ runner.os }}-nuxt-build-

- name: Install Dependencies
run: yarn
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Generate
run: yarn generate
- name: Static HTML export with Nuxt
run: pnpm run generate

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: .output/public
cname: mywitwallet.com
path: ./dist

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist
.DS_Store
assets/.DS_Store
assets/svg/.DS_Store
docs/** */
37 changes: 37 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Ignore build output directories
.nuxt/
dist/
./docs/** */
./docs/_nuxt/** */
DEBUG=1/** */

# Ignore node modules
node_modules/

# Ignore specific configuration files
*.config.js

# Ignore environment variables files
.env
.env.*

# Ignore lock files
yarn.lock
package-lock.json

# Ignore logs
*.log

# Ignore compiled files
*.min.js
*.min.css

# Ignore specific file types
*.png
*.jpg
*.jpeg
*.gif
*.svg

# Ignore other generated files
coverage/
59 changes: 47 additions & 12 deletions components/DownloadBtn.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
<template>
<a
v-if="release.platform"
v-if="releaseContent && releaseContent.downloadName"
class="link"
:href="release.releaseUrl"
:href="releaseContent.releaseUrl"
target="_blank"
:download="release.downloadName"
:download="releaseContent.downloadName"
>
<ElButton class="btn" type="primary">
<i18n-t keypath="download" tag="span">
<button class="btn">
<i18n-t keypath="downloadLink" tag="span">
<template #platform>
<span>{{ release.platform }}</span>
<span>{{ releaseContent.platform }}</span>
</template>
</i18n-t>
</ElButton>
</button>
</a>
<a
v-else
class="link"
href="https://github.com/witnet/my-wit-wallet/releases/latest"
:href="releaseContent ? releaseContent.releaseUrl : GITHUB_RELEASE_URL"
>
<ElButton class="btn" type="primary">{{ $t('head.title') }}</ElButton>
<button class="btn">
<i18n-t v-if="releaseContent" keypath="downloadLink" tag="span">
<template #platform>
<span>{{ releaseContent?.platform }}</span>
</template>
</i18n-t>
<span v-else>{{ t('githubLink') }}</span>
</button>
</a>
</template>

<script setup>
import { getLatestRelease } from '../getLatestRelease'
const release = await getLatestRelease(navigator)
import { getLatestRelease, getStoreRelease } from '@/getLatestRelease'
import { getBrowserOs } from '@/getBrowserOs'
import { useI18n } from 'vue-i18n'
import { GITHUB_RELEASE_URL } from '@/constants'
import { onMounted, ref } from 'vue'
const { t } = useI18n()

const releaseContent = ref(null)

onMounted(async () => {
releaseContent.value = await release()
})

async function release() {
const os = getBrowserOs(navigator)
const storeRelease = getStoreRelease({ os })
if (!os) {
return null
}
if (storeRelease) {
return storeRelease
}
return await getLatestRelease({ os })
}
</script>

<style></style>
<style lang="scss">
.link {
width: max-content;
height: auto;
display: flex;
}
</style>
2 changes: 2 additions & 0 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const languages = [
export const fallbackLocale = 'en'

export const DEFAULT_OS = 'Linux'
export const GITHUB_RELEASE_URL =
'https://github.com/witnet/sheikah/releases/latest'

export const URL_RELEASE_BASE =
'https://api.github.com/repos/witnet/my-wit-wallet/releases/latest'
34 changes: 34 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import globals from 'globals'
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginVue from "eslint-plugin-vue";
import eslintConfigPrettier from "eslint-config-prettier";
// eslint.config.js
export default [
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...pluginVue.configs["flat/essential"],
eslintConfigPrettier,
{
ignores: ['node_modules', 'dist', 'public', '.nuxt', 'docs/**/*', 'DEBUG=1/**/*'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ignores: ['node_modules', 'dist', 'public', '.nuxt', 'docs/**/*', 'DEBUG=1/**/*'],
ignores: ['node_modules', 'dist', 'public', '.nuxt', 'docs/**/*', '.output'],

},
{
files: ['pages/*.vue'],
rules: {
'vue/multi-word-component-names': 0,
},
},
{
files: ['**/*.vue', '**/*.ts'],
languageOptions: {
globals: {
...globals.browser,
...globals.node
},
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
},
},
]
34 changes: 29 additions & 5 deletions getBrowserOs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
import { DEFAULT_OS } from './constants'
export function getBrowserOs(navigator: Navigator) {
return navigator.userAgentData?.platform
? detectPlatformWithUserAgentData(navigator)
: detectPlatform(navigator)
}

const detectPlatformWithUserAgentData = (navigator: Navigator) => {
const userAgentData: NavigatorUAData | undefined = navigator.userAgentData
return userAgentData?.platform.toLowerCase()
}

export function getBrowserOs(navigator: any) {
const supportedOs = ['Win', 'Mac', 'Linux', 'MacIntel']
const platform = navigator.platform
return supportedOs.find((os) => platform.includes(os)) || DEFAULT_OS
const detectPlatform = (navigator: Navigator): string | undefined => {
const ua = navigator.userAgent.toLowerCase().replace(/^mozilla\/\d\.\d\W/, '')
const mobiles: Record<string, RegExp> = {
iphone: /iphone/,
ipad: /ipad|macintosh/,
android: /android/,
}
const desktops: Record<string, RegExp> = {
windows: /win/,
macos: /macintosh/,
linux: /linux/,
}
// Determine the operating system
const mobileOS = Object.keys(mobiles).find(
(os) => mobiles[os].test(ua) && navigator.maxTouchPoints >= 1,
)
const desktopOS = Object.keys(desktops).find((os) => desktops[os].test(ua))
const os = mobileOS || desktopOS
return os
}
83 changes: 61 additions & 22 deletions getLatestRelease.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,78 @@
import axios from 'axios'
import { URL_RELEASE_BASE } from './constants'
import { getBrowserOs } from '@/getBrowserOs'
import { GITHUB_RELEASE_URL, URL_RELEASE_BASE } from './constants'

type Release = {
platform: String
releaseUrl: String
downloadName: String
platform: string
releaseUrl: string
downloadName: string | null
}

export async function getLatestRelease(navigator: any): Promise<Release> {
return await axios.get(URL_RELEASE_BASE).then(async (result: any) => {
const os = await getBrowserOs(navigator).toLowerCase()
const macRelease = await result.data.assets.find((asset: any) => {
return asset.browser_download_url.includes('myWitWallet.dmg')
})
const linuxRelease = await result.data.assets.find((asset: any) =>
asset.browser_download_url.includes('linux.tar.gz')
)
type LatestReleaseResponse = {
assets: []
}

type ReleaseAsset = {
browser_download_url: string
name: string | null
}

export function getStoreRelease({ os }: { os: string }): Release | undefined {
const iosLink = {
platform: 'iOS',
releaseUrl: 'https://apps.apple.com/cl/app/mywitwallet/id6449979271',
downloadName: null,
}
const storeReleases: Record<string, Release> = {
iphone: iosLink,
ipad: iosLink,
android: {
platform: 'Android',
releaseUrl:
'https://play.google.com/store/apps/details?id=io.witnet.myWitWallet&hl=es_419&pli=1',
downloadName: null,
},
windows: {
platform: 'Windows',
releaseUrl: 'https://apps.microsoft.com/detail/9PN09DKWPL57',
downloadName: null,
},
}
if (storeReleases[os]) {
return storeReleases[os]
}
}

const { data }: { data: Ref<LatestReleaseResponse | undefined> } =
await useAsyncData('release', () => $fetch(URL_RELEASE_BASE))

export async function getLatestRelease({
os,
}: {
os: string
}): Promise<Release | null> {
if (data.value) {
const macRelease: ReleaseAsset = data.value.assets.find(
(asset: ReleaseAsset) => {
return asset.browser_download_url.includes('myWitWallet.dmg')
},
) ?? { browser_download_url: GITHUB_RELEASE_URL, name: null }
const linuxRelease: ReleaseAsset = data.value.assets.find(
(asset: ReleaseAsset) =>
asset.browser_download_url.includes('linux.tar.gz'),
) ?? { browser_download_url: GITHUB_RELEASE_URL, name: null }

const release: Record<string, Release> = {
linux: {
platform: 'GNU / Linux',
releaseUrl: linuxRelease.browser_download_url,
downloadName: linuxRelease.name,
},
win: {
platform: 'Windows',
releaseUrl: 'https://apps.microsoft.com/detail/9PN09DKWPL57',
downloadName: 'myWitWallet',
},
mac: {
macos: {
platform: 'Mac OS',
releaseUrl: macRelease.browser_download_url,
downloadName: macRelease.name,
},
}
return release[os]
})
}
return null
}
Loading