From 52dad3acb1ba8aa7038c7a51ac5d69901fce1f3e Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Thu, 5 Mar 2026 22:26:55 +0530 Subject: [PATCH] refactor: install yt-dlp-plugins on XDG_CONFIG_HOME in flatpak --- src-tauri/capabilities/shell.json | 10 +++++ src/App.tsx | 2 +- src/helpers/use-downloader.ts | 4 +- src/helpers/use-linux-registerer.ts | 69 +++++++++++++++-------------- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src-tauri/capabilities/shell.json b/src-tauri/capabilities/shell.json index 5fe39a8..8bfec17 100644 --- a/src-tauri/capabilities/shell.json +++ b/src-tauri/capabilities/shell.json @@ -40,6 +40,11 @@ "args": true, "sidecar": true }, + { + "name": "yt-dlp", + "cmd": "yt-dlp", + "args": true + }, { "name": "ffmpeg", "cmd": "ffmpeg", @@ -105,6 +110,11 @@ "args": true, "sidecar": true }, + { + "name": "yt-dlp", + "cmd": "yt-dlp", + "args": true + }, { "name": "ffmpeg", "cmd": "ffmpeg", diff --git a/src/App.tsx b/src/App.tsx index 62b16b0..a0ceba7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -259,7 +259,7 @@ export default function App({ children }: { children: React.ReactNode }) { try { const isFlatpak = await invoke('is_flatpak'); const command = isFlatpak - ? Command.create('sh', ['-c', `yt-dlp --version`]) + ? Command.create('yt-dlp', [' --version']) : Command.sidecar('binaries/yt-dlp', ['--version']); const output = await command.execute(); if (output.code === 0) { diff --git a/src/helpers/use-downloader.ts b/src/helpers/use-downloader.ts index 1fb44b5..eef8a9c 100644 --- a/src/helpers/use-downloader.ts +++ b/src/helpers/use-downloader.ts @@ -198,7 +198,7 @@ export default function useDownloader() { const isFlatpak = await invoke('is_flatpak'); const command = isFlatpak - ? Command.create('sh', ['-c', `yt-dlp ${args.map(arg => arg.includes(' ') ? `"${arg}"` : arg).join(' ')}`]) + ? Command.create('yt-dlp', args) : Command.sidecar('binaries/yt-dlp', args); let jsonOutput = ''; @@ -562,7 +562,7 @@ export default function useDownloader() { console.log('Starting download with args:', args); const isFlatpak = await invoke('is_flatpak'); const command = isFlatpak - ? Command.create('sh', ['-c', `yt-dlp ${args.map(arg => arg.includes(' ') ? `"${arg}"` : arg).join(' ')}`]) + ? Command.create('yt-dlp', args) : Command.sidecar('binaries/yt-dlp', args); command.on('close', async (data) => { diff --git a/src/helpers/use-linux-registerer.ts b/src/helpers/use-linux-registerer.ts index b63be88..bce81c5 100644 --- a/src/helpers/use-linux-registerer.ts +++ b/src/helpers/use-linux-registerer.ts @@ -2,7 +2,7 @@ import { join, resourceDir, homeDir } from "@tauri-apps/api/path"; import * as fs from "@tauri-apps/plugin-fs"; import { useKvPairs } from "@/helpers/use-kvpairs"; import { useSettingsPageStatesStore } from "@/services/store"; -// import { Command } from "@tauri-apps/plugin-shell"; +import { Command } from "@tauri-apps/plugin-shell"; import { invoke } from "@tauri-apps/api/core"; interface FileMap { @@ -42,42 +42,43 @@ export function useLinuxRegisterer() { { source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' }, ]; - // const filesToCopyFlatpak: FileMap[] = [ - // { source: 'chrome.json', destination: '.config/google-chrome/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/google-chrome/NativeMessagingHosts/', content: JSON.stringify(flatpakChromeManifestContent) }, - // { source: 'chrome.json', destination: '.config/chromium/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/chromium/NativeMessagingHosts/', content: JSON.stringify(flatpakChromeManifestContent) }, - // { source: 'firefox.json', destination: '.mozilla/native-messaging-hosts/com.neosubhamoy.neodlp.json', dir: '.mozilla/native-messaging-hosts/', content: JSON.stringify(flatpakFirefoxManifestContent) }, - // { source: 'neodlp-msghost', destination: '.local/bin/neodlp-msghost', dir: '.local/bin/' }, - // ]; + const filesToCopyFlatpak: FileMap[] = [ + // { source: 'chrome.json', destination: '.config/google-chrome/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/google-chrome/NativeMessagingHosts/', content: JSON.stringify(flatpakChromeManifestContent) }, + // { source: 'chrome.json', destination: '.config/chromium/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/chromium/NativeMessagingHosts/', content: JSON.stringify(flatpakChromeManifestContent) }, + // { source: 'firefox.json', destination: '.mozilla/native-messaging-hosts/com.neosubhamoy.neodlp.json', dir: '.mozilla/native-messaging-hosts/', content: JSON.stringify(flatpakFirefoxManifestContent) }, + // { source: 'neodlp-msghost', destination: '.local/bin/neodlp-msghost', dir: '.local/bin/' }, + { source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', destination: '.var/app/com.neosubhamoy.neodlp/config/yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', dir: '.var/app/com.neosubhamoy.neodlp/config/yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' }, + { source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', destination: '.var/app/com.neosubhamoy.neodlp/config/yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', dir: '.var/app/com.neosubhamoy.neodlp/config/yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' }, + { source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', destination: '.var/app/com.neosubhamoy.neodlp/config/yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', dir: '.var/app/com.neosubhamoy.neodlp/config/yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' }, + ]; if (isFlatpak) { - // Skip registration and just return success in flatpak - console.log('Running in Flatpak, Skipping registration...'); + for (const file of filesToCopyFlatpak) { + const sourcePath = await join(resourceDirPath, file.source); + const destinationDir = await join(homeDirPath, file.dir); + const destinationPath = await join(homeDirPath, file.destination); + const escapedContent = file.content?.replace(/'/g, `'\\''`) || ''; + const copyCommand = Command.create('sh', ['-c', `mkdir -p "${destinationDir}" && cp "${sourcePath}" "${destinationPath}"`]); + const writeCommand = Command.create('sh', ['-c', `printf '%s' '${escapedContent}' > "${destinationPath}"`]); - // for (const file of filesToCopyFlatpak) { - // const sourcePath = await join(resourceDirPath, file.source); - // const destinationPath = await join(homeDirPath, file.destination); - // const escapedContent = file.content?.replace(/'/g, `'\\''`) || ''; - // const copyCommand = Command.create('sh', ['-c', `cp "${sourcePath}" "${destinationPath}"`]); - // const writeCommand = Command.create('sh', ['-c', `printf '%s' '${escapedContent}' > "${destinationPath}"`]); - - // if (file.content) { - // const writeOutput = await writeCommand.execute(); - // if (writeOutput.code === 0) { - // console.log(`File ${file.destination} created successfully at ${destinationPath}`); - // } else { - // console.error(`Failed to create file ${file.destination} at ${destinationPath}:`, writeOutput.stderr); - // return { success: false, message: 'Failed to register' }; - // } - // } else { - // const copyOutput = await copyCommand.execute(); - // if (copyOutput.code === 0) { - // console.log(`File ${file.source} copied successfully to ${destinationPath}`); - // } else { - // console.error(`Failed to copy file ${file.source} to ${destinationPath}:`, copyOutput.stderr); - // return { success: false, message: 'Failed to register' }; - // } - // } - // } + if (file.content) { + const writeOutput = await writeCommand.execute(); + if (writeOutput.code === 0) { + console.log(`File ${file.destination} created successfully at ${destinationPath}`); + } else { + console.error(`Failed to create file ${file.destination} at ${destinationPath}:`, writeOutput.stderr); + return { success: false, message: 'Failed to register' }; + } + } else { + const copyOutput = await copyCommand.execute(); + if (copyOutput.code === 0) { + console.log(`File ${file.source} copied successfully to ${destinationPath}`); + } else { + console.error(`Failed to copy file ${file.source} to ${destinationPath}:`, copyOutput.stderr); + return { success: false, message: 'Failed to register' }; + } + } + } } else { for (const file of filesToCopy) { const sourcePath = await join(resourceDirPath, file.source);