chore: formatting fixes
This commit is contained in:
parent
dd6af5e879
commit
119a46c339
167 changed files with 4507 additions and 3248 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { autoUpdater } from 'electron-updater';
|
||||
import { app, dialog, BrowserWindow } from 'electron';
|
||||
import { EventEmitter } from 'events';
|
||||
import { logger } from '../logger';
|
||||
import { autoUpdater } from "electron-updater";
|
||||
import { app, dialog, BrowserWindow } from "electron";
|
||||
import { EventEmitter } from "events";
|
||||
import { logger } from "../logger";
|
||||
|
||||
export class AutoUpdaterService extends EventEmitter {
|
||||
private checkingForUpdate = false;
|
||||
|
|
@ -10,12 +10,12 @@ export class AutoUpdaterService extends EventEmitter {
|
|||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
||||
// Only set up auto-updater in production
|
||||
if (process.env.NODE_ENV !== 'development' && app.isPackaged) {
|
||||
if (process.env.NODE_ENV !== "development" && app.isPackaged) {
|
||||
this.setupAutoUpdater();
|
||||
} else {
|
||||
logger.updater.info('Auto-updater disabled in development mode');
|
||||
logger.updater.info("Auto-updater disabled in development mode");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,20 +29,20 @@ export class AutoUpdaterService extends EventEmitter {
|
|||
autoUpdater.autoInstallOnAppQuit = true;
|
||||
|
||||
// Development settings
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
// In development, you can test with a local update server
|
||||
// autoUpdater.updateConfigPath = path.join(__dirname, 'dev-app-update.yml');
|
||||
autoUpdater.forceDevUpdateConfig = true;
|
||||
}
|
||||
|
||||
// Event handlers
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
logger.updater.info('Checking for update...');
|
||||
autoUpdater.on("checking-for-update", () => {
|
||||
logger.updater.info("Checking for update...");
|
||||
this.checkingForUpdate = true;
|
||||
});
|
||||
|
||||
autoUpdater.on('update-available', (info) => {
|
||||
logger.updater.info('Update available', {
|
||||
autoUpdater.on("update-available", (info) => {
|
||||
logger.updater.info("Update available", {
|
||||
version: info.version,
|
||||
releaseDate: info.releaseDate,
|
||||
});
|
||||
|
|
@ -51,36 +51,39 @@ export class AutoUpdaterService extends EventEmitter {
|
|||
this.showUpdateDialog(info);
|
||||
});
|
||||
|
||||
autoUpdater.on('update-not-available', (info) => {
|
||||
logger.updater.info('Update not available', { version: info.version });
|
||||
autoUpdater.on("update-not-available", (info) => {
|
||||
logger.updater.info("Update not available", { version: info.version });
|
||||
this.checkingForUpdate = false;
|
||||
this.updateAvailable = false;
|
||||
});
|
||||
|
||||
autoUpdater.on('error', (err) => {
|
||||
logger.updater.error('Error in auto-updater', { error: err.message });
|
||||
autoUpdater.on("error", (err) => {
|
||||
logger.updater.error("Error in auto-updater", { error: err.message });
|
||||
this.checkingForUpdate = false;
|
||||
|
||||
|
||||
// Show error dialog only if user manually checked for updates
|
||||
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
|
||||
dialog.showErrorBox('Update Error', `Error checking for updates: ${err.message}`);
|
||||
dialog.showErrorBox(
|
||||
"Update Error",
|
||||
`Error checking for updates: ${err.message}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
autoUpdater.on('download-progress', (progressObj) => {
|
||||
logger.updater.info('Download progress', {
|
||||
autoUpdater.on("download-progress", (progressObj) => {
|
||||
logger.updater.info("Download progress", {
|
||||
bytesPerSecond: progressObj.bytesPerSecond,
|
||||
percent: progressObj.percent,
|
||||
transferred: progressObj.transferred,
|
||||
total: progressObj.total,
|
||||
});
|
||||
|
||||
|
||||
// Emit event for tRPC subscription
|
||||
this.emit('download-progress', progressObj);
|
||||
this.emit("download-progress", progressObj);
|
||||
});
|
||||
|
||||
autoUpdater.on('update-downloaded', (info) => {
|
||||
logger.updater.info('Update downloaded', { version: info.version });
|
||||
autoUpdater.on("update-downloaded", (info) => {
|
||||
logger.updater.info("Update downloaded", { version: info.version });
|
||||
this.showInstallDialog(info);
|
||||
});
|
||||
}
|
||||
|
|
@ -91,20 +94,21 @@ export class AutoUpdaterService extends EventEmitter {
|
|||
}
|
||||
|
||||
const result = await dialog.showMessageBox(this.mainWindow, {
|
||||
type: 'info',
|
||||
title: 'Update Available',
|
||||
type: "info",
|
||||
title: "Update Available",
|
||||
message: `A new version (${info.version}) is available.`,
|
||||
detail: 'Would you like to download it now? The update will be installed when you restart the app.',
|
||||
buttons: ['Download Now', 'Later'],
|
||||
detail:
|
||||
"Would you like to download it now? The update will be installed when you restart the app.",
|
||||
buttons: ["Download Now", "Later"],
|
||||
defaultId: 0,
|
||||
cancelId: 1,
|
||||
});
|
||||
|
||||
if (result.response === 0) {
|
||||
logger.updater.info('User chose to download update');
|
||||
logger.updater.info("User chose to download update");
|
||||
autoUpdater.downloadUpdate();
|
||||
} else {
|
||||
logger.updater.info('User chose to skip update');
|
||||
logger.updater.info("User chose to skip update");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,69 +118,75 @@ export class AutoUpdaterService extends EventEmitter {
|
|||
}
|
||||
|
||||
const result = await dialog.showMessageBox(this.mainWindow, {
|
||||
type: 'info',
|
||||
title: 'Update Ready',
|
||||
type: "info",
|
||||
title: "Update Ready",
|
||||
message: `Update ${info.version} has been downloaded.`,
|
||||
detail: 'The update will be installed when you restart the app. Would you like to restart now?',
|
||||
buttons: ['Restart Now', 'Later'],
|
||||
detail:
|
||||
"The update will be installed when you restart the app. Would you like to restart now?",
|
||||
buttons: ["Restart Now", "Later"],
|
||||
defaultId: 0,
|
||||
cancelId: 1,
|
||||
});
|
||||
|
||||
if (result.response === 0) {
|
||||
logger.updater.info('User chose to restart and install update');
|
||||
logger.updater.info("User chose to restart and install update");
|
||||
autoUpdater.quitAndInstall();
|
||||
} else {
|
||||
logger.updater.info('User chose to install update later');
|
||||
logger.updater.info("User chose to install update later");
|
||||
}
|
||||
}
|
||||
|
||||
async checkForUpdates(userInitiated = false): Promise<void> {
|
||||
// Skip in development
|
||||
if (process.env.NODE_ENV === 'development' || !app.isPackaged) {
|
||||
logger.updater.info('Skipping update check in development mode');
|
||||
if (process.env.NODE_ENV === "development" || !app.isPackaged) {
|
||||
logger.updater.info("Skipping update check in development mode");
|
||||
if (userInitiated && this.mainWindow && !this.mainWindow.isDestroyed()) {
|
||||
dialog.showMessageBox(this.mainWindow, {
|
||||
type: 'info',
|
||||
title: 'Development Mode',
|
||||
message: 'Update checking is disabled in development mode.',
|
||||
buttons: ['OK']
|
||||
type: "info",
|
||||
title: "Development Mode",
|
||||
message: "Update checking is disabled in development mode.",
|
||||
buttons: ["OK"],
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.checkingForUpdate) {
|
||||
logger.updater.info('Already checking for updates');
|
||||
logger.updater.info("Already checking for updates");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
logger.updater.info('Starting update check', { userInitiated });
|
||||
logger.updater.info("Starting update check", { userInitiated });
|
||||
await autoUpdater.checkForUpdates();
|
||||
} catch (error) {
|
||||
logger.updater.error('Failed to check for updates', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
logger.updater.error("Failed to check for updates", {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
|
||||
|
||||
if (userInitiated && this.mainWindow && !this.mainWindow.isDestroyed()) {
|
||||
dialog.showErrorBox('Update Check Failed', 'Failed to check for updates. Please try again later.');
|
||||
dialog.showErrorBox(
|
||||
"Update Check Failed",
|
||||
"Failed to check for updates. Please try again later.",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async checkForUpdatesAndNotify(): Promise<void> {
|
||||
// Skip in development
|
||||
if (process.env.NODE_ENV === 'development' || !app.isPackaged) {
|
||||
logger.updater.info('Skipping background update check in development mode');
|
||||
if (process.env.NODE_ENV === "development" || !app.isPackaged) {
|
||||
logger.updater.info(
|
||||
"Skipping background update check in development mode",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await autoUpdater.checkForUpdatesAndNotify();
|
||||
} catch (error) {
|
||||
logger.updater.error('Failed to check for updates and notify', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
logger.updater.error("Failed to check for updates and notify", {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -191,20 +201,20 @@ export class AutoUpdaterService extends EventEmitter {
|
|||
|
||||
async downloadUpdate(): Promise<void> {
|
||||
// Skip in development
|
||||
if (process.env.NODE_ENV === 'development' || !app.isPackaged) {
|
||||
logger.updater.info('Skipping update download in development mode');
|
||||
throw new Error('Update downloads are disabled in development mode');
|
||||
if (process.env.NODE_ENV === "development" || !app.isPackaged) {
|
||||
logger.updater.info("Skipping update download in development mode");
|
||||
throw new Error("Update downloads are disabled in development mode");
|
||||
}
|
||||
|
||||
if (!this.updateAvailable) {
|
||||
throw new Error('No update available to download');
|
||||
throw new Error("No update available to download");
|
||||
}
|
||||
|
||||
try {
|
||||
await autoUpdater.downloadUpdate();
|
||||
} catch (error) {
|
||||
logger.updater.error('Failed to download update', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
logger.updater.error("Failed to download update", {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -212,11 +222,11 @@ export class AutoUpdaterService extends EventEmitter {
|
|||
|
||||
quitAndInstall(): void {
|
||||
// Skip in development
|
||||
if (process.env.NODE_ENV === 'development' || !app.isPackaged) {
|
||||
logger.updater.info('Skipping quit and install in development mode');
|
||||
if (process.env.NODE_ENV === "development" || !app.isPackaged) {
|
||||
logger.updater.info("Skipping quit and install in development mode");
|
||||
return;
|
||||
}
|
||||
|
||||
autoUpdater.quitAndInstall();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue