Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 33 additions & 1 deletion src/components/Modal/contents/DownloadOurAppModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,35 @@ import {
ModalFlex
} from './styled'
import Image from '../../atoms/Image'
import { getAppLinkFromUserAgent } from '../../../lib/download'
import { openNew } from '../../../lib/utils/platform'
import isElectron from 'is-electron'

interface PrimaryLinkProps {
children: string
}

const DownloadOurAppModal = () => {
const runningOnElectron = isElectron()
const userAgent = getAppLinkFromUserAgent()

const AppLink = ({ children }: PrimaryLinkProps) => {
const handleClick = (event: React.MouseEvent) => {
event.preventDefault()
openNew(runningOnElectron ? 'https://note.boostio.co' : userAgent.link)
}

return (
<button
className='button'
disabled={!runningOnElectron && userAgent.link == null}
onClick={handleClick}
>
{children}
</button>
)
}

return (
<ModalContainer>
<ModalHeader>Download our apps</ModalHeader>
Expand All @@ -19,7 +46,12 @@ const DownloadOurAppModal = () => {
<ModalFlex>
<div className='center'>
<Image src='/app/static/Desktop.svg' />
<button className='button'>Download for Mac</button>
<img src='/app/static/Desktop.svg' />
<AppLink>
{`Download ${
userAgent.os !== '' ? `for ${userAgent.os}` : 'our app'
}`}
</AppLink>
</div>
<div className='center'>
<Image src='/app/static/Mobile.svg' />
Expand Down
25 changes: 25 additions & 0 deletions src/lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,28 @@ export function downloadBlob(blob: Blob, fileName: string) {
window.URL.revokeObjectURL(anchor.href)
document.body.removeChild(anchor)
}

export function getAppLinkFromUserAgent() {
const userAgent = navigator.userAgent
const download = {
os: '',
link: ''
}

if (userAgent.indexOf('Windows') != -1) {
download.os = 'Windows'
download.link =
'https://github.com/BoostIO/BoostNote.next/releases/latest/download/boost-note-win.exe'
}
if (userAgent.indexOf('Mac') != -1) {
download.os = 'Mac'
download.link =
'https://github.com/BoostIO/BoostNote.next/releases/latest/download/boost-note-mac.dmg'
}
if (userAgent.indexOf('Linux') != -1) {
download.os = 'Linux'
download.link =
'https://github.com/BoostIO/BoostNote.next/releases/latest/download/boost-note-linux.deb'
}
return download
}