it just works

This commit is contained in:
2023-01-12 23:18:50 +01:00
parent f8091b6d14
commit 5e3a40baf4
4 changed files with 18 additions and 6 deletions

View File

@@ -74,9 +74,12 @@ export default function Home({ socket }: Props) {
}, []) }, [])
useEffect(() => { useEffect(() => {
if (status.connected) {
client.running()
const interval = setInterval(() => client.running(), 1000) const interval = setInterval(() => client.running(), 1000)
return () => clearInterval(interval) return () => clearInterval(interval)
}, []) }
}, [status.connected])
useEffect(() => { useEffect(() => {
client.freeSpace() client.freeSpace()
@@ -89,7 +92,7 @@ export default function Home({ socket }: Props) {
switch (typeof res.result) { switch (typeof res.result) {
case 'object': case 'object':
setActiveDownloads( setActiveDownloads(
res.result (res.result ?? [])
.filter((r: RPCResult) => !!r.info.url) .filter((r: RPCResult) => !!r.info.url)
.sort((a: RPCResult, b: RPCResult) => a.info.title.localeCompare(b.info.title)) .sort((a: RPCResult, b: RPCResult) => a.info.title.localeCompare(b.info.title))
) )

View File

@@ -1,6 +1,7 @@
export type RPCMethods = export type RPCMethods =
| "Service.Exec" | "Service.Exec"
| "Service.Kill" | "Service.Kill"
| "Service.Clear"
| "Service.Running" | "Service.Running"
| "Service.KillAll" | "Service.KillAll"
| "Service.FreeSpace" | "Service.FreeSpace"

View File

@@ -167,6 +167,7 @@ func (p *Process) Complete() {
// Kill a process and remove it from the memory // Kill a process and remove it from the memory
func (p *Process) Kill() error { func (p *Process) Kill() error {
p.mem.Delete(p.id)
// yt-dlp uses multiple child process the parent process // yt-dlp uses multiple child process the parent process
// has been spawned with setPgid = true. To properly kill // has been spawned with setPgid = true. To properly kill
// all subprocesses a SIGTERM need to be sent to the correct // all subprocesses a SIGTERM need to be sent to the correct
@@ -176,8 +177,8 @@ func (p *Process) Kill() error {
return err return err
} }
err = syscall.Kill(-pgid, syscall.SIGTERM) err = syscall.Kill(-pgid, syscall.SIGTERM)
p.mem.Delete(p.id)
log.Printf("Killed process %s\n", p.id) log.Println("Killed process", p.id)
return err return err
} }

View File

@@ -90,6 +90,13 @@ func (t *Service) KillAll(args NoArgs, killed *string) error {
return err return err
} }
// Remove a process from the db rendering it unusable if active
func (t *Service) Clear(args string, killed *string) error {
log.Println("Clearing process with id", args)
db.Delete(args)
return nil
}
// FreeSpace gets the available from package sys util // FreeSpace gets the available from package sys util
func (t *Service) FreeSpace(args NoArgs, free *uint64) error { func (t *Service) FreeSpace(args NoArgs, free *uint64) error {
freeSpace, err := sys.FreeSpace() freeSpace, err := sys.FreeSpace()