From 2ee778c5c6e5a1ea7af5f88a279d3eb31d5b1101 Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Tue, 4 Nov 2025 23:53:44 +0530 Subject: [PATCH] fix: yt-dlp not updating on windows msi install --- src-tauri/capabilities/shell.json | 5 +++++ src-tauri/src/lib.rs | 11 +++++++++++ src/App.tsx | 1 - src/helpers/use-ytdlp-updater.ts | 33 ++++++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src-tauri/capabilities/shell.json b/src-tauri/capabilities/shell.json index 5500902..6623c75 100644 --- a/src-tauri/capabilities/shell.json +++ b/src-tauri/capabilities/shell.json @@ -49,6 +49,11 @@ "name": "pkexec", "cmd": "pkexec", "args": true + }, + { + "name": "powershell", + "cmd": "powershell", + "args": true } ] }, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d354682..6b22edd 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -174,6 +174,16 @@ fn get_config_file_path() -> Result { } } +#[tauri::command] +fn get_current_app_path() -> Result { + let exe_path = std::env::current_exe().map_err(|e| e.to_string())?; + Ok(exe_path + .parent() + .ok_or("Failed to get parent directory")? + .to_string_lossy() + .into_owned()) +} + #[tauri::command] async fn update_config( new_config: Config, @@ -588,6 +598,7 @@ pub async fn run() { reset_config, get_config_file_path, restart_websocket_server, + get_current_app_path, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src/App.tsx b/src/App.tsx index 97b7fc8..6948c9d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1047,7 +1047,6 @@ export default function App({ children }: { children: React.ReactNode }) { const YTDLP_UPDATE_INTERVAL = 86400000 // 24H; if (YTDLP_AUTO_UPDATE && (ytDlpUpdateLastCheck === null || currentTimestamp - ytDlpUpdateLastCheck > YTDLP_UPDATE_INTERVAL)) { console.log("Running auto-update for yt-dlp..."); - LOG.info('NEODLP', 'Updating yt-dlp to latest version (triggered because auto-update is enabled)'); updateYtDlp(); } else { console.log("Skipping yt-dlp auto-update, either disabled or recently updated."); diff --git a/src/helpers/use-ytdlp-updater.ts b/src/helpers/use-ytdlp-updater.ts index 2b56f4d..a50c346 100644 --- a/src/helpers/use-ytdlp-updater.ts +++ b/src/helpers/use-ytdlp-updater.ts @@ -1,7 +1,11 @@ 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 { platform } from "@tauri-apps/plugin-os"; +import { useLogger } from "@/helpers/use-logger"; +import { toast } from "sonner"; export function useYtDlpUpdater() { const { saveKvPair } = useKvPairs(); @@ -9,26 +13,53 @@ export function useYtDlpUpdater() { const setIsUpdatingYtDlp = useSettingsPageStatesStore((state) => state.setIsUpdatingYtDlp); const setYtDlpVersion = useSettingsPageStatesStore((state) => state.setYtDlpVersion); const currentPlatform = platform(); + const LOG = useLogger(); const updateYtDlp = async () => { const CURRENT_TIMESTAMP = Date.now(); setIsUpdatingYtDlp(true); + LOG.info('NEODLP', 'Updating yt-dlp to latest version'); try { const command = currentPlatform === 'linux' ? Command.create('pkexec', ['yt-dlp', '--update-to', ytDlpUpdateChannel]) : Command.sidecar('binaries/yt-dlp', ['--update-to', ytDlpUpdateChannel]); const output = await command.execute(); if (output.code === 0) { console.log("yt-dlp updated successfully:", output.stdout); + LOG.info('NEODLP', "yt-dlp updated successfully"); saveKvPair('ytdlp_update_last_check', CURRENT_TIMESTAMP); setYtDlpVersion(null); + toast.success("Update successful", { description: "yt-dlp has been updated successfully." }); } else { + if (currentPlatform === 'windows') { + LOG.warning('NEODLP', "yt-dlp update failed! Now, attempting with elevated privileges."); + const appPath = await invoke('get_current_app_path'); + const ytdlpPath = await join(appPath, 'yt-dlp.exe'); + const elevateCommand = Command.create('powershell', ['Start-Process', `"${ytdlpPath}"`, '-ArgumentList', `"--update-to ${ytDlpUpdateChannel}"`, '-Verb', 'RunAs', '-Wait', '-WindowStyle', 'Hidden']); + const elevateOutput = await elevateCommand.execute(); + if (elevateOutput.code === 0) { + console.log("yt-dlp updated successfully with elevation:", elevateOutput.stdout); + LOG.info('NEODLP', "yt-dlp updated successfully with elevation"); + saveKvPair('ytdlp_update_last_check', CURRENT_TIMESTAMP); + setYtDlpVersion(null); + toast.success("Update successful", { description: "yt-dlp has been updated successfully." }); + } else { + console.error("Failed to update yt-dlp with elevation:", elevateOutput.stderr); + LOG.error('NEODLP', `Failed to update yt-dlp with elevation: ${elevateOutput.stderr}`); + toast.error("Update failed", { description: "Failed to update yt-dlp." }); + } + return; + } console.error("Failed to update yt-dlp:", output.stderr); + LOG.error('NEODLP', `Failed to update yt-dlp: ${output.stderr}`); + toast.error("Update failed", { description: "Failed to update yt-dlp." }); } } catch (e) { console.error('Failed to update yt-dlp:', e); + LOG.error('NEODLP', `Exception while updating yt-dlp: ${e}`); + toast.error("Update failed", { description: "An error occurred while updating yt-dlp." }); } finally { setIsUpdatingYtDlp(false); } } return { updateYtDlp }; -} \ No newline at end of file +}