fix: correct use of logger for path.helpers.js

This commit is contained in:
MasterAcnolo
2026-07-22 20:41:54 +02:00
parent d5965c2ce0
commit 90d8a9f65d

View File

@@ -3,8 +3,6 @@ const fs = require("fs");
const { app } = require("electron"); const { app } = require("electron");
const config = require("../../config.js"); const config = require("../../config.js");
const { logger } = require("../logger.js");
/** /**
* Is the OS windows * Is the OS windows
*/ */
@@ -104,7 +102,7 @@ if (config.devMode) {
try { try {
fs.chmodSync(userYtDlp, 0o755); fs.chmodSync(userYtDlp, 0o755);
} catch (err) { } catch (err) {
logger.warn(`Failed to chmod yt-dlp: ${err.message}`); getLogger().warn(`Failed to chmod yt-dlp: ${err.message}`);
} }
} }
} }
@@ -165,48 +163,38 @@ function initUserThemes() {
try { try {
if (!fs.existsSync(userThemesPath)) { if (!fs.existsSync(userThemesPath)) {
fs.mkdirSync(userThemesPath, { recursive: true }); fs.mkdirSync(userThemesPath, { recursive: true });
// Ensure folder is writable
fs.chmodSync(userThemesPath, 0o777); fs.chmodSync(userThemesPath, 0o777);
logger.info("Created user themes directory"); getLogger().info("Created user themes directory");
} }
// Copy default themes from resources to user directory if they don't exist
if (fs.existsSync(defaultThemesSourcePath)) { if (fs.existsSync(defaultThemesSourcePath)) {
const defaultThemes = fs.readdirSync(defaultThemesSourcePath); const defaultThemes = fs.readdirSync(defaultThemesSourcePath);
for (const theme of defaultThemes) { for (const theme of defaultThemes) {
const srcPath = path.join(defaultThemesSourcePath, theme); const srcPath = path.join(defaultThemesSourcePath, theme);
const destPath = path.join(userThemesPath, theme); const destPath = path.join(userThemesPath, theme);
if (!fs.existsSync(destPath)) { if (!fs.existsSync(destPath)) {
try { try {
if (fs.statSync(srcPath).isDirectory()) {
copyDirectory(srcPath, destPath); copyDirectory(srcPath, destPath);
fs.chmodSync(destPath, 0o777); fs.chmodSync(destPath, 0o777);
logger.info(`Copied default theme: ${theme}`); } else {
} catch (copyErr) { fs.copyFileSync(srcPath, destPath);
logger.warn( fs.chmodSync(destPath, 0o666);
`Failed to copy theme ${theme}: ${copyErr.message}. Theme folder will be created, add theme files manually.`
);
try {
fs.mkdirSync(destPath, { recursive: true });
fs.chmodSync(destPath, 0o777);
} catch (mkdirErr) {
logger.warn(
`Could not create theme directory ${theme}: ${mkdirErr.message}`
);
} }
getLogger().info(`Copied default theme: ${theme}`);
} catch (copyErr) {
getLogger().warn(`Failed to copy theme ${theme}: ${copyErr.message}`);
} }
} }
} }
} else { } else {
logger.warn( getLogger().warn(`Default themes source path not found: ${defaultThemesSourcePath}`);
`Default themes source path not found: ${defaultThemesSourcePath}`
);
} }
} catch (err) { } catch (err) {
logger.error(`Failed to initialize user themes: ${err.message}`); getLogger().error(`Failed to initialize user themes: ${err.message}`);
} }
} }
/** /**
* Recursively copies a directory and its contents. * Recursively copies a directory and its contents.
* *
@@ -242,15 +230,23 @@ function copyDirectory(src, dest) {
// Runtime validation of critical binaries // Runtime validation of critical binaries
if (!userYtDlp) { if (!userYtDlp) {
logger.error("Missing yt-dlp binary"); getLogger().error("Missing yt-dlp binary");
} }
if (!ffmpegPath) { if (!ffmpegPath) {
logger.error("Missing ffmpeg binary"); getLogger().error("Missing ffmpeg binary");
} }
if (!denoPath) { if (!denoPath) {
logger.error("Missing deno binary"); getLogger().error("Missing deno binary");
}
/**
* Helper to lazy load logger, avoid circular import
* @returns {winston.Logger}
*/
function getLogger() {
return require("../logger.js").logger;
} }
module.exports = { userYtDlp, ffmpegPath, denoPath, iconPaths, binaryPaths, resourcesPath, defaultDownloadFolder, userThemesPath, initUserThemes, isWindows }; module.exports = { userYtDlp, ffmpegPath, denoPath, iconPaths, binaryPaths, resourcesPath, defaultDownloadFolder, userThemesPath, initUserThemes, isWindows };