mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2026-03-23 12:15:50 +05:30
refactor: added yt-dlp auto update on flatpak
This commit is contained in:
15
src/App.tsx
15
src/App.tsx
@@ -3,7 +3,7 @@ import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { AppContext } from "@/providers/appContextProvider";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { arch, exeExtension } from "@tauri-apps/plugin-os";
|
||||
import { downloadDir, join, resourceDir, tempDir } from "@tauri-apps/api/path";
|
||||
import { downloadDir, join, resourceDir, tempDir, dataDir } from "@tauri-apps/api/path";
|
||||
import { useBasePathsStore, useCurrentVideoMetadataStore, useDownloaderPageStatesStore, useDownloadStatesStore, useEnvironmentStore, useKvPairsStatesStore, useSettingsPageStatesStore } from "@/services/store";
|
||||
import { isObjEmpty} from "@/utils";
|
||||
import { Command } from "@tauri-apps/plugin-shell";
|
||||
@@ -258,8 +258,9 @@ export default function App({ children }: { children: React.ReactNode }) {
|
||||
setIsFetchingYtDlpVersion(true);
|
||||
try {
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
const xdgDataDir = await dataDir();
|
||||
const command = isFlatpak
|
||||
? Command.create('sh', ['-c', `yt-dlp --version`])
|
||||
? Command.create('sh', ['-c', `${xdgDataDir}/pip/bin/yt-dlp --version`])
|
||||
: Command.sidecar('binaries/yt-dlp', ['--version']);
|
||||
const output = await command.execute();
|
||||
if (output.code === 0) {
|
||||
@@ -309,11 +310,11 @@ export default function App({ children }: { children: React.ReactNode }) {
|
||||
console.log("Auto-update check already performed in this session, skipping");
|
||||
return;
|
||||
}
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
if (isFlatpak) {
|
||||
console.log("Flatpak detected! Skipping yt-dlp auto-update");
|
||||
return;
|
||||
}
|
||||
// const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
// if (isFlatpak) {
|
||||
// console.log("Flatpak detected! Skipping yt-dlp auto-update");
|
||||
// return;
|
||||
// }
|
||||
hasRunYtDlpAutoUpdateRef.current = true;
|
||||
console.log("Checking yt-dlp auto-update with loaded config values:", {
|
||||
autoUpdate: YTDLP_AUTO_UPDATE,
|
||||
|
||||
@@ -1842,7 +1842,7 @@ function AppInfoSettings() {
|
||||
<TriangleAlert className="size-4 stroke-primary" />
|
||||
<AlertTitle className="text-sm">Flatpak Sandbox Detected!</AlertTitle>
|
||||
<AlertDescription className="text-xs">
|
||||
It looks like you are running NeoDLP in a Flatpak sandbox. Some features like browser integration, desktop notifications, cookies, po tokens, changing download folder, revealing completed downloads in explorer, automatic yt-dlp updates and auto-launch on startup are not available in Flatpak due to sandbox restrictions. To use these features, please install the native linux build (DEB, RPM or AUR) of NeoDLP.
|
||||
It looks like you are running NeoDLP in a Flatpak sandbox. Some features like browser integration, desktop notifications, cookies, changing download folder, revealing completed downloads in explorer, and auto-launch on startup are not available in Flatpak due to sandbox restrictions. To use these features, please install the native linux build (DEB, RPM or AUR) of NeoDLP.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
) : isAppimage ? (
|
||||
@@ -1933,7 +1933,7 @@ function AppInfoSettings() {
|
||||
}
|
||||
|
||||
export function ApplicationSettings() {
|
||||
const isFlatpak = useEnvironmentStore(state => state.isFlatpak);
|
||||
// const isFlatpak = useEnvironmentStore(state => state.isFlatpak);
|
||||
|
||||
const activeSubAppTab = useSettingsPageStatesStore(state => state.activeSubAppTab);
|
||||
const setActiveSubAppTab = useSettingsPageStatesStore(state => state.setActiveSubAppTab);
|
||||
@@ -1992,14 +1992,14 @@ export function ApplicationSettings() {
|
||||
<Switch
|
||||
id="ytdlp-auto-update"
|
||||
checked={ytDlpAutoUpdate}
|
||||
disabled={isFlatpak}
|
||||
// disabled={isFlatpak}
|
||||
onCheckedChange={(checked) => saveSettingsKey('ytdlp_auto_update', checked)}
|
||||
/>
|
||||
<Label htmlFor="ytdlp-auto-update">Auto Update</Label>
|
||||
</div>
|
||||
<Select
|
||||
value={ytDlpUpdateChannel}
|
||||
disabled={isFlatpak}
|
||||
// disabled={isFlatpak}
|
||||
onValueChange={(value) => saveSettingsKey('ytdlp_update_channel', value)}
|
||||
>
|
||||
<SelectTrigger className="w-37.5 ring-0 focus:ring-0">
|
||||
@@ -2014,7 +2014,7 @@ export function ApplicationSettings() {
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button
|
||||
disabled={ytDlpAutoUpdate || isUpdatingYtDlp || ongoingDownloads.length > 0 || isFlatpak}
|
||||
disabled={ytDlpAutoUpdate || isUpdatingYtDlp || ongoingDownloads.length > 0 /*|| isFlatpak*/}
|
||||
onClick={async () => await updateYtDlp()}
|
||||
>
|
||||
{isUpdatingYtDlp ? (
|
||||
|
||||
@@ -15,6 +15,7 @@ import { sendNotification } from '@tauri-apps/plugin-notification';
|
||||
import { FetchVideoMetadataParams, StartDownloadParams } from "@/providers/appContextProvider";
|
||||
import { useDebouncedCallback } from '@tanstack/react-pacer/debouncer';
|
||||
import { fetchDownloadStateById } from "@/services/database";
|
||||
import { dataDir } from "@tauri-apps/api/path";
|
||||
|
||||
export default function useDownloader() {
|
||||
const globalDownloadStates = useDownloadStatesStore((state) => state.downloadStates);
|
||||
@@ -199,8 +200,9 @@ export default function useDownloader() {
|
||||
}
|
||||
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
const xdgDataDir = await dataDir();
|
||||
const command = isFlatpak
|
||||
? Command.create('sh', ['-c', `yt-dlp ${args.map(arg => `'${arg.replace(/'/g, "'\\''")}'`).join(' ')}`])
|
||||
? Command.create('sh', ['-c', `${xdgDataDir}/pip/bin/yt-dlp ${args.map(arg => `'${arg.replace(/'/g, "'\\''")}'`).join(' ')}`])
|
||||
: Command.sidecar('binaries/yt-dlp', args);
|
||||
|
||||
let jsonOutput = '';
|
||||
@@ -569,8 +571,9 @@ export default function useDownloader() {
|
||||
|
||||
console.log('Starting download with args:', args);
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
const xdgDataDir = await dataDir();
|
||||
const command = isFlatpak
|
||||
? Command.create('sh', ['-c', `yt-dlp ${args.map(arg => `'${arg.replace(/'/g, "'\\''")}'`).join(' ')}`])
|
||||
? Command.create('sh', ['-c', `${xdgDataDir}/pip/bin/yt-dlp ${args.map(arg => `'${arg.replace(/'/g, "'\\''")}'`).join(' ')}`])
|
||||
: Command.sidecar('binaries/yt-dlp', args);
|
||||
|
||||
command.on('close', async (data) => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useSettingsPageStatesStore } from "@/services/store";
|
||||
import { useKvPairs } from "@/helpers/use-kvpairs";
|
||||
import { Command } from "@tauri-apps/plugin-shell";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { join } from "@tauri-apps/api/path";
|
||||
import { join, dataDir } from "@tauri-apps/api/path";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { useLogger } from "@/helpers/use-logger";
|
||||
import { toast } from "sonner";
|
||||
@@ -18,13 +18,14 @@ export function useYtDlpUpdater() {
|
||||
const updateYtDlp = async () => {
|
||||
const CURRENT_TIMESTAMP = Date.now();
|
||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||
const xdgDataDir = await dataDir();
|
||||
setIsUpdatingYtDlp(true);
|
||||
LOG.info('NEODLP', 'Updating yt-dlp to latest version');
|
||||
try {
|
||||
const command = currentPlatform === 'linux' && isFlatpak
|
||||
? ytDlpUpdateChannel === 'nightly'
|
||||
? Command.create('sh', ['-c', 'pip3 install -U --pre "yt-dlp[default,curl-cffi]"'])
|
||||
: Command.create('sh', ['-c', 'pip3 install -U "yt-dlp[default,curl-cffi]"'])
|
||||
? Command.create('sh', ['-c', `PYTHONUSERBASE=${xdgDataDir}/pip pip3 install --user --upgrade --pre "yt-dlp[default,curl-cffi]"`])
|
||||
: Command.create('sh', ['-c', `PYTHONUSERBASE=${xdgDataDir}/pip pip3 install --user --upgrade "yt-dlp[default,curl-cffi]"`])
|
||||
: currentPlatform === 'linux'
|
||||
? Command.create('pkexec', ['yt-dlp', '--update-to', ytDlpUpdateChannel])
|
||||
: Command.sidecar('binaries/yt-dlp', ['--update-to', ytDlpUpdateChannel]);
|
||||
|
||||
Reference in New Issue
Block a user