feat: système de profils — historiques et drop stats séparés par profil
- Profils stockés dans profiles.json (userData), profil "Défaut" rétro-compatible - Chaque profil a son propre historique de sessions et app state (fichiers suffixés par id) - Drop stats : mode Privé (fichier propre) ou Partagé (pool dropstats-shared.json commun) - Bouton 👤 dans la topbar ouvre une modal de gestion des profils - Créer, renommer (double-clic), supprimer, activer un profil - Basculer le mode de drop stats (Privé ↔ Partagé) par profil - timers et alertes isolés par profil via clés localStorage préfixées par profil id - Switch de profil = rechargement de page (données propres sans état résiduel) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
308
main.js
308
main.js
@@ -4,24 +4,25 @@ const fs = require('fs');
|
|||||||
const fsp = fs.promises;
|
const fsp = fs.promises;
|
||||||
const { emptyDropStats, mergeDropStatsInto } = require('./lib/dropstats');
|
const { emptyDropStats, mergeDropStatsInto } = require('./lib/dropstats');
|
||||||
|
|
||||||
// Stocké automatiquement dans ~/.config/farm-tracker/ sur Linux (géré par Electron).
|
|
||||||
const userDataDir = app.getPath('userData');
|
const userDataDir = app.getPath('userData');
|
||||||
const APP_STATE_FILE = path.join(userDataDir, 'app-state.json');
|
|
||||||
const DROPSTATS_FILE = path.join(userDataDir, 'dropstats.json');
|
// Fichiers globaux (non liés à un profil)
|
||||||
const COMMUNITY_DROPSTATS_FILE = path.join(userDataDir, 'community-dropstats.json');
|
const COMMUNITY_DROPSTATS_FILE = path.join(userDataDir, 'community-dropstats.json');
|
||||||
const SESSION_HISTORY_FILE = path.join(userDataDir, 'session-history.json');
|
|
||||||
const UPDATE_PREFS_FILE = path.join(userDataDir, 'update-prefs.json');
|
const UPDATE_PREFS_FILE = path.join(userDataDir, 'update-prefs.json');
|
||||||
|
const PROFILES_FILE = path.join(userDataDir, 'profiles.json');
|
||||||
|
|
||||||
|
// Fichiers legacy (profil "default")
|
||||||
|
const LEGACY_APP_STATE_FILE = path.join(userDataDir, 'app-state.json');
|
||||||
|
const LEGACY_DROPSTATS_FILE = path.join(userDataDir, 'dropstats.json');
|
||||||
|
const LEGACY_SESSION_HISTORY_FILE= path.join(userDataDir, 'session-history.json');
|
||||||
|
|
||||||
const RELEASES_API = 'https://git.shamiiow.com/api/v1/repos/shamiiow/farm-tracker-sao/releases/latest';
|
const RELEASES_API = 'https://git.shamiiow.com/api/v1/repos/shamiiow/farm-tracker-sao/releases/latest';
|
||||||
|
|
||||||
// ---------- Lecture / écriture disque (JSON indenté = facilement lisible) ----------
|
// ---------- Lecture / écriture disque ----------
|
||||||
|
|
||||||
function readJsonSafe(filePath, fallback) {
|
function readJsonSafe(filePath, fallback) {
|
||||||
try {
|
try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }
|
||||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
catch { return fallback; }
|
||||||
} catch (e) {
|
|
||||||
return fallback;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeJsonAtomic(filePath, obj) {
|
function writeJsonAtomic(filePath, obj) {
|
||||||
@@ -37,22 +38,82 @@ function writeJsonAtomic(filePath, obj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadAppState() { return readJsonSafe(APP_STATE_FILE, null); }
|
function tryUnlink(filePath) { try { fs.unlinkSync(filePath); } catch (_) {} }
|
||||||
function saveAppState(obj) { return writeJsonAtomic(APP_STATE_FILE, obj); }
|
|
||||||
function loadDropStats() { return readJsonSafe(DROPSTATS_FILE, emptyDropStats()); }
|
function generateId() {
|
||||||
function saveDropStats(obj) { return writeJsonAtomic(DROPSTATS_FILE, obj); }
|
return Math.random().toString(36).slice(2, 10) + Date.now().toString(36);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- Profils ----------
|
||||||
|
|
||||||
|
function emptyProfilesData() {
|
||||||
|
return {
|
||||||
|
activeProfileId: 'default',
|
||||||
|
profiles: [{
|
||||||
|
id: 'default',
|
||||||
|
name: 'Défaut',
|
||||||
|
dropStatsMode: 'private',
|
||||||
|
createdAt: new Date().toISOString()
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadProfilesData() {
|
||||||
|
const data = readJsonSafe(PROFILES_FILE, null);
|
||||||
|
if (!data) {
|
||||||
|
const def = emptyProfilesData();
|
||||||
|
writeJsonAtomic(PROFILES_FILE, def);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
// compat : s'assurer que le profil default existe toujours
|
||||||
|
if (!data.profiles.find(p => p.id === 'default')) {
|
||||||
|
data.profiles.unshift({ id: 'default', name: 'Défaut', dropStatsMode: 'private', createdAt: new Date().toISOString() });
|
||||||
|
writeJsonAtomic(PROFILES_FILE, data);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getActiveProfile() {
|
||||||
|
const data = loadProfilesData();
|
||||||
|
return data.profiles.find(p => p.id === data.activeProfileId) || data.profiles[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- Chemins de fichiers dynamiques selon profil ----------
|
||||||
|
|
||||||
|
function profileAppStateFile(p) {
|
||||||
|
if (!p || p.id === 'default') return LEGACY_APP_STATE_FILE;
|
||||||
|
return path.join(userDataDir, `app-state-${p.id}.json`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function profileDropStatsFile(p) {
|
||||||
|
if (!p || p.id === 'default') return LEGACY_DROPSTATS_FILE;
|
||||||
|
if (p.dropStatsMode === 'shared') return path.join(userDataDir, 'dropstats-shared.json');
|
||||||
|
return path.join(userDataDir, `dropstats-${p.id}.json`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function profileSessionHistoryFile(p) {
|
||||||
|
if (!p || p.id === 'default') return LEGACY_SESSION_HISTORY_FILE;
|
||||||
|
return path.join(userDataDir, `session-history-${p.id}.json`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- Load / save avec profil actif ----------
|
||||||
|
|
||||||
|
function loadAppState() { return readJsonSafe(profileAppStateFile(getActiveProfile()), null); }
|
||||||
|
function saveAppState(obj) { return writeJsonAtomic(profileAppStateFile(getActiveProfile()), obj); }
|
||||||
|
function loadDropStats() { return readJsonSafe(profileDropStatsFile(getActiveProfile()), emptyDropStats()); }
|
||||||
|
function saveDropStats(obj) { return writeJsonAtomic(profileDropStatsFile(getActiveProfile()), obj); }
|
||||||
|
function loadSessionHistory() { return readJsonSafe(profileSessionHistoryFile(getActiveProfile()), { type: 'farm-tracker-session-history', version: 1, sessions: [] }); }
|
||||||
|
function saveSessionHistory(o) { return writeJsonAtomic(profileSessionHistoryFile(getActiveProfile()), o); }
|
||||||
function loadCommunityDropStats() { return readJsonSafe(COMMUNITY_DROPSTATS_FILE, null); }
|
function loadCommunityDropStats() { return readJsonSafe(COMMUNITY_DROPSTATS_FILE, null); }
|
||||||
function saveCommunityDropStats(obj) { return writeJsonAtomic(COMMUNITY_DROPSTATS_FILE, obj); }
|
function saveCommunityDropStats(obj) { return writeJsonAtomic(COMMUNITY_DROPSTATS_FILE, obj); }
|
||||||
function loadSessionHistory() { return readJsonSafe(SESSION_HISTORY_FILE, { type: 'farm-tracker-session-history', version: 1, sessions: [] }); }
|
|
||||||
function saveSessionHistory(obj) { return writeJsonAtomic(SESSION_HISTORY_FILE, obj); }
|
|
||||||
function loadUpdatePrefs() { return readJsonSafe(UPDATE_PREFS_FILE, { snoozedUntil: null }); }
|
function loadUpdatePrefs() { return readJsonSafe(UPDATE_PREFS_FILE, { snoozedUntil: null }); }
|
||||||
function saveUpdatePrefs(obj) { return writeJsonAtomic(UPDATE_PREFS_FILE, obj); }
|
function saveUpdatePrefs(obj) { return writeJsonAtomic(UPDATE_PREFS_FILE, obj); }
|
||||||
|
|
||||||
function resolveLogPath(folderPath) {
|
function resolveLogPath(folderPath) {
|
||||||
const candidate1 = path.join(folderPath, 'logs', 'latest.log');
|
const c1 = path.join(folderPath, 'logs', 'latest.log');
|
||||||
const candidate2 = path.join(folderPath, 'latest.log');
|
const c2 = path.join(folderPath, 'latest.log');
|
||||||
if (fs.existsSync(candidate1)) return candidate1;
|
if (fs.existsSync(c1)) return c1;
|
||||||
if (fs.existsSync(candidate2)) return candidate2;
|
if (fs.existsSync(c2)) return c2;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,11 +199,7 @@ function downloadFileWithProgress(url, destPath, onProgress) {
|
|||||||
|
|
||||||
async function downloadAndInstall(downloadUrl, version) {
|
async function downloadAndInstall(downloadUrl, version) {
|
||||||
if (!app.isPackaged) {
|
if (!app.isPackaged) {
|
||||||
dialog.showMessageBox(mainWindow, {
|
dialog.showMessageBox(mainWindow, { type: 'info', title: 'Mode développement', message: 'Auto-install non disponible en mode dev.', buttons: ['OK'] });
|
||||||
type: 'info', title: 'Mode développement',
|
|
||||||
message: 'Auto-install non disponible en mode dev.',
|
|
||||||
buttons: ['OK']
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const ext = process.platform === 'win32' ? '.exe' : '.AppImage';
|
const ext = process.platform === 'win32' ? '.exe' : '.AppImage';
|
||||||
@@ -169,44 +226,28 @@ async function downloadAndInstall(downloadUrl, version) {
|
|||||||
async function showUpdateDialog(version, downloadUrl, ignoreSnooze = false) {
|
async function showUpdateDialog(version, downloadUrl, ignoreSnooze = false) {
|
||||||
const current = app.getVersion();
|
const current = app.getVersion();
|
||||||
if (!isNewerVersion(version, current)) return false;
|
if (!isNewerVersion(version, current)) return false;
|
||||||
|
|
||||||
if (!ignoreSnooze) {
|
if (!ignoreSnooze) {
|
||||||
const prefs = loadUpdatePrefs();
|
const prefs = loadUpdatePrefs();
|
||||||
if (prefs.snoozedUntil === 'indefinite') return false;
|
if (prefs.snoozedUntil === 'indefinite') return false;
|
||||||
if (prefs.snoozedUntil && new Date(prefs.snoozedUntil) > new Date()) return false;
|
if (prefs.snoozedUntil && new Date(prefs.snoozedUntil) > new Date()) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { response } = await dialog.showMessageBox(mainWindow, {
|
const { response } = await dialog.showMessageBox(mainWindow, {
|
||||||
type: 'info',
|
type: 'info', title: 'Mise à jour disponible', message: `Version ${version} disponible`,
|
||||||
title: 'Mise à jour disponible',
|
|
||||||
message: `Version ${version} disponible`,
|
|
||||||
detail: `Version actuelle : ${current}\nL'application se relancera automatiquement après la mise à jour.`,
|
detail: `Version actuelle : ${current}\nL'application se relancera automatiquement après la mise à jour.`,
|
||||||
buttons: ['Installer maintenant', 'Me rappeler dans...'],
|
buttons: ['Installer maintenant', 'Me rappeler dans...'], defaultId: 0, cancelId: 1
|
||||||
defaultId: 0,
|
|
||||||
cancelId: 1
|
|
||||||
});
|
});
|
||||||
|
if (response === 0) { downloadAndInstall(downloadUrl, version); return true; }
|
||||||
if (response === 0) {
|
|
||||||
downloadAndInstall(downloadUrl, version);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { response: snoozeResponse } = await dialog.showMessageBox(mainWindow, {
|
const { response: snoozeResponse } = await dialog.showMessageBox(mainWindow, {
|
||||||
type: 'question',
|
type: 'question', title: 'Me rappeler dans...',
|
||||||
title: 'Me rappeler dans...',
|
|
||||||
message: 'Ne plus afficher cette mise à jour pendant :',
|
message: 'Ne plus afficher cette mise à jour pendant :',
|
||||||
buttons: SNOOZE_OPTIONS.map(o => o.label),
|
buttons: SNOOZE_OPTIONS.map(o => o.label), defaultId: 0, cancelId: SNOOZE_OPTIONS.length - 1
|
||||||
defaultId: 0,
|
|
||||||
cancelId: SNOOZE_OPTIONS.length - 1
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const chosen = SNOOZE_OPTIONS[snoozeResponse];
|
const chosen = SNOOZE_OPTIONS[snoozeResponse];
|
||||||
if (chosen.days === -1) return false;
|
if (chosen.days === -1) return false;
|
||||||
if (chosen.days === null) {
|
if (chosen.days === null) {
|
||||||
saveUpdatePrefs({ snoozedUntil: 'indefinite' });
|
saveUpdatePrefs({ snoozedUntil: 'indefinite' });
|
||||||
} else {
|
} else {
|
||||||
const until = new Date();
|
const until = new Date(); until.setDate(until.getDate() + chosen.days);
|
||||||
until.setDate(until.getDate() + chosen.days);
|
|
||||||
saveUpdatePrefs({ snoozedUntil: until.toISOString() });
|
saveUpdatePrefs({ snoozedUntil: until.toISOString() });
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -219,25 +260,18 @@ async function checkForUpdates(ignoreSnooze = false) {
|
|||||||
const downloadUrl = resolveAssetUrl(release);
|
const downloadUrl = resolveAssetUrl(release);
|
||||||
if (!version || !downloadUrl) return false;
|
if (!version || !downloadUrl) return false;
|
||||||
return await showUpdateDialog(version, downloadUrl, ignoreSnooze);
|
return await showUpdateDialog(version, downloadUrl, ignoreSnooze);
|
||||||
} catch (_) {
|
} catch (_) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 1180,
|
width: 1180, height: 880, minWidth: 760, minHeight: 600,
|
||||||
height: 880,
|
backgroundColor: '#0B0F0C', autoHideMenuBar: true,
|
||||||
minWidth: 760,
|
|
||||||
minHeight: 600,
|
|
||||||
backgroundColor: '#0B0F0C',
|
|
||||||
autoHideMenuBar: true,
|
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, 'preload.js'),
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
contextIsolation: true,
|
contextIsolation: true, nodeIntegration: false
|
||||||
nodeIntegration: false
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mainWindow.setMenuBarVisibility(false);
|
mainWindow.setMenuBarVisibility(false);
|
||||||
@@ -265,7 +299,7 @@ app.whenReady().then(() => {
|
|||||||
app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); });
|
app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); });
|
||||||
app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); });
|
app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); });
|
||||||
|
|
||||||
// ---------- IPC : sélection et lecture du dossier Minecraft ----------
|
// ---------- IPC : dossier Minecraft ----------
|
||||||
|
|
||||||
ipcMain.handle('pick-folder', async () => {
|
ipcMain.handle('pick-folder', async () => {
|
||||||
const result = await dialog.showOpenDialog(mainWindow, {
|
const result = await dialog.showOpenDialog(mainWindow, {
|
||||||
@@ -275,18 +309,13 @@ ipcMain.handle('pick-folder', async () => {
|
|||||||
if (result.canceled || !result.filePaths.length) return { canceled: true };
|
if (result.canceled || !result.filePaths.length) return { canceled: true };
|
||||||
const folder = result.filePaths[0];
|
const folder = result.filePaths[0];
|
||||||
const logPath = resolveLogPath(folder);
|
const logPath = resolveLogPath(folder);
|
||||||
if (!logPath) {
|
if (!logPath) return { canceled: false, error: 'Impossible de trouver "latest.log" dans ce dossier ni dans son sous-dossier "logs". Sélectionne ton dossier .minecraft, ou le dossier logs directement.' };
|
||||||
return {
|
|
||||||
canceled: false,
|
|
||||||
error: 'Impossible de trouver "latest.log" dans ce dossier ni dans son sous-dossier "logs". Sélectionne ton dossier .minecraft, ou le dossier logs directement.'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { canceled: false, logPath };
|
return { canceled: false, logPath };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('check-log-path', async (event, logPath) => {
|
ipcMain.handle('check-log-path', async (event, logPath) => {
|
||||||
try { await fsp.access(logPath, fs.constants.R_OK); return { ok: true }; }
|
try { await fsp.access(logPath, fs.constants.R_OK); return { ok: true }; }
|
||||||
catch (e) { return { ok: false }; }
|
catch { return { ok: false }; }
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('get-file-size', async (event, logPath) => {
|
ipcMain.handle('get-file-size', async (event, logPath) => {
|
||||||
@@ -303,52 +332,38 @@ ipcMain.handle('read-chunk', async (event, logPath, start, end) => {
|
|||||||
const buffer = Buffer.alloc(length);
|
const buffer = Buffer.alloc(length);
|
||||||
await fd.read(buffer, 0, length, start);
|
await fd.read(buffer, 0, length, start);
|
||||||
return { text: buffer.toString('utf8') };
|
return { text: buffer.toString('utf8') };
|
||||||
} catch (e) {
|
} catch (e) { return { text: '', error: e.message }; }
|
||||||
return { text: '', error: e.message };
|
finally { if (fd) await fd.close().catch(() => {}); }
|
||||||
} finally {
|
|
||||||
if (fd) await fd.close().catch(() => {});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---------- IPC : état général de l'appli ----------
|
// ---------- IPC : état application (par profil) ----------
|
||||||
|
|
||||||
ipcMain.handle('load-app-state', async () => loadAppState());
|
ipcMain.handle('load-app-state', async () => loadAppState());
|
||||||
ipcMain.handle('save-app-state', async (event, obj) => saveAppState(obj));
|
ipcMain.handle('save-app-state', async (_, obj) => saveAppState(obj));
|
||||||
|
|
||||||
// ---------- IPC : stats de chance de drop personnelles ----------
|
// ---------- IPC : drop stats (par profil) ----------
|
||||||
|
|
||||||
ipcMain.handle('load-drop-stats', async () => loadDropStats());
|
ipcMain.handle('load-drop-stats', async () => loadDropStats());
|
||||||
ipcMain.handle('save-drop-stats', async (event, obj) => saveDropStats(obj));
|
ipcMain.handle('save-drop-stats', async (_, obj) => saveDropStats(obj));
|
||||||
|
|
||||||
ipcMain.handle('export-drop-stats', async () => {
|
ipcMain.handle('export-drop-stats', async () => {
|
||||||
const current = loadDropStats();
|
const current = loadDropStats();
|
||||||
const defaultName = 'farm-tracker-dropstats-' + new Date().toISOString().slice(0, 10) + '.json';
|
const defaultName = 'farm-tracker-dropstats-' + new Date().toISOString().slice(0, 10) + '.json';
|
||||||
const result = await dialog.showSaveDialog(mainWindow, {
|
const result = await dialog.showSaveDialog(mainWindow, { title: 'Exporter mes stats de chance de drop', defaultPath: defaultName, filters: [{ name: 'JSON', extensions: ['json'] }] });
|
||||||
title: 'Exporter mes stats de chance de drop',
|
|
||||||
defaultPath: defaultName,
|
|
||||||
filters: [{ name: 'JSON', extensions: ['json'] }]
|
|
||||||
});
|
|
||||||
if (result.canceled || !result.filePath) return { canceled: true };
|
if (result.canceled || !result.filePath) return { canceled: true };
|
||||||
fs.writeFileSync(result.filePath, JSON.stringify(current, null, 2));
|
fs.writeFileSync(result.filePath, JSON.stringify(current, null, 2));
|
||||||
return { canceled: false, filePath: result.filePath };
|
return { canceled: false, filePath: result.filePath };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('import-merge-drop-stats', async () => {
|
ipcMain.handle('import-merge-drop-stats', async () => {
|
||||||
const result = await dialog.showOpenDialog(mainWindow, {
|
const result = await dialog.showOpenDialog(mainWindow, { title: 'Importer et fusionner des fichiers de stats de drop', properties: ['openFile', 'multiSelections'], filters: [{ name: 'JSON', extensions: ['json'] }] });
|
||||||
title: 'Importer et fusionner des fichiers de stats de drop (plusieurs fichiers possibles)',
|
|
||||||
properties: ['openFile', 'multiSelections'],
|
|
||||||
filters: [{ name: 'JSON', extensions: ['json'] }]
|
|
||||||
});
|
|
||||||
if (result.canceled || !result.filePaths.length) return { canceled: true };
|
if (result.canceled || !result.filePaths.length) return { canceled: true };
|
||||||
|
|
||||||
const current = loadDropStats();
|
const current = loadDropStats();
|
||||||
const details = [];
|
const details = [];
|
||||||
let totalAdded = 0;
|
let totalAdded = 0;
|
||||||
|
|
||||||
for (const filePath of result.filePaths) {
|
for (const filePath of result.filePaths) {
|
||||||
try {
|
try {
|
||||||
const raw = fs.readFileSync(filePath, 'utf8');
|
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||||
const data = JSON.parse(raw);
|
|
||||||
const added = mergeDropStatsInto(current, data);
|
const added = mergeDropStatsInto(current, data);
|
||||||
totalAdded += added;
|
totalAdded += added;
|
||||||
details.push({ file: path.basename(filePath), addedKills: added, ok: true });
|
details.push({ file: path.basename(filePath), addedKills: added, ok: true });
|
||||||
@@ -356,23 +371,82 @@ ipcMain.handle('import-merge-drop-stats', async () => {
|
|||||||
details.push({ file: path.basename(filePath), ok: false, error: e.message });
|
details.push({ file: path.basename(filePath), ok: false, error: e.message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current.updatedAt = new Date().toISOString();
|
current.updatedAt = new Date().toISOString();
|
||||||
saveDropStats(current);
|
saveDropStats(current);
|
||||||
|
|
||||||
return { canceled: false, totalAdded, details, dropStats: current };
|
return { canceled: false, totalAdded, details, dropStats: current };
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---------- IPC : stats communautaires (reçues du serveur de sync) ----------
|
// ---------- IPC : stats communautaires (globales) ----------
|
||||||
|
|
||||||
ipcMain.handle('load-community-drop-stats', async () => loadCommunityDropStats());
|
ipcMain.handle('load-community-drop-stats', async () => loadCommunityDropStats());
|
||||||
ipcMain.handle('save-community-drop-stats', async (event, obj) => saveCommunityDropStats(obj));
|
ipcMain.handle('save-community-drop-stats', async (_, obj) => saveCommunityDropStats(obj));
|
||||||
ipcMain.handle('get-file-paths', () => ({ dropStats: DROPSTATS_FILE, communityDropStats: COMMUNITY_DROPSTATS_FILE }));
|
ipcMain.handle('get-file-paths', () => ({
|
||||||
|
dropStats: profileDropStatsFile(getActiveProfile()),
|
||||||
|
communityDropStats: COMMUNITY_DROPSTATS_FILE
|
||||||
|
}));
|
||||||
|
|
||||||
// ---------- IPC : historique des sessions ----------
|
// ---------- IPC : historique des sessions (par profil) ----------
|
||||||
|
|
||||||
ipcMain.handle('load-session-history', async () => loadSessionHistory());
|
ipcMain.handle('load-session-history', async () => loadSessionHistory());
|
||||||
ipcMain.handle('save-session-history', async (event, obj) => saveSessionHistory(obj));
|
ipcMain.handle('save-session-history', async (_, obj) => saveSessionHistory(obj));
|
||||||
|
|
||||||
|
// ---------- IPC : profils ----------
|
||||||
|
|
||||||
|
ipcMain.handle('get-profiles', () => loadProfilesData());
|
||||||
|
|
||||||
|
ipcMain.handle('create-profile', (_, { name, dropStatsMode }) => {
|
||||||
|
const data = loadProfilesData();
|
||||||
|
const newProfile = {
|
||||||
|
id: generateId(),
|
||||||
|
name: (name || 'Nouveau profil').trim().slice(0, 40),
|
||||||
|
dropStatsMode: dropStatsMode === 'shared' ? 'shared' : 'private',
|
||||||
|
createdAt: new Date().toISOString()
|
||||||
|
};
|
||||||
|
data.profiles.push(newProfile);
|
||||||
|
writeJsonAtomic(PROFILES_FILE, data);
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('switch-profile', (_, id) => {
|
||||||
|
const data = loadProfilesData();
|
||||||
|
if (!data.profiles.find(p => p.id === id)) return { ok: false, error: 'Profil introuvable' };
|
||||||
|
data.activeProfileId = id;
|
||||||
|
writeJsonAtomic(PROFILES_FILE, data);
|
||||||
|
return { ok: true };
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('rename-profile', (_, { id, name }) => {
|
||||||
|
const data = loadProfilesData();
|
||||||
|
const profile = data.profiles.find(p => p.id === id);
|
||||||
|
if (!profile) return { ok: false };
|
||||||
|
profile.name = (name || '').trim().slice(0, 40) || profile.name;
|
||||||
|
writeJsonAtomic(PROFILES_FILE, data);
|
||||||
|
return { ok: true, profile };
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('delete-profile', (_, id) => {
|
||||||
|
if (id === 'default') return { ok: false, error: 'Le profil Défaut ne peut pas être supprimé.' };
|
||||||
|
const data = loadProfilesData();
|
||||||
|
const profile = data.profiles.find(p => p.id === id);
|
||||||
|
if (!profile) return { ok: false, error: 'Profil introuvable' };
|
||||||
|
data.profiles = data.profiles.filter(p => p.id !== id);
|
||||||
|
if (data.activeProfileId === id) data.activeProfileId = 'default';
|
||||||
|
// supprimer les fichiers du profil
|
||||||
|
tryUnlink(path.join(userDataDir, `app-state-${id}.json`));
|
||||||
|
tryUnlink(path.join(userDataDir, `dropstats-${id}.json`));
|
||||||
|
tryUnlink(path.join(userDataDir, `session-history-${id}.json`));
|
||||||
|
writeJsonAtomic(PROFILES_FILE, data);
|
||||||
|
return { ok: true, newActiveId: data.activeProfileId };
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('set-drop-stats-mode', (_, { id, mode }) => {
|
||||||
|
const data = loadProfilesData();
|
||||||
|
const profile = data.profiles.find(p => p.id === id);
|
||||||
|
if (!profile) return { ok: false };
|
||||||
|
profile.dropStatsMode = mode === 'shared' ? 'shared' : 'private';
|
||||||
|
writeJsonAtomic(PROFILES_FILE, data);
|
||||||
|
return { ok: true };
|
||||||
|
});
|
||||||
|
|
||||||
// ---------- IPC : mise à jour ----------
|
// ---------- IPC : mise à jour ----------
|
||||||
|
|
||||||
@@ -382,28 +456,20 @@ ipcMain.handle('check-update-manual', async () => {
|
|||||||
const version = (release.tag_name || '').replace(/^v/, '');
|
const version = (release.tag_name || '').replace(/^v/, '');
|
||||||
const downloadUrl = resolveAssetUrl(release);
|
const downloadUrl = resolveAssetUrl(release);
|
||||||
const current = app.getVersion();
|
const current = app.getVersion();
|
||||||
if (!version || !downloadUrl || !isNewerVersion(version, current)) {
|
if (!version || !downloadUrl || !isNewerVersion(version, current)) return { checked: true, hasUpdate: false, current };
|
||||||
return { checked: true, hasUpdate: false, current };
|
|
||||||
}
|
|
||||||
await showUpdateDialog(version, downloadUrl, true);
|
await showUpdateDialog(version, downloadUrl, true);
|
||||||
return { checked: true, hasUpdate: true };
|
return { checked: true, hasUpdate: true };
|
||||||
} catch (e) {
|
} catch (e) { return { checked: false, error: e.message }; }
|
||||||
return { checked: false, error: e.message };
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---------- IPC : sync avec le serveur VPS ----------
|
// ---------- IPC : sync VPS ----------
|
||||||
|
|
||||||
ipcMain.handle('fetch-community-stats', async (event, { serverUrl }) => {
|
ipcMain.handle('fetch-community-stats', async (_, { serverUrl }) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL('/stats', serverUrl);
|
const url = new URL('/stats', serverUrl);
|
||||||
const mod = url.protocol === 'https:' ? require('https') : require('http');
|
const mod = url.protocol === 'https:' ? require('https') : require('http');
|
||||||
const req = mod.get({
|
const req = mod.get({ hostname: url.hostname, port: url.port || (url.protocol === 'https:' ? 443 : 80), path: '/stats' }, (res) => {
|
||||||
hostname: url.hostname,
|
|
||||||
port: url.port || (url.protocol === 'https:' ? 443 : 80),
|
|
||||||
path: '/stats'
|
|
||||||
}, (res) => {
|
|
||||||
let data = '';
|
let data = '';
|
||||||
res.on('data', chunk => { data += chunk; });
|
res.on('data', chunk => { data += chunk; });
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
@@ -413,27 +479,20 @@ ipcMain.handle('fetch-community-stats', async (event, { serverUrl }) => {
|
|||||||
});
|
});
|
||||||
req.setTimeout(15000, () => { req.destroy(); resolve({ ok: false, error: 'Timeout (15s)' }); });
|
req.setTimeout(15000, () => { req.destroy(); resolve({ ok: false, error: 'Timeout (15s)' }); });
|
||||||
req.on('error', (e) => resolve({ ok: false, error: e.message }));
|
req.on('error', (e) => resolve({ ok: false, error: e.message }));
|
||||||
} catch (e) {
|
} catch (e) { resolve({ ok: false, error: e.message }); }
|
||||||
resolve({ ok: false, error: e.message });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('sync-drop-stats', async (event, { serverUrl, clientId, dropStats }) => {
|
ipcMain.handle('sync-drop-stats', async (_, { serverUrl, clientId, dropStats }) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL('/sync', serverUrl);
|
const url = new URL('/sync', serverUrl);
|
||||||
const body = JSON.stringify({ clientId, dropStats });
|
const body = JSON.stringify({ clientId, dropStats });
|
||||||
const mod = url.protocol === 'https:' ? require('https') : require('http');
|
const mod = url.protocol === 'https:' ? require('https') : require('http');
|
||||||
const options = {
|
const options = {
|
||||||
hostname: url.hostname,
|
hostname: url.hostname, port: url.port || (url.protocol === 'https:' ? 443 : 80),
|
||||||
port: url.port || (url.protocol === 'https:' ? 443 : 80),
|
path: '/sync', method: 'POST',
|
||||||
path: '/sync',
|
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Content-Length': Buffer.byteLength(body)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const req = mod.request(options, (res) => {
|
const req = mod.request(options, (res) => {
|
||||||
let data = '';
|
let data = '';
|
||||||
@@ -445,10 +504,7 @@ ipcMain.handle('sync-drop-stats', async (event, { serverUrl, clientId, dropStats
|
|||||||
});
|
});
|
||||||
req.setTimeout(15000, () => { req.destroy(); resolve({ ok: false, error: 'Timeout (15s)' }); });
|
req.setTimeout(15000, () => { req.destroy(); resolve({ ok: false, error: 'Timeout (15s)' }); });
|
||||||
req.on('error', (e) => resolve({ ok: false, error: e.message }));
|
req.on('error', (e) => resolve({ ok: false, error: e.message }));
|
||||||
req.write(body);
|
req.write(body); req.end();
|
||||||
req.end();
|
} catch (e) { resolve({ ok: false, error: e.message }); }
|
||||||
} catch (e) {
|
|
||||||
resolve({ ok: false, error: e.message });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,5 +25,12 @@ contextBridge.exposeInMainWorld('api', {
|
|||||||
saveSessionHistory: (obj) => ipcRenderer.invoke('save-session-history', obj),
|
saveSessionHistory: (obj) => ipcRenderer.invoke('save-session-history', obj),
|
||||||
|
|
||||||
checkUpdateManual: () => ipcRenderer.invoke('check-update-manual'),
|
checkUpdateManual: () => ipcRenderer.invoke('check-update-manual'),
|
||||||
onUpdateProgress: (cb) => ipcRenderer.on('update-progress', (_, data) => cb(data))
|
onUpdateProgress: (cb) => ipcRenderer.on('update-progress', (_, data) => cb(data)),
|
||||||
|
|
||||||
|
getProfiles: () => ipcRenderer.invoke('get-profiles'),
|
||||||
|
createProfile: (name, mode) => ipcRenderer.invoke('create-profile', { name, dropStatsMode: mode }),
|
||||||
|
switchProfile: (id) => ipcRenderer.invoke('switch-profile', id),
|
||||||
|
renameProfile: (id, name) => ipcRenderer.invoke('rename-profile', { id, name }),
|
||||||
|
deleteProfile: (id) => ipcRenderer.invoke('delete-profile', id),
|
||||||
|
setDropStatsMode: (id, mode) => ipcRenderer.invoke('set-drop-stats-mode', { id, mode }),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -348,6 +348,24 @@
|
|||||||
.sound-card-actions{display:flex;gap:6px;align-items:center;margin-top:2px;}
|
.sound-card-actions{display:flex;gap:6px;align-items:center;margin-top:2px;}
|
||||||
.sound-card-status{font-size:10px;font-family:var(--font-mono);color:var(--moss);margin-left:auto;}
|
.sound-card-status{font-size:10px;font-family:var(--font-mono);color:var(--moss);margin-left:auto;}
|
||||||
|
|
||||||
|
/* --- Profils --- */
|
||||||
|
#profileBtn{font-size:11px;max-width:160px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
|
||||||
|
.profile-modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.65);z-index:900;display:flex;align-items:center;justify-content:center;}
|
||||||
|
.profile-modal-overlay[hidden]{display:none;}
|
||||||
|
.profile-modal-box{background:var(--bg-panel);border:1px solid var(--border);padding:22px 24px;width:460px;max-width:95vw;max-height:80vh;overflow-y:auto;display:flex;flex-direction:column;gap:14px;}
|
||||||
|
.profile-modal-box h3{font-size:14px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;margin:0;}
|
||||||
|
.profile-list{display:flex;flex-direction:column;gap:6px;}
|
||||||
|
.profile-row{display:flex;align-items:center;gap:8px;padding:8px 10px;border:1px solid var(--border);background:var(--bg);}
|
||||||
|
.profile-row.active{border-color:var(--moss);}
|
||||||
|
.profile-row-name{flex:1;font-size:13px;font-weight:600;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
|
||||||
|
.profile-row-mode{font-size:10px;font-family:var(--font-mono);padding:2px 6px;border:1px solid var(--border);color:var(--text-dim);cursor:pointer;white-space:nowrap;}
|
||||||
|
.profile-row-mode.shared{color:var(--corrupt);border-color:var(--corrupt);}
|
||||||
|
.profile-create-form{display:flex;flex-direction:column;gap:8px;padding:10px;border:1px solid var(--border);background:var(--bg);}
|
||||||
|
.profile-create-form input[type=text]{width:100%;box-sizing:border-box;}
|
||||||
|
.profile-mode-row{display:flex;gap:16px;font-size:12px;color:var(--text-dim);}
|
||||||
|
.profile-mode-row label{display:flex;align-items:center;gap:5px;cursor:pointer;}
|
||||||
|
.profile-mode-desc{font-size:11px;color:var(--text-dim);line-height:1.5;}
|
||||||
|
|
||||||
#chartTip{position:fixed;z-index:1001;background:var(--bg-panel);border:1px solid var(--border);
|
#chartTip{position:fixed;z-index:1001;background:var(--bg-panel);border:1px solid var(--border);
|
||||||
padding:4px 10px;font-family:var(--font-mono);font-size:11px;color:var(--text);
|
padding:4px 10px;font-family:var(--font-mono);font-size:11px;color:var(--text);
|
||||||
pointer-events:none;display:none;white-space:nowrap;box-shadow:0 2px 8px rgba(0,0,0,.5);}
|
pointer-events:none;display:none;white-space:nowrap;box-shadow:0 2px 8px rgba(0,0,0,.5);}
|
||||||
@@ -359,11 +377,39 @@
|
|||||||
<div class="shell-topbar">
|
<div class="shell-topbar">
|
||||||
<div class="brand" id="brandHome"><span class="brand-mark">⛏</span><span class="brand-text">FARM TRACKER</span></div>
|
<div class="brand" id="brandHome"><span class="brand-mark">⛏</span><span class="brand-text">FARM TRACKER</span></div>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
|
<button class="btn-ghost small" id="profileBtn">👤 …</button>
|
||||||
<button class="btn-ghost" id="homeBtn" hidden>🏠 Accueil</button>
|
<button class="btn-ghost" id="homeBtn" hidden>🏠 Accueil</button>
|
||||||
<button class="btn-ghost" id="changeFolderBtn" hidden>Changer de dossier</button>
|
<button class="btn-ghost" id="changeFolderBtn" hidden>Changer de dossier</button>
|
||||||
<button class="btn-ghost small" id="checkUpdateBtn" title="Vérifier les mises à jour">Mises à jour</button>
|
<button class="btn-ghost small" id="checkUpdateBtn" title="Vérifier les mises à jour">Mises à jour</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal profils -->
|
||||||
|
<div class="profile-modal-overlay" id="profileModal" hidden>
|
||||||
|
<div class="profile-modal-box">
|
||||||
|
<div style="display:flex;justify-content:space-between;align-items:center;">
|
||||||
|
<h3>Profils</h3>
|
||||||
|
<button class="btn-ghost small" id="profileModalClose">✕</button>
|
||||||
|
</div>
|
||||||
|
<div class="profile-list" id="profileList"></div>
|
||||||
|
<div class="profile-create-form" id="profileCreateForm" hidden>
|
||||||
|
<input type="text" id="profileNewName" placeholder="Nom du profil" maxlength="40">
|
||||||
|
<div class="profile-mode-row">
|
||||||
|
<label><input type="radio" name="newProfileMode" value="private" checked> Stats de drop privées</label>
|
||||||
|
<label><input type="radio" name="newProfileMode" value="shared"> Stats de drop partagées</label>
|
||||||
|
</div>
|
||||||
|
<p class="profile-mode-desc" id="profileModeDesc">
|
||||||
|
<strong>Privé :</strong> ce profil a ses propres chances de drop, indépendantes des autres.<br>
|
||||||
|
<strong>Partagé :</strong> ce profil partage le même pool de drop stats que tous les autres profils en mode partagé.
|
||||||
|
</p>
|
||||||
|
<div style="display:flex;gap:8px;">
|
||||||
|
<button class="btn-ghost small" id="profileCreateCancel">Annuler</button>
|
||||||
|
<button class="btn-ghost accent small" id="profileCreateConfirm">Créer le profil</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="btn-ghost small" id="profileNewBtn" style="align-self:flex-start;">+ Nouveau profil</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- ============ ÉCRAN 1 : choix du dossier (une seule fois, global) ============ -->
|
<!-- ============ ÉCRAN 1 : choix du dossier (une seule fois, global) ============ -->
|
||||||
<section class="connect-screen" id="folderScreen">
|
<section class="connect-screen" id="folderScreen">
|
||||||
<div class="connect-card">
|
<div class="connect-card">
|
||||||
@@ -901,6 +947,126 @@
|
|||||||
|
|
||||||
const $ = (id) => document.getElementById(id);
|
const $ = (id) => document.getElementById(id);
|
||||||
|
|
||||||
|
// ======================================================================
|
||||||
|
// PROFILS
|
||||||
|
// ======================================================================
|
||||||
|
|
||||||
|
let _profiles = null; // { activeProfileId, profiles: [...] }
|
||||||
|
let _activeProfile = null; // profil actif
|
||||||
|
|
||||||
|
async function loadProfiles() {
|
||||||
|
_profiles = await window.api.getProfiles();
|
||||||
|
_activeProfile = _profiles.profiles.find(p => p.id === _profiles.activeProfileId) || _profiles.profiles[0];
|
||||||
|
renderProfileBtn();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderProfileBtn() {
|
||||||
|
const btn = $('profileBtn');
|
||||||
|
if (btn && _activeProfile) btn.textContent = '👤 ' + _activeProfile.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clé localStorage préfixée par profil (compat : profil "default" = clé sans préfixe)
|
||||||
|
function lsKey(key) {
|
||||||
|
if (!_activeProfile || _activeProfile.id === 'default') return key;
|
||||||
|
return _activeProfile.id + ':' + key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderProfileModal() {
|
||||||
|
const list = $('profileList');
|
||||||
|
if (!list || !_profiles) return;
|
||||||
|
list.innerHTML = _profiles.profiles.map(p => {
|
||||||
|
const isActive = p.id === _profiles.activeProfileId;
|
||||||
|
const modeLabel = p.dropStatsMode === 'shared' ? 'Partagé' : 'Privé';
|
||||||
|
const modeClass = p.dropStatsMode === 'shared' ? 'shared' : '';
|
||||||
|
return '<div class="profile-row' + (isActive ? ' active' : '') + '" data-profile-id="' + escHtml(p.id) + '">' +
|
||||||
|
'<span class="profile-row-name">' + (isActive ? '● ' : '') + escHtml(p.name) + '</span>' +
|
||||||
|
'<button class="profile-row-mode ' + modeClass + '" data-toggle-mode="' + escHtml(p.id) + '" title="Cliquer pour changer le mode de drop stats">' + modeLabel + '</button>' +
|
||||||
|
(isActive ? '' : '<button class="btn-ghost small" data-switch-profile="' + escHtml(p.id) + '">Activer</button>') +
|
||||||
|
(p.id !== 'default' && !isActive ? '<button class="btn-ghost small danger" data-delete-profile="' + escHtml(p.id) + '">✕</button>' : '') +
|
||||||
|
'</div>';
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('profileBtn').addEventListener('click', () => {
|
||||||
|
renderProfileModal();
|
||||||
|
$('profileModal').hidden = false;
|
||||||
|
$('profileCreateForm').hidden = true;
|
||||||
|
});
|
||||||
|
$('profileModalClose').addEventListener('click', () => { $('profileModal').hidden = true; });
|
||||||
|
$('profileModal').addEventListener('click', e => { if (e.target === $('profileModal')) $('profileModal').hidden = true; });
|
||||||
|
|
||||||
|
$('profileNewBtn').addEventListener('click', () => {
|
||||||
|
$('profileCreateForm').hidden = false;
|
||||||
|
$('profileNewBtn').hidden = true;
|
||||||
|
$('profileNewName').value = '';
|
||||||
|
$('profileNewName').focus();
|
||||||
|
});
|
||||||
|
$('profileCreateCancel').addEventListener('click', () => {
|
||||||
|
$('profileCreateForm').hidden = true;
|
||||||
|
$('profileNewBtn').hidden = false;
|
||||||
|
});
|
||||||
|
$('profileCreateConfirm').addEventListener('click', async () => {
|
||||||
|
const name = $('profileNewName').value.trim();
|
||||||
|
if (!name) return;
|
||||||
|
const mode = document.querySelector('input[name="newProfileMode"]:checked')?.value || 'private';
|
||||||
|
_profiles = await window.api.createProfile(name, mode);
|
||||||
|
_activeProfile = _profiles.profiles.find(p => p.id === _profiles.activeProfileId) || _profiles.profiles[0];
|
||||||
|
$('profileCreateForm').hidden = true;
|
||||||
|
$('profileNewBtn').hidden = false;
|
||||||
|
renderProfileModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('profileList').addEventListener('click', async e => {
|
||||||
|
const switchId = e.target.dataset.switchProfile;
|
||||||
|
if (switchId) {
|
||||||
|
await window.api.switchProfile(switchId);
|
||||||
|
location.reload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const deleteId = e.target.dataset.deleteProfile;
|
||||||
|
if (deleteId) {
|
||||||
|
if (!confirm('Supprimer ce profil ? L\'historique et les stats de drop privées seront effacés définitivement.')) return;
|
||||||
|
const res = await window.api.deleteProfile(deleteId);
|
||||||
|
if (res.ok) {
|
||||||
|
_profiles = await window.api.getProfiles();
|
||||||
|
renderProfileModal();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const toggleId = e.target.dataset.toggleMode;
|
||||||
|
if (toggleId) {
|
||||||
|
const p = _profiles.profiles.find(pr => pr.id === toggleId);
|
||||||
|
if (!p) return;
|
||||||
|
const newMode = p.dropStatsMode === 'shared' ? 'private' : 'shared';
|
||||||
|
await window.api.setDropStatsMode(toggleId, newMode);
|
||||||
|
_profiles = await window.api.getProfiles();
|
||||||
|
_activeProfile = _profiles.profiles.find(pr => pr.id === _profiles.activeProfileId) || _profiles.profiles[0];
|
||||||
|
renderProfileModal();
|
||||||
|
// si c'est le profil actif, reload pour recharger les drop stats
|
||||||
|
if (toggleId === _profiles.activeProfileId) {
|
||||||
|
if (confirm('Mode de drop stats changé. Recharger pour appliquer ?')) location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Renommage double-clic sur le nom
|
||||||
|
$('profileList').addEventListener('dblclick', async e => {
|
||||||
|
const row = e.target.closest('.profile-row');
|
||||||
|
if (!row) return;
|
||||||
|
const id = row.dataset.profileId;
|
||||||
|
const nameEl = row.querySelector('.profile-row-name');
|
||||||
|
if (!nameEl) return;
|
||||||
|
const current = _profiles.profiles.find(p => p.id === id);
|
||||||
|
if (!current) return;
|
||||||
|
const newName = prompt('Renommer le profil :', current.name);
|
||||||
|
if (!newName || !newName.trim()) return;
|
||||||
|
await window.api.renameProfile(id, newName.trim());
|
||||||
|
_profiles = await window.api.getProfiles();
|
||||||
|
_activeProfile = _profiles.profiles.find(p => p.id === _profiles.activeProfileId) || _profiles.profiles[0];
|
||||||
|
renderProfileBtn();
|
||||||
|
renderProfileModal();
|
||||||
|
});
|
||||||
|
|
||||||
// ---------- Tooltip pour les graphes ----------
|
// ---------- Tooltip pour les graphes ----------
|
||||||
const chartTip = $('chartTip');
|
const chartTip = $('chartTip');
|
||||||
function showChartTip(text, cx, cy){
|
function showChartTip(text, cx, cy){
|
||||||
@@ -2217,7 +2383,7 @@
|
|||||||
// TIMERS
|
// TIMERS
|
||||||
// ======================================================================
|
// ======================================================================
|
||||||
|
|
||||||
let timerConfigs = JSON.parse(localStorage.getItem('timerConfigs') || '[]');
|
let timerConfigs = JSON.parse(localStorage.getItem(lsKey('timerConfigs')) || '[]');
|
||||||
// ---- Sound catalog ----
|
// ---- Sound catalog ----
|
||||||
const SOUND_CATALOG = [
|
const SOUND_CATALOG = [
|
||||||
{ id:'levelup', label:'Level Up XP', desc:'Montée de niveau', hash:'19034765ba8ba5389b35804ab213537ab5cf706f' },
|
{ id:'levelup', label:'Level Up XP', desc:'Montée de niveau', hash:'19034765ba8ba5389b35804ab213537ab5cf706f' },
|
||||||
@@ -2331,12 +2497,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// migration : ajoute soundId et volume si absents
|
// migration : ajoute soundId et volume si absents
|
||||||
let alertConfigs = JSON.parse(localStorage.getItem('alertConfigs') || '[]').map(c => ({
|
let alertConfigs = JSON.parse(localStorage.getItem(lsKey('alertConfigs')) || '[]').map(c => ({
|
||||||
soundId: 'levelup', volume: 10, ...c
|
soundId: 'levelup', volume: 10, ...c
|
||||||
}));
|
}));
|
||||||
|
|
||||||
function saveAlertConfigs(){
|
function saveAlertConfigs(){
|
||||||
localStorage.setItem('alertConfigs', JSON.stringify(alertConfigs));
|
localStorage.setItem(lsKey('alertConfigs'), JSON.stringify(alertConfigs));
|
||||||
}
|
}
|
||||||
|
|
||||||
// activeTimers : Map<configId, { endsAt: number, durationSec: number, mobName: string }>
|
// activeTimers : Map<configId, { endsAt: number, durationSec: number, mobName: string }>
|
||||||
@@ -2344,7 +2510,7 @@
|
|||||||
let timerClockId = null;
|
let timerClockId = null;
|
||||||
|
|
||||||
function saveTimerConfigs(){
|
function saveTimerConfigs(){
|
||||||
localStorage.setItem('timerConfigs', JSON.stringify(timerConfigs));
|
localStorage.setItem(lsKey('timerConfigs'), JSON.stringify(timerConfigs));
|
||||||
updateTimerTileStatus();
|
updateTimerTileStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2761,6 +2927,13 @@
|
|||||||
// ======================================================================
|
// ======================================================================
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
// Charger les profils en premier (nécessaire avant lsKey et les données)
|
||||||
|
await loadProfiles();
|
||||||
|
|
||||||
|
// Re-lire timerConfigs et alertConfigs maintenant que lsKey est disponible
|
||||||
|
timerConfigs = JSON.parse(localStorage.getItem(lsKey('timerConfigs')) || '[]');
|
||||||
|
alertConfigs = JSON.parse(localStorage.getItem(lsKey('alertConfigs')) || '[]').map(c => ({ soundId: 'levelup', volume: 10, ...c }));
|
||||||
|
|
||||||
let appState = null, dropStatsPlain = null, communityDropStatsPlain = null;
|
let appState = null, dropStatsPlain = null, communityDropStatsPlain = null;
|
||||||
try{ appState = await window.api.loadAppState(); }catch(e){}
|
try{ appState = await window.api.loadAppState(); }catch(e){}
|
||||||
try{ dropStatsPlain = await window.api.loadDropStats(); }catch(e){}
|
try{ dropStatsPlain = await window.api.loadDropStats(); }catch(e){}
|
||||||
|
|||||||
Reference in New Issue
Block a user