From 415162e058e293b31f6842bade906e3c48aba60b Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 19 Apr 2026 11:46:50 +0200 Subject: [PATCH] fix(log): fall back to user's Desktop before AppData, keep daily-log naming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the configured log path (or the default exe-adjacent path) isn't writable, we now try the current user's Desktop first — that's where users actually look — and only fall back to AppData if Desktop is also unavailable. The daily-log filename suffix is preserved on the fallback file so the format stays consistent. --- main.js | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 04245d8..0d10154 100644 --- a/main.js +++ b/main.js @@ -113,6 +113,25 @@ function getLogFilePath() { return _dailyLogPath; } +function buildFallbackLogName(dir) { + // Match the daily-log naming when enabled, so fallback files stay consistent. + const config = configStore.load(); + const useDailyLog = config && config.globalSettings && config.globalSettings.sessionLog; + if (!useDailyLog) return path.join(dir, 'fileuploader.log'); + const now = new Date(); + const pad = (n) => String(n).padStart(2, '0'); + const today = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`; + return path.join(dir, `fileuploader-${today}.log`); +} + +function getSafeDesktopDir() { + try { + const desktop = app.getPath('desktop'); + if (desktop && fs.existsSync(desktop)) return desktop; + } catch {} + return null; +} + let _uploadLogFallbackWarned = false; function appendUploadLog(hoster, link, fileName) { const now = new Date(); @@ -129,11 +148,30 @@ function appendUploadLog(hoster, link, fileName) { tryWrite(getLogFilePath()); return; } catch (err) { - debugLog(`appendUploadLog primary failed (${err.message}); using fallback`); + debugLog(`appendUploadLog primary failed (${err.message}); trying desktop fallback`); } + // Fallback 1: current user's Desktop (visible, easy to find). + const desktop = getSafeDesktopDir(); + if (desktop) { + try { + const fallbackPath = buildFallbackLogName(desktop); + tryWrite(fallbackPath); + if (!_uploadLogFallbackWarned) { + _uploadLogFallbackWarned = true; + if (mainWindow && !mainWindow.isDestroyed()) { + mainWindow.webContents.send('upload-log-fallback', { fallbackPath }); + } + } + return; + } catch (err) { + debugLog(`appendUploadLog desktop fallback failed (${err.message}); trying userData`); + } + } + + // Fallback 2: userData (always writable by the current user). try { - const fallbackPath = path.join(app.getPath('userData'), 'fileuploader-fallback.log'); + const fallbackPath = buildFallbackLogName(app.getPath('userData')); tryWrite(fallbackPath); if (!_uploadLogFallbackWarned) { _uploadLogFallbackWarned = true; @@ -142,7 +180,7 @@ function appendUploadLog(hoster, link, fileName) { } } } catch (err) { - debugLog(`appendUploadLog fallback also failed: ${err.message}`); + debugLog(`appendUploadLog all fallbacks failed: ${err.message}`); } }