mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2026-03-23 13:25: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 { AppContext } from "@/providers/appContextProvider";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { arch, exeExtension } from "@tauri-apps/plugin-os";
|
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 { useBasePathsStore, useCurrentVideoMetadataStore, useDownloaderPageStatesStore, useDownloadStatesStore, useEnvironmentStore, useKvPairsStatesStore, useSettingsPageStatesStore } from "@/services/store";
|
||||||
import { isObjEmpty} from "@/utils";
|
import { isObjEmpty} from "@/utils";
|
||||||
import { Command } from "@tauri-apps/plugin-shell";
|
import { Command } from "@tauri-apps/plugin-shell";
|
||||||
@@ -258,8 +258,9 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
setIsFetchingYtDlpVersion(true);
|
setIsFetchingYtDlpVersion(true);
|
||||||
try {
|
try {
|
||||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
|
const xdgDataDir = await dataDir();
|
||||||
const command = isFlatpak
|
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']);
|
: Command.sidecar('binaries/yt-dlp', ['--version']);
|
||||||
const output = await command.execute();
|
const output = await command.execute();
|
||||||
if (output.code === 0) {
|
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");
|
console.log("Auto-update check already performed in this session, skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
// const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
if (isFlatpak) {
|
// if (isFlatpak) {
|
||||||
console.log("Flatpak detected! Skipping yt-dlp auto-update");
|
// console.log("Flatpak detected! Skipping yt-dlp auto-update");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
hasRunYtDlpAutoUpdateRef.current = true;
|
hasRunYtDlpAutoUpdateRef.current = true;
|
||||||
console.log("Checking yt-dlp auto-update with loaded config values:", {
|
console.log("Checking yt-dlp auto-update with loaded config values:", {
|
||||||
autoUpdate: YTDLP_AUTO_UPDATE,
|
autoUpdate: YTDLP_AUTO_UPDATE,
|
||||||
|
|||||||
@@ -1842,7 +1842,7 @@ function AppInfoSettings() {
|
|||||||
<TriangleAlert className="size-4 stroke-primary" />
|
<TriangleAlert className="size-4 stroke-primary" />
|
||||||
<AlertTitle className="text-sm">Flatpak Sandbox Detected!</AlertTitle>
|
<AlertTitle className="text-sm">Flatpak Sandbox Detected!</AlertTitle>
|
||||||
<AlertDescription className="text-xs">
|
<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>
|
</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
) : isAppimage ? (
|
) : isAppimage ? (
|
||||||
@@ -1933,7 +1933,7 @@ function AppInfoSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ApplicationSettings() {
|
export function ApplicationSettings() {
|
||||||
const isFlatpak = useEnvironmentStore(state => state.isFlatpak);
|
// const isFlatpak = useEnvironmentStore(state => state.isFlatpak);
|
||||||
|
|
||||||
const activeSubAppTab = useSettingsPageStatesStore(state => state.activeSubAppTab);
|
const activeSubAppTab = useSettingsPageStatesStore(state => state.activeSubAppTab);
|
||||||
const setActiveSubAppTab = useSettingsPageStatesStore(state => state.setActiveSubAppTab);
|
const setActiveSubAppTab = useSettingsPageStatesStore(state => state.setActiveSubAppTab);
|
||||||
@@ -1992,14 +1992,14 @@ export function ApplicationSettings() {
|
|||||||
<Switch
|
<Switch
|
||||||
id="ytdlp-auto-update"
|
id="ytdlp-auto-update"
|
||||||
checked={ytDlpAutoUpdate}
|
checked={ytDlpAutoUpdate}
|
||||||
disabled={isFlatpak}
|
// disabled={isFlatpak}
|
||||||
onCheckedChange={(checked) => saveSettingsKey('ytdlp_auto_update', checked)}
|
onCheckedChange={(checked) => saveSettingsKey('ytdlp_auto_update', checked)}
|
||||||
/>
|
/>
|
||||||
<Label htmlFor="ytdlp-auto-update">Auto Update</Label>
|
<Label htmlFor="ytdlp-auto-update">Auto Update</Label>
|
||||||
</div>
|
</div>
|
||||||
<Select
|
<Select
|
||||||
value={ytDlpUpdateChannel}
|
value={ytDlpUpdateChannel}
|
||||||
disabled={isFlatpak}
|
// disabled={isFlatpak}
|
||||||
onValueChange={(value) => saveSettingsKey('ytdlp_update_channel', value)}
|
onValueChange={(value) => saveSettingsKey('ytdlp_update_channel', value)}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-37.5 ring-0 focus:ring-0">
|
<SelectTrigger className="w-37.5 ring-0 focus:ring-0">
|
||||||
@@ -2014,7 +2014,7 @@ export function ApplicationSettings() {
|
|||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<Button
|
<Button
|
||||||
disabled={ytDlpAutoUpdate || isUpdatingYtDlp || ongoingDownloads.length > 0 || isFlatpak}
|
disabled={ytDlpAutoUpdate || isUpdatingYtDlp || ongoingDownloads.length > 0 /*|| isFlatpak*/}
|
||||||
onClick={async () => await updateYtDlp()}
|
onClick={async () => await updateYtDlp()}
|
||||||
>
|
>
|
||||||
{isUpdatingYtDlp ? (
|
{isUpdatingYtDlp ? (
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { sendNotification } from '@tauri-apps/plugin-notification';
|
|||||||
import { FetchVideoMetadataParams, StartDownloadParams } from "@/providers/appContextProvider";
|
import { FetchVideoMetadataParams, StartDownloadParams } from "@/providers/appContextProvider";
|
||||||
import { useDebouncedCallback } from '@tanstack/react-pacer/debouncer';
|
import { useDebouncedCallback } from '@tanstack/react-pacer/debouncer';
|
||||||
import { fetchDownloadStateById } from "@/services/database";
|
import { fetchDownloadStateById } from "@/services/database";
|
||||||
|
import { dataDir } from "@tauri-apps/api/path";
|
||||||
|
|
||||||
export default function useDownloader() {
|
export default function useDownloader() {
|
||||||
const globalDownloadStates = useDownloadStatesStore((state) => state.downloadStates);
|
const globalDownloadStates = useDownloadStatesStore((state) => state.downloadStates);
|
||||||
@@ -199,8 +200,9 @@ export default function useDownloader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
|
const xdgDataDir = await dataDir();
|
||||||
const command = isFlatpak
|
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.sidecar('binaries/yt-dlp', args);
|
||||||
|
|
||||||
let jsonOutput = '';
|
let jsonOutput = '';
|
||||||
@@ -569,8 +571,9 @@ export default function useDownloader() {
|
|||||||
|
|
||||||
console.log('Starting download with args:', args);
|
console.log('Starting download with args:', args);
|
||||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
|
const xdgDataDir = await dataDir();
|
||||||
const command = isFlatpak
|
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.sidecar('binaries/yt-dlp', args);
|
||||||
|
|
||||||
command.on('close', async (data) => {
|
command.on('close', async (data) => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useSettingsPageStatesStore } from "@/services/store";
|
|||||||
import { useKvPairs } from "@/helpers/use-kvpairs";
|
import { useKvPairs } from "@/helpers/use-kvpairs";
|
||||||
import { Command } from "@tauri-apps/plugin-shell";
|
import { Command } from "@tauri-apps/plugin-shell";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
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 { platform } from "@tauri-apps/plugin-os";
|
||||||
import { useLogger } from "@/helpers/use-logger";
|
import { useLogger } from "@/helpers/use-logger";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
@@ -18,13 +18,14 @@ export function useYtDlpUpdater() {
|
|||||||
const updateYtDlp = async () => {
|
const updateYtDlp = async () => {
|
||||||
const CURRENT_TIMESTAMP = Date.now();
|
const CURRENT_TIMESTAMP = Date.now();
|
||||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
|
const xdgDataDir = await dataDir();
|
||||||
setIsUpdatingYtDlp(true);
|
setIsUpdatingYtDlp(true);
|
||||||
LOG.info('NEODLP', 'Updating yt-dlp to latest version');
|
LOG.info('NEODLP', 'Updating yt-dlp to latest version');
|
||||||
try {
|
try {
|
||||||
const command = currentPlatform === 'linux' && isFlatpak
|
const command = currentPlatform === 'linux' && isFlatpak
|
||||||
? ytDlpUpdateChannel === 'nightly'
|
? ytDlpUpdateChannel === 'nightly'
|
||||||
? Command.create('sh', ['-c', 'pip3 install -U --pre "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', 'pip3 install -U "yt-dlp[default,curl-cffi]"'])
|
: Command.create('sh', ['-c', `PYTHONUSERBASE=${xdgDataDir}/pip pip3 install --user --upgrade "yt-dlp[default,curl-cffi]"`])
|
||||||
: currentPlatform === 'linux'
|
: currentPlatform === 'linux'
|
||||||
? Command.create('pkexec', ['yt-dlp', '--update-to', ytDlpUpdateChannel])
|
? Command.create('pkexec', ['yt-dlp', '--update-to', ytDlpUpdateChannel])
|
||||||
: Command.sidecar('binaries/yt-dlp', ['--update-to', ytDlpUpdateChannel]);
|
: Command.sidecar('binaries/yt-dlp', ['--update-to', ytDlpUpdateChannel]);
|
||||||
|
|||||||
Reference in New Issue
Block a user