mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2025-12-19 17:52:59 +05:30
fix: yt-dlp not updating on windows msi install
This commit is contained in:
@@ -49,6 +49,11 @@
|
|||||||
"name": "pkexec",
|
"name": "pkexec",
|
||||||
"cmd": "pkexec",
|
"cmd": "pkexec",
|
||||||
"args": true
|
"args": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "powershell",
|
||||||
|
"cmd": "powershell",
|
||||||
|
"args": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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]
|
#[tauri::command]
|
||||||
async fn update_config(
|
async fn update_config(
|
||||||
new_config: Config,
|
new_config: Config,
|
||||||
@@ -588,6 +598,7 @@ pub async fn run() {
|
|||||||
reset_config,
|
reset_config,
|
||||||
get_config_file_path,
|
get_config_file_path,
|
||||||
restart_websocket_server,
|
restart_websocket_server,
|
||||||
|
get_current_app_path,
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|||||||
@@ -1047,7 +1047,6 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
const YTDLP_UPDATE_INTERVAL = 86400000 // 24H;
|
const YTDLP_UPDATE_INTERVAL = 86400000 // 24H;
|
||||||
if (YTDLP_AUTO_UPDATE && (ytDlpUpdateLastCheck === null || currentTimestamp - ytDlpUpdateLastCheck > YTDLP_UPDATE_INTERVAL)) {
|
if (YTDLP_AUTO_UPDATE && (ytDlpUpdateLastCheck === null || currentTimestamp - ytDlpUpdateLastCheck > YTDLP_UPDATE_INTERVAL)) {
|
||||||
console.log("Running auto-update for yt-dlp...");
|
console.log("Running auto-update for yt-dlp...");
|
||||||
LOG.info('NEODLP', 'Updating yt-dlp to latest version (triggered because auto-update is enabled)');
|
|
||||||
updateYtDlp();
|
updateYtDlp();
|
||||||
} else {
|
} else {
|
||||||
console.log("Skipping yt-dlp auto-update, either disabled or recently updated.");
|
console.log("Skipping yt-dlp auto-update, either disabled or recently updated.");
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { useSettingsPageStatesStore } from "@/services/store";
|
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 { join } 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 { toast } from "sonner";
|
||||||
|
|
||||||
export function useYtDlpUpdater() {
|
export function useYtDlpUpdater() {
|
||||||
const { saveKvPair } = useKvPairs();
|
const { saveKvPair } = useKvPairs();
|
||||||
@@ -9,22 +13,49 @@ export function useYtDlpUpdater() {
|
|||||||
const setIsUpdatingYtDlp = useSettingsPageStatesStore((state) => state.setIsUpdatingYtDlp);
|
const setIsUpdatingYtDlp = useSettingsPageStatesStore((state) => state.setIsUpdatingYtDlp);
|
||||||
const setYtDlpVersion = useSettingsPageStatesStore((state) => state.setYtDlpVersion);
|
const setYtDlpVersion = useSettingsPageStatesStore((state) => state.setYtDlpVersion);
|
||||||
const currentPlatform = platform();
|
const currentPlatform = platform();
|
||||||
|
const LOG = useLogger();
|
||||||
|
|
||||||
const updateYtDlp = async () => {
|
const updateYtDlp = async () => {
|
||||||
const CURRENT_TIMESTAMP = Date.now();
|
const CURRENT_TIMESTAMP = Date.now();
|
||||||
setIsUpdatingYtDlp(true);
|
setIsUpdatingYtDlp(true);
|
||||||
|
LOG.info('NEODLP', 'Updating yt-dlp to latest version');
|
||||||
try {
|
try {
|
||||||
const command = currentPlatform === 'linux' ? Command.create('pkexec', ['yt-dlp', '--update-to', ytDlpUpdateChannel]) : Command.sidecar('binaries/yt-dlp', ['--update-to', ytDlpUpdateChannel]);
|
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();
|
const output = await command.execute();
|
||||||
if (output.code === 0) {
|
if (output.code === 0) {
|
||||||
console.log("yt-dlp updated successfully:", output.stdout);
|
console.log("yt-dlp updated successfully:", output.stdout);
|
||||||
|
LOG.info('NEODLP', "yt-dlp updated successfully");
|
||||||
saveKvPair('ytdlp_update_last_check', CURRENT_TIMESTAMP);
|
saveKvPair('ytdlp_update_last_check', CURRENT_TIMESTAMP);
|
||||||
setYtDlpVersion(null);
|
setYtDlpVersion(null);
|
||||||
|
toast.success("Update successful", { description: "yt-dlp has been updated successfully." });
|
||||||
} else {
|
} 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);
|
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) {
|
} catch (e) {
|
||||||
console.error('Failed to update yt-dlp:', 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 {
|
} finally {
|
||||||
setIsUpdatingYtDlp(false);
|
setIsUpdatingYtDlp(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user