Skip to content

Commit

Permalink
Migrate to en var loaded from .env
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Ray committed Aug 17, 2024
1 parent e505bad commit 5bea9f0
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 47 deletions.
2 changes: 2 additions & 0 deletions apps/app/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EXPO_PUBLIC_SIGNALING_URL=ws://localhost:9001
EXPO_PUBLIC_APP_URL=http://localhost:8081
2 changes: 2 additions & 0 deletions apps/app/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EXPO_PUBLIC_SIGNALING_URL=wss://hub.pikatorrent.com
EXPO_PUBLIC_APP_URL=https://app.pikatorrent.com
2 changes: 2 additions & 0 deletions apps/app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ dist/
# @end expo-cli

.tamagui

.env.local
7 changes: 0 additions & 7 deletions apps/app/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ module.exports = function (api) {
return {
presets: ['babel-preset-expo'],
plugins: [
// NOTE: this is required to pass the right environment
[
'transform-inline-environment-variables',
{
include: ['SIGNALING_URL', 'APP_URL', 'APP_VARIANT'],
},
],
// NOTE: this is optional, you don't *need* the compiler
[
'@tamagui/babel-plugin',
Expand Down
9 changes: 5 additions & 4 deletions apps/app/components/screens/settings/Nodes/Nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import {
import { AcceptedOrRejectedPeers } from './AcceptedOrRejectPeers'
import { AddNodeDialog } from '../../../dialogs/AddNodeDialog'
import { SettingLayout } from '../SettingLayout'
import { APP_URL } from '../../../../config'
import { useToastController } from '@tamagui/toast'
import { useLocalNode } from '../../../../hooks/useLocalNode'
import { useI18n } from '../../../../hooks/use18n'
import isElectron from 'is-electron'

const appUrl = process.env.EXPO_PUBLIC_APP_URL

export const Nodes = () => {
const settingsContext = useContext(SettingsContext)
const { settings, updateSettings } = settingsContext
Expand Down Expand Up @@ -179,15 +180,15 @@ const LocalNodeQrcode = () => {
const [isDisplayed, setIsDisplayed] = useState(false)
const [qrCodeXML, setQrCodeXML] = useState(null)
const linkURL = localNode?.settings?.nodeId
? `${APP_URL}/settings?nodeId=${
? `${appUrl}/settings?nodeId=${
localNode?.settings?.nodeId
}&name=${getDeviceName()}`
: null

useEffect(() => {
if (linkURL) {
QRCodeGenerator.toString(encodeURI(linkURL), { type: 'svg' }).then(
setQrCodeXML
setQrCodeXML,
)
}
}, [linkURL])
Expand All @@ -209,7 +210,7 @@ const LocalNodeQrcode = () => {
{i18n.t(
isDisplayed
? 'settings.nodes.hideQRCode'
: 'settings.nodes.showQRCode'
: 'settings.nodes.showQRCode',
)}
</Button>
</XStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Share2 } from '@tamagui/lucide-icons'
import { Button } from 'tamagui'
import { Platform, Share } from 'react-native'
import { useI18n } from '../../../../hooks/use18n'
import { APP_URL } from '../../../../config'

const appUrl = process.env.EXPO_PUBLIC_APP_URL

export const ShareButtons = ({ toast, torrent }) => {
const i18n = useI18n()
Expand All @@ -13,7 +14,7 @@ export const ShareButtons = ({ toast, torrent }) => {
<Button
icon={Share2}
onPress={async () => {
const shareLink = APP_URL + '/add#' + torrent.magnetLink
const shareLink = appUrl + '/add#' + torrent.magnetLink
try {
navigator.clipboard.writeText(shareLink)
toast.show(i18n.t('toasts.linkCopied'))
Expand All @@ -30,7 +31,7 @@ export const ShareButtons = ({ toast, torrent }) => {
<Button
icon={Share2}
onPress={async () => {
const shareLink = APP_URL + '/add#' + torrent.magnetLink
const shareLink = appUrl + '/add#' + torrent.magnetLink
Share.share({
url: shareLink,
message: shareLink,
Expand Down
16 changes: 0 additions & 16 deletions apps/app/config.js

This file was deleted.

8 changes: 6 additions & 2 deletions apps/app/hooks/useWebSocket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useEffect, useRef, useState } from 'react'

import { SIGNALING_URL } from '../config'
const signalingUrl = process.env.EXPO_PUBLIC_SIGNALING_URL

if (!signalingUrl) {
throw new Error('Missing EXPO_PUBLIC_SIGNALING_URL env var')
}

interface UseWebSocketOptions {
clientId: string
Expand Down Expand Up @@ -34,7 +38,7 @@ export const useWebSocket = ({ clientId }: UseWebSocketOptions) => {
// Cleanup any existing instance & listener
close()

wsRef.current = new WebSocket(SIGNALING_URL)
wsRef.current = new WebSocket(signalingUrl)

wsRef.current.addEventListener('error', handleError)
wsRef.current.addEventListener('close', handleClose)
Expand Down
1 change: 0 additions & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"@types/simple-peer": "^9.11.8",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5bea9f0

Please sign in to comment.