Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: Ask user: Capture error in Sentry when app crashes #184

Merged
20 changes: 20 additions & 0 deletions src/config/comfySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ export class ComfySettings {
}
}

public saveSettings() {
try {
const dirname = path.dirname(this.filePath);
if (!fs.existsSync(dirname)) {
log.info(`Settings directory ${dirname} does not exist, creating ...`);
oto-ciulis-tt marked this conversation as resolved.
Show resolved Hide resolved
fs.mkdirSync(dirname, {
recursive: true,
});
}

fs.writeFileSync(this.filePath, JSON.stringify(this.settings), 'utf-8');
} catch (error) {
log.error(`Failed to save settings to ${this.filePath}:`, error);
}
}

get autoUpdate(): boolean {
return this.settings['Comfy-Desktop.AutoUpdate'] ?? true;
}
Expand All @@ -42,6 +58,10 @@ export class ComfySettings {
return this.settings['Comfy-Desktop.SendCrashStatistics'] ?? true;
}

set sendCrashStatistics(value: boolean) {
this.settings['Comfy-Desktop.SendCrashStatistics'] = value;
}

oto-ciulis-tt marked this conversation as resolved.
Show resolved Hide resolved
public reload(): void {
this.settings = this.loadSettings();
}
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const IPC_CHANNELS = {
CANCEL_DOWNLOAD: 'cancel-download',
DELETE_MODEL: 'delete-model',
GET_ALL_DOWNLOADS: 'get-all-downloads',
SET_SEND_CRASH_REPORTS: 'set-send-crash-reports',
GET_ELECTRON_VERSION: 'get-electron-version',
SEND_ERROR_TO_SENTRY: 'send-error-to-sentry',
GET_BASE_PATH: 'get-base-path',
Expand Down
21 changes: 18 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const gotTheLock = app.requestSingleInstanceLock();

if (!gotTheLock) {
log.info('App already running. Exiting...');

app.quit();
} else {
store = new Store<StoreType>();
Expand All @@ -106,13 +107,24 @@ if (!gotTheLock) {
Sentry.init({
dsn: SENTRY_URL_ENDPOINT,
autoSessionTracking: false,
beforeSend(event, hint) {
async beforeSend(event, hint) {
if (event.extra?.comfyUIExecutionError) {
return event;
}

//TODO (use default pop up behavior).
return event;
let sendCrashReport = comfySettings.sendCrashStatistics;

if (!sendCrashReport) {
const { response } = await dialog.showMessageBox({
title: 'Send Crash Statistics',
message: `Would you like to send crash statistics to the team?`,
buttons: ['Always send crash reports', 'Do not send crash report'],
});

sendCrashReport = response === 0;
}

return sendCrashReport ? event : null;
oto-ciulis-tt marked this conversation as resolved.
Show resolved Hide resolved
},
integrations: [
Sentry.childProcessIntegration({
Expand Down Expand Up @@ -198,6 +210,9 @@ if (!gotTheLock) {
ipcMain.on(IPC_CHANNELS.OPEN_DEV_TOOLS, () => {
mainWindow?.webContents.openDevTools();
});
ipcMain.on(IPC_CHANNELS.SET_SEND_CRASH_REPORTS, (_event, value) => {
comfySettings.sendCrashStatistics = value;
oto-ciulis-tt marked this conversation as resolved.
Show resolved Hide resolved
});
ipcMain.handle(IPC_CHANNELS.IS_PACKAGED, () => {
return app.isPackaged;
});
Expand Down
3 changes: 3 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const electronAPI = {
selectSetupDirectory: (directory: string) => {
ipcRenderer.send(IPC_CHANNELS.SELECTED_DIRECTORY, directory);
},
setSendCrashReports: (sendCrashReports: boolean) => {
ipcRenderer.send(IPC_CHANNELS.SET_SEND_CRASH_REPORTS, sendCrashReports);
oto-ciulis-tt marked this conversation as resolved.
Show resolved Hide resolved
},
openDialog: (options: Electron.OpenDialogOptions) => {
return ipcRenderer.invoke(IPC_CHANNELS.OPEN_DIALOG, options);
},
Expand Down
Loading