From 1ff32ca021e558324406e0268002112473c7b46b Mon Sep 17 00:00:00 2001 From: MasterAcnolo Date: Sat, 25 Jul 2026 11:32:48 +0200 Subject: [PATCH] sync: to work on windows --- main.js | 4 ++- server/helpers/path.helpers.js | 65 +++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/main.js b/main.js index 7d64f79..47cc446 100644 --- a/main.js +++ b/main.js @@ -79,7 +79,7 @@ const { updateYtDlp } = require("./app/ytDlpUpdater"); const { createMainWindow, getMainWindow } = require("./app/windowManager"); const { registerIpcHandlers } = require("./app/ipcHandlers"); const { createSplashWindow, closeSplashWindow, setSplashProgress } = require("./app/splashManager"); -const { userThemesPath, initUserThemes, isWindows } = require("./server/helpers/path.helpers"); +const { userThemesPath, initUserThemes, isWindows, validateBinaries } = require("./server/helpers/path.helpers"); /** @@ -117,6 +117,8 @@ app.whenReady().then(async () => { setSplashProgress(2); // Loading themes + validateBinaries(); + initUserThemes(); await initThemes(userThemesPath); diff --git a/server/helpers/path.helpers.js b/server/helpers/path.helpers.js index 81625dc..9657baa 100644 --- a/server/helpers/path.helpers.js +++ b/server/helpers/path.helpers.js @@ -164,7 +164,7 @@ function initUserThemes() { if (!fs.existsSync(userThemesPath)) { fs.mkdirSync(userThemesPath, { recursive: true }); fs.chmodSync(userThemesPath, 0o777); - getLogger().info("Created user themes directory"); + getLogger().info("Created user themes directory"); } if (fs.existsSync(defaultThemesSourcePath)) { @@ -172,27 +172,37 @@ function initUserThemes() { for (const theme of defaultThemes) { const srcPath = path.join(defaultThemesSourcePath, theme); const destPath = path.join(userThemesPath, theme); + const srcIsFile = !fs.statSync(srcPath).isDirectory(); - if (!fs.existsSync(destPath)) { - try { - if (fs.statSync(srcPath).isDirectory()) { - copyDirectory(srcPath, destPath); - fs.chmodSync(destPath, 0o777); - } else { - fs.copyFileSync(srcPath, destPath); - fs.chmodSync(destPath, 0o666); - } - getLogger().info(`Copied default theme: ${theme}`); - } catch (copyErr) { - getLogger().warn(`Failed to copy theme ${theme}: ${copyErr.message}`); + if (fs.existsSync(destPath)) { + const destIsDir = fs.statSync(destPath).isDirectory(); + if (srcIsFile && destIsDir) { + getLogger().warn(`Corrupted theme entry: ${theme}, fixing...`); + fs.rmSync(destPath, { recursive: true, force: true }); + + } else { + continue; } } + + try { + if (srcIsFile) { + fs.copyFileSync(srcPath, destPath); + fs.chmodSync(destPath, 0o666); + } else { + copyDirectory(srcPath, destPath); + fs.chmodSync(destPath, 0o777); + } + getLogger().info(`Copied default theme: ${theme}`); + } catch (copyErr) { + getLogger().warn(`Failed to copy theme ${theme}: ${copyErr.message}`); + } } } else { - getLogger().warn(`Default themes source path not found: ${defaultThemesSourcePath}`); + getLogger().warn(`Default themes source path not found: ${defaultThemesSourcePath}`); } } catch (err) { - getLogger().error(`Failed to initialize user themes: ${err.message}`); + getLogger().error(`Failed to initialize user themes: ${err.message}`); } } /** @@ -229,16 +239,23 @@ function copyDirectory(src, dest) { } // Runtime validation of critical binaries -if (!userYtDlp) { - getLogger().error("Missing yt-dlp binary"); -} +// if (!userYtDlp) { +// getLogger().error("Missing yt-dlp binary"); +// } -if (!ffmpegPath) { - getLogger().error("Missing ffmpeg binary"); -} +// if (!ffmpegPath) { +// getLogger().error("Missing ffmpeg binary"); +// } -if (!denoPath) { - getLogger().error("Missing deno binary"); +// if (!denoPath) { +// getLogger().error("Missing deno binary"); +// } + + +function validateBinaries() { + if (!userYtDlp) getLogger().error("Missing yt-dlp binary"); + if (!ffmpegPath) getLogger().error("Missing ffmpeg binary"); + if (!denoPath) getLogger().error("Missing deno binary"); } /** @@ -249,4 +266,4 @@ function getLogger() { return require("../logger.js").logger; } -module.exports = { userYtDlp, ffmpegPath, denoPath, iconPaths, binaryPaths, resourcesPath, defaultDownloadFolder, userThemesPath, initUserThemes, isWindows }; \ No newline at end of file +module.exports = { userYtDlp, ffmpegPath, denoPath, iconPaths, binaryPaths, resourcesPath, defaultDownloadFolder, userThemesPath, initUserThemes, isWindows, validateBinaries }; \ No newline at end of file