Root cause: startBatch() ran synchronously inside ipcMain.handle() callback, causing webContents.send() events to conflict with the handle response and never reach the renderer. Fix: defer startBatch() via process.nextTick so IPC response is sent first, then upload events flow correctly. Also: - Add .catch() on startBatch to surface hidden errors - Fix settings panel not updating after save (renderSettings) - Add select-folder IPC handler (was in preload but missing) - Add debug-log and debug-test-upload IPC for diagnostics - Add upload-debug.log file for tracing upload flow - Add unhandledRejection handler for main process - Add scramble defaults to config-store globalSettings Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
113 lines
3.3 KiB
JavaScript
113 lines
3.3 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const HOSTER_SETTINGS_DEFAULTS = {
|
|
retries: 3,
|
|
maxSpeedKbs: 0, // 0 = unlimited
|
|
parallelCount: 2, // 1-10
|
|
restartBelowKbs: 0, // 0 = off
|
|
timeIntervalSec: 0, // delay between jobs
|
|
maxSizeMb: 0 // 0 = unlimited
|
|
};
|
|
|
|
const DEFAULTS = {
|
|
hosters: {
|
|
'doodstream.com': { enabled: true, apiKey: '' },
|
|
'voe.sx': { enabled: true, apiKey: '' },
|
|
'vidmoly.me': { enabled: true, authType: 'login', username: '', password: '' },
|
|
'byse.sx': { enabled: true, apiKey: '' }
|
|
},
|
|
hosterSettings: {
|
|
'doodstream.com': { ...HOSTER_SETTINGS_DEFAULTS },
|
|
'voe.sx': { ...HOSTER_SETTINGS_DEFAULTS },
|
|
'vidmoly.me': { ...HOSTER_SETTINGS_DEFAULTS },
|
|
'byse.sx': { ...HOSTER_SETTINGS_DEFAULTS }
|
|
},
|
|
globalSettings: {
|
|
alwaysOnTop: false,
|
|
shutdownAfterFinish: 'nothing', // nothing | sleep | shutdown | restart
|
|
scramble: {
|
|
active: false,
|
|
prefix: '',
|
|
suffix: '',
|
|
chars: 'both', // 'letters' | 'numbers' | 'both'
|
|
length: 0 // 0 = same as original basename length
|
|
}
|
|
},
|
|
history: []
|
|
};
|
|
|
|
const MAX_HISTORY = 100;
|
|
|
|
class ConfigStore {
|
|
constructor(app) {
|
|
const dir = app && app.isPackaged
|
|
? app.getPath('userData')
|
|
: path.join(__dirname, '..');
|
|
this.filePath = path.join(dir, 'electron-config.json');
|
|
}
|
|
|
|
load() {
|
|
try {
|
|
const raw = fs.readFileSync(this.filePath, 'utf-8');
|
|
const data = JSON.parse(raw);
|
|
// Merge with defaults so new hosters are always present
|
|
const hosters = { ...DEFAULTS.hosters };
|
|
for (const [name, val] of Object.entries(data.hosters || {})) {
|
|
if (hosters[name]) {
|
|
hosters[name] = { ...hosters[name], ...val };
|
|
}
|
|
}
|
|
// Merge hoster settings with defaults
|
|
const hosterSettings = {};
|
|
for (const name of Object.keys(DEFAULTS.hosterSettings)) {
|
|
hosterSettings[name] = {
|
|
...HOSTER_SETTINGS_DEFAULTS,
|
|
...(data.hosterSettings && data.hosterSettings[name] || {})
|
|
};
|
|
}
|
|
const globalSettings = {
|
|
...DEFAULTS.globalSettings,
|
|
...(data.globalSettings || {})
|
|
};
|
|
return { hosters, hosterSettings, globalSettings, history: data.history || [] };
|
|
} catch {
|
|
return JSON.parse(JSON.stringify(DEFAULTS));
|
|
}
|
|
}
|
|
|
|
save(config) {
|
|
const current = this.load();
|
|
// Update hosters credentials
|
|
if (config.hosters) current.hosters = config.hosters;
|
|
// Update hoster settings
|
|
if (config.hosterSettings) current.hosterSettings = config.hosterSettings;
|
|
// Update global settings
|
|
if (config.globalSettings) current.globalSettings = config.globalSettings;
|
|
fs.writeFileSync(this.filePath, JSON.stringify(current, null, 2), 'utf-8');
|
|
}
|
|
|
|
loadHistory() {
|
|
const config = this.load();
|
|
return config.history || [];
|
|
}
|
|
|
|
appendHistory(entry) {
|
|
const config = this.load();
|
|
config.history.push(entry);
|
|
// Cap at MAX_HISTORY
|
|
if (config.history.length > MAX_HISTORY) {
|
|
config.history = config.history.slice(-MAX_HISTORY);
|
|
}
|
|
fs.writeFileSync(this.filePath, JSON.stringify(config, null, 2), 'utf-8');
|
|
}
|
|
|
|
clearHistory() {
|
|
const config = this.load();
|
|
config.history = [];
|
|
fs.writeFileSync(this.filePath, JSON.stringify(config, null, 2), 'utf-8');
|
|
}
|
|
}
|
|
|
|
module.exports = ConfigStore;
|