- Implemented `AdvancedGenerationOptions` component for toggling Explicit and Smart modes with confirmation dialogs. - Integrated generation options into `GhostWriter`, `DraftCompanion`, and `ShortStoryGenerator`. - Introduced `ToggleWithConfirmation` component for user interaction with alerts. - Updated `InputField` to support centered alignment for better layout flexibility. - Localized Explicit and Smart mode strings in English and French. - Enhanced content preview logic to filter placeholder text before display. - Added `autoUpdater` initialization checks and refactored updater setup for improved reliability.
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import pkg from 'electron-updater';
|
|
import type { UpdateInfo } from 'electron-updater';
|
|
const { autoUpdater } = pkg;
|
|
import { app, BrowserWindow } from 'electron';
|
|
|
|
const updateCheckInterval = 4 * 60 * 60 * 1000; // 4 heures
|
|
|
|
let initialized = false;
|
|
let currentWindow: BrowserWindow | null = null;
|
|
|
|
export function initAutoUpdater(window: BrowserWindow): void {
|
|
currentWindow = window;
|
|
|
|
if (!app.isPackaged) {
|
|
console.log('[AutoUpdater] Skipped in development mode');
|
|
return;
|
|
}
|
|
|
|
// Si déjà initialisé, juste mettre à jour la fenêtre cible
|
|
if (initialized) {
|
|
console.log('[AutoUpdater] Window target updated');
|
|
return;
|
|
}
|
|
|
|
initialized = true;
|
|
|
|
// Config: télécharge auto, installe au quit
|
|
autoUpdater.autoDownload = true;
|
|
autoUpdater.autoInstallOnAppQuit = true;
|
|
|
|
autoUpdater.on('checking-for-update', () => {
|
|
console.log('[AutoUpdater] Checking for updates...');
|
|
});
|
|
|
|
autoUpdater.on('update-available', (info: UpdateInfo) => {
|
|
console.log('[AutoUpdater] Update available:', info.version);
|
|
currentWindow?.webContents.send('update:available', info.version);
|
|
});
|
|
|
|
autoUpdater.on('update-not-available', () => {
|
|
console.log('[AutoUpdater] App is up to date');
|
|
});
|
|
|
|
autoUpdater.on('download-progress', (progress) => {
|
|
const percent = Math.round(progress.percent);
|
|
console.log(`[AutoUpdater] Downloading: ${percent}%`);
|
|
currentWindow?.webContents.send('update:progress', percent);
|
|
});
|
|
|
|
autoUpdater.on('update-downloaded', (info: UpdateInfo) => {
|
|
console.log('[AutoUpdater] Update ready:', info.version);
|
|
currentWindow?.webContents.send('update:ready', info.version);
|
|
});
|
|
|
|
autoUpdater.on('error', (error: Error) => {
|
|
console.error('[AutoUpdater] Error:', error.message);
|
|
});
|
|
|
|
// Check initial
|
|
autoUpdater.checkForUpdates().catch((err) => {
|
|
console.error('[AutoUpdater] Check failed:', err.message);
|
|
});
|
|
|
|
// Re-check périodique
|
|
setInterval(() => {
|
|
autoUpdater.checkForUpdates().catch((err) => {
|
|
console.error('[AutoUpdater] Periodic check failed:', err.message);
|
|
});
|
|
}, updateCheckInterval);
|
|
}
|
|
|
|
// Pour forcer l'installation immédiate (optionnel, appelable depuis le renderer)
|
|
export function installUpdateNow(): void {
|
|
autoUpdater.quitAndInstall(false, true);
|
|
} |