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

Missing client side UpdateExecutable function #227

Merged
merged 1 commit into from
Nov 19, 2024
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
33 changes: 33 additions & 0 deletions frontend/src/components/UpdateBinaryButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Button, CircularProgress } from '@mui/material'
import { useI18n } from '../hooks/useI18n'
import { useRPC } from '../hooks/useRPC'
import { useState } from 'react'
import { useToast } from '../hooks/toast'

const UpdateBinaryButton: React.FC = () => {
const { i18n } = useI18n()
const { client } = useRPC()
const { pushMessage } = useToast()

const [isLoading, setIsLoading] = useState(false)

const updateBinary = () => {
setIsLoading(true)
client
.updateExecutable()
.then(() => pushMessage(i18n.t('toastUpdated'), 'success'))
.then(() => setIsLoading(false))
}

return (
<Button
variant="contained"
endIcon={isLoading ? <CircularProgress size={16} color='secondary' /> : <></>}
onClick={updateBinary}
>
{i18n.t('updateBinButton')}
</Button>
)
}

export default UpdateBinaryButton
7 changes: 7 additions & 0 deletions frontend/src/lib/rpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,11 @@ export class RPCClient {
params: []
})
}

public updateExecutable() {
return this.sendHTTP({
method: 'Service.UpdateExecutable',
params: []
})
}
}
23 changes: 4 additions & 19 deletions frontend/src/views/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Button,
Checkbox,
Container,
FormControl,
Expand All @@ -18,6 +17,7 @@ import {
Typography,
capitalize
} from '@mui/material'
import { useAtom } from 'jotai'
import { Suspense, useEffect, useMemo, useState } from 'react'
import {
Subject,
Expand All @@ -44,11 +44,10 @@ import {
themeState
} from '../atoms/settings'
import CookiesTextField from '../components/CookiesTextField'
import UpdateBinaryButton from '../components/UpdateBinaryButton'
import { useToast } from '../hooks/toast'
import { useI18n } from '../hooks/useI18n'
import { useRPC } from '../hooks/useRPC'
import { validateDomain, validateIP } from '../utils'
import { useAtom } from 'jotai'

// NEED ABSOLUTELY TO BE SPLIT IN MULTIPLE COMPONENTS
export default function Settings() {
Expand All @@ -72,7 +71,6 @@ export default function Settings() {
const [invalidIP, setInvalidIP] = useState(false)

const { i18n } = useI18n()
const { client } = useRPC()

const { pushMessage } = useToast()

Expand Down Expand Up @@ -140,13 +138,6 @@ export default function Settings() {
setTheme(event.target.value as Theme)
}

/**
* Updates yt-dlp binary via RPC
*/
const updateBinary = () => {
client.updateExecutable().then(() => pushMessage(i18n.t('toastUpdated'), 'success'))
}

return (
<Container maxWidth="xl" sx={{ mt: 4, mb: 8 }}>
<Paper
Expand Down Expand Up @@ -352,14 +343,8 @@ export default function Settings() {
</Suspense>
</Grid>
<Grid>
<Stack direction="row">
<Button
sx={{ mr: 1, mt: 3 }}
variant="contained"
onClick={() => updateBinary()}
>
{i18n.t('updateBinButton')}
</Button>
<Stack direction="row" sx={{ pt: 2 }}>
<UpdateBinaryButton />
</Stack>
</Grid>
</Paper>
Expand Down
Loading