mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-09-28 04:21:15 +02:00
Compare commits
8 Commits
7ab23d495c
...
2a9b4420de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a9b4420de | ||
|
|
e521747baa | ||
|
|
2d71449a10 | ||
|
|
0a152d4b10 | ||
|
|
676607b2c9 | ||
|
|
def3ced215 | ||
|
|
febe8364cd | ||
|
|
25d3b6e8e7 |
@@ -18,6 +18,7 @@ const { getThemes, reloadThemes } = require("./themeManager");
|
|||||||
const config = require("../config");
|
const config = require("../config");
|
||||||
const { validateDownloadPath, getDefaultDownloadPath } = require("./pathValidator");
|
const { validateDownloadPath, getDefaultDownloadPath } = require("./pathValidator");
|
||||||
const { userThemesPath } = require("../server/helpers/path.helpers");
|
const { userThemesPath } = require("../server/helpers/path.helpers");
|
||||||
|
const { createSystemTray, destroyTray } = require("./tray");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Security whitelist for feature flags that can be modified at runtime.
|
* Security whitelist for feature flags that can be modified at runtime.
|
||||||
@@ -214,6 +215,21 @@ function registerIpcHandlers(getMainWindow) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamically intercepts and applies System Tray state changes at runtime.
|
||||||
|
* Instantiates or destroys the tray icon immediately to prevent window
|
||||||
|
* lifecycle desynchronization (e.g., minimizing a window to a non-existent tray).
|
||||||
|
*/
|
||||||
|
if (key === "systemTray") {
|
||||||
|
if (value === true) {
|
||||||
|
logger.info("System Tray enabled dynamically.");
|
||||||
|
createSystemTray(getMainWindow(), config.devMode);
|
||||||
|
} else {
|
||||||
|
logger.info("System Tray disabled dynamically.");
|
||||||
|
destroyTray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
configFeatures[key] = value;
|
configFeatures[key] = value;
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
|
|||||||
@@ -56,35 +56,30 @@ function validateDownloadPath(userPath) {
|
|||||||
if (!userPath) return getDefaultDownloadPath();
|
if (!userPath) return getDefaultDownloadPath();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const absolutePath = path.resolve(userPath);
|
||||||
|
|
||||||
/**
|
if (!fs.existsSync(absolutePath)) {
|
||||||
* Resolves filesystem symlinks to ensure canonical absolute path.
|
fs.mkdirSync(absolutePath, { recursive: true });
|
||||||
* Required to prevent path traversal or alias bypass.
|
logger.info(`Download folder created: ${absolutePath}`);
|
||||||
*/
|
}
|
||||||
const resolved = fs.realpathSync(path.resolve(userPath));
|
|
||||||
|
|
||||||
if (!fs.existsSync(resolved)) {
|
const real = fs.realpathSync(absolutePath);
|
||||||
fs.mkdirSync(resolved, { recursive: true });
|
|
||||||
logger.info(`Download folder created: ${resolved}`);
|
if (!isSafePath(real)) {
|
||||||
|
throw new Error("Path not allowed: system folders are blocked!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return real;
|
||||||
}
|
}
|
||||||
|
|
||||||
const real = fs.realpathSync(resolved);
|
catch (err) {
|
||||||
|
/**
|
||||||
if (!isSafePath(resolved)) {
|
* Handles invalid filesystem paths, permissions issues, or resolution failures.
|
||||||
throw new Error("Path not allowed: system folders are blocked!");
|
* Logs diagnostic information before propagating a sanitized error.
|
||||||
|
*/
|
||||||
|
logger.error(`Invalid download path: ${userPath} — ${err.message}`);
|
||||||
|
throw new Error(`Invalid or inaccessible path: ${err.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return real;
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles invalid filesystem paths, permissions issues, or resolution failures.
|
|
||||||
* Logs diagnostic information before propagating a sanitized error.
|
|
||||||
*/
|
|
||||||
logger.error(`Invalid download path: ${userPath} — ${err.message}`);
|
|
||||||
throw new Error(`Invalid or inaccessible path: ${err.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { validateDownloadPath, getDefaultDownloadPath };
|
module.exports = { validateDownloadPath, getDefaultDownloadPath };
|
||||||
@@ -87,7 +87,7 @@ async function createMainWindow() {
|
|||||||
* cancels the destruction and hides the window instead.
|
* cancels the destruction and hides the window instead.
|
||||||
*/
|
*/
|
||||||
mainWindow.on('close', (event) => {
|
mainWindow.on('close', (event) => {
|
||||||
if (!app.isQuitting) {
|
if (!app.isQuitting && config.systemTray ) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"autoUpdate": true,
|
"autoUpdate": true,
|
||||||
"systemTray": true,
|
"systemTray": false,
|
||||||
"discordRPC": true,
|
"discordRPC": true,
|
||||||
"customTopBar": true,
|
"customTopBar": true,
|
||||||
"autoCheckInfo": true,
|
"autoCheckInfo": true,
|
||||||
|
|||||||
39
main.js
39
main.js
@@ -82,8 +82,20 @@ const { createSplashWindow, closeSplashWindow, setSplashProgress } = require("./
|
|||||||
const { userThemesPath, initUserThemes, isWindows, validateBinaries, defaultDownloadFolder } = require("./server/helpers/path.helpers");
|
const { userThemesPath, initUserThemes, isWindows, validateBinaries, defaultDownloadFolder } = require("./server/helpers/path.helpers");
|
||||||
const {createSystemTray, destroyTray} = require("./app/tray");
|
const {createSystemTray, destroyTray} = require("./app/tray");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global flag indicating if the application is intentionally shutting down.
|
||||||
|
* Used across the app to bypass the "minimize to tray on close" behavior.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
app.isQuitting = false;
|
app.isQuitting = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State flag to track the asynchronous cleanup process during shutdown.
|
||||||
|
* Prevents the application from exiting before services (RPC, Tray, Logs) are properly closed.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
let isCleanedUp = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If another instance want to run
|
* If another instance want to run
|
||||||
*/
|
*/
|
||||||
@@ -145,7 +157,7 @@ app.whenReady().then(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on("window-all-closed", () => {
|
app.on("window-all-closed", () => {
|
||||||
if (app.isQuitting) {
|
if (app.isQuitting || !configFeatures.systemTray) {
|
||||||
logger.info("Shutting down...");
|
logger.info("Shutting down...");
|
||||||
app.quit();
|
app.quit();
|
||||||
} else if (process.platform !== "darwin") {
|
} else if (process.platform !== "darwin") {
|
||||||
@@ -153,10 +165,25 @@ app.on("window-all-closed", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("before-quit", async () => {
|
app.on("before-quit", (event) => {
|
||||||
app.isQuitting = true;
|
app.isQuitting = true;
|
||||||
destroyTray();
|
|
||||||
await stopRPC();
|
if (!isCleanedUp) {
|
||||||
logger.info("All services stopped. Have a nice day!");
|
event.preventDefault();
|
||||||
logSessionEnd();
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
destroyTray();
|
||||||
|
await stopRPC();
|
||||||
|
} catch (err) {
|
||||||
|
logger.error("Error during cleanup:", err);
|
||||||
|
} finally {
|
||||||
|
logger.info("All services stopped. Have a nice day!");
|
||||||
|
logSessionEnd();
|
||||||
|
|
||||||
|
isCleanedUp = true;
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "freedom-loader",
|
"name": "freedom-loader",
|
||||||
"version": "1.6.1",
|
"version": "1.6.2-preview",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "freedom-loader",
|
"name": "freedom-loader",
|
||||||
"version": "1.6.1",
|
"version": "1.6.2-preview",
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const getUserBrowser = require("./getBrowser.helpers.js");
|
|||||||
const { ffmpegPath, denoPath} = require("./path.helpers.js");
|
const { ffmpegPath, denoPath} = require("./path.helpers.js");
|
||||||
const { configFeatures } = require("../../config.js");
|
const { configFeatures } = require("../../config.js");
|
||||||
const { logger } = require("../logger.js");
|
const { logger } = require("../logger.js");
|
||||||
|
const config = require("../../config")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates whether the provided codec is supported by the application.
|
* Validates whether the provided codec is supported by the application.
|
||||||
@@ -130,6 +131,14 @@ function buildYtDlpArgs({url, audioOnly, quality, outputFolder, isPlaylist}) {
|
|||||||
outputTemplate = "%(playlist_index)02d - %(title)s.%(ext)s";
|
outputTemplate = "%(playlist_index)02d - %(title)s.%(ext)s";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a custom signature in each file downloaded with the app. It's a small things but i found it cool :)
|
||||||
|
if (configFeatures.addMetadata) {
|
||||||
|
args.push(
|
||||||
|
"--postprocessor-args",
|
||||||
|
`ffmpeg:-metadata comment="Downloaded with Freedom Loader v${config.version}"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
args.push("-o", path.join(outputFolder, outputTemplate));
|
args.push("-o", path.join(outputFolder, outputTemplate));
|
||||||
args.push(url);
|
args.push(url);
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ const logger = createLogger({
|
|||||||
* Start Log Session
|
* Start Log Session
|
||||||
*/
|
*/
|
||||||
function logSessionStart(logDir, downloadPath) {
|
function logSessionStart(logDir, downloadPath) {
|
||||||
logger.info(`--- Starting session: ${new Date().toISOString()} ---`);
|
logger.info(`--- Starting session: ${new Date().toLocaleString('sv-SE')} ---`);
|
||||||
logger.info("============================================================")
|
logger.info("============================================================")
|
||||||
logger.info(`Application Version: ${config.version}`)
|
logger.info(`Application Version: ${config.version}`)
|
||||||
if (typeof logSystemInfo === 'function') logSystemInfo(logger, logDir, downloadPath);
|
if (typeof logSystemInfo === 'function') logSystemInfo(logger, logDir, downloadPath);
|
||||||
@@ -88,7 +88,7 @@ function logSessionStart(logDir, downloadPath) {
|
|||||||
* Stop Log Session
|
* Stop Log Session
|
||||||
*/
|
*/
|
||||||
function logSessionEnd() {
|
function logSessionEnd() {
|
||||||
logger.info(`--- Ending session: ${new Date().toISOString()} ---`);
|
logger.info(`--- Ending session: ${new Date().toLocaleString('sv-SE')} ---`);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ function createPlaylistFolder(basePath, playlistTitle) {
|
|||||||
* @param {string} [options.outputFolder] - Destination folder.
|
* @param {string} [options.outputFolder] - Destination folder.
|
||||||
* @param {string} [options.playlistTitle] - Playlist title.
|
* @param {string} [options.playlistTitle] - Playlist title.
|
||||||
*
|
*
|
||||||
* @param {Function[]} listeners - Progress listeners.
|
* @param {Function[]} progressListeners - Progress listeners.
|
||||||
* @param {Function[]} speedListeners - Download speed listeners.
|
* @param {Function[]} speedListeners - Download speed listeners.
|
||||||
* @param {Function[]} stageListeners - Processing stage listeners.
|
* @param {Function[]} stageListeners - Processing stage listeners.
|
||||||
* @param {Function[]} playlistInfoListeners - Playlist progress listeners.
|
* @param {Function[]} playlistInfoListeners - Playlist progress listeners.
|
||||||
@@ -132,7 +132,7 @@ function createPlaylistFolder(basePath, playlistTitle) {
|
|||||||
* Resolves with the final output folder path once the
|
* Resolves with the final output folder path once the
|
||||||
* download has completed successfully.
|
* download has completed successfully.
|
||||||
*/
|
*/
|
||||||
function fetchDownload(options, listeners, speedListeners, stageListeners, playlistInfoListeners) {
|
function fetchDownload(options, progressListeners, speedListeners, stageListeners, playlistInfoListeners) {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ function fetchDownload(options, listeners, speedListeners, stageListeners, playl
|
|||||||
|
|
||||||
child.on("close", code => {
|
child.on("close", code => {
|
||||||
currentDownloadProcess = null;
|
currentDownloadProcess = null;
|
||||||
listeners.forEach(fn => fn("done"));
|
progressListeners.forEach(fn => fn("done"));
|
||||||
if (code === 0) resolve(safeOutputFolder);
|
if (code === 0) resolve(safeOutputFolder);
|
||||||
else if (code === null) reject(new Error(`Download cancelled by user`));
|
else if (code === null) reject(new Error(`Download cancelled by user`));
|
||||||
else reject(new Error(`YT-DLP failed with code : ${code}`));
|
else reject(new Error(`YT-DLP failed with code : ${code}`));
|
||||||
@@ -204,11 +204,11 @@ function fetchDownload(options, listeners, speedListeners, stageListeners, playl
|
|||||||
|
|
||||||
// Progress Bar
|
// Progress Bar
|
||||||
if (line.startsWith("[download] Destination:")) {
|
if (line.startsWith("[download] Destination:")) {
|
||||||
listeners.forEach(fn => fn("reset"));
|
progressListeners.forEach(fn => fn("reset"));
|
||||||
stageListeners.forEach(fn => fn("Downloading..."));
|
stageListeners.forEach(fn => fn("Downloading..."));
|
||||||
}
|
}
|
||||||
const match = line.match(/\[download\]\s+(\d+\.\d+)%/);
|
const match = line.match(/\[download\]\s+(\d+\.\d+)%/);
|
||||||
if (match) listeners.forEach(fn => fn(parseFloat(match[1])));
|
if (match) progressListeners.forEach(fn => fn(parseFloat(match[1])));
|
||||||
|
|
||||||
if (line.includes("MiB/s") || line.includes("KiB/s")) {
|
if (line.includes("MiB/s") || line.includes("KiB/s")) {
|
||||||
const match = line.match(/\d+(\.\d+)?[KM]?iB\/s/);
|
const match = line.match(/\d+(\.\d+)?[KM]?iB\/s/);
|
||||||
|
|||||||
Reference in New Issue
Block a user