fix: yt-dlp not updating on windows msi install

This commit is contained in:
2025-11-04 23:53:44 +05:30
parent 2ea008126e
commit 2ee778c5c6
4 changed files with 48 additions and 2 deletions

View File

@@ -49,6 +49,11 @@
"name": "pkexec",
"cmd": "pkexec",
"args": true
},
{
"name": "powershell",
"cmd": "powershell",
"args": true
}
]
},

View File

@@ -174,6 +174,16 @@ fn get_config_file_path() -> Result<String, String> {
}
}
#[tauri::command]
fn get_current_app_path() -> Result<String, String> {
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");

View File

@@ -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.");

View File

@@ -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<string>('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 };
}
}