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
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"homepage": "https://comfy.org",
"description": "The best modular GUI to run AI diffusion models.",
"main": ".vite/build/main.js",
"packageManager": "[email protected].0",
"packageManager": "[email protected].1",
"scripts": {
oto-ciulis-tt marked this conversation as resolved.
Show resolved Hide resolved
"clean": "rimraf .vite dist out",
"clean:assets": "rimraf assets/.env assets/ComfyUI assets/python.tgz & yarn run clean:assets:dev",
Expand Down
21 changes: 21 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 {
}
}

private saveSettings() {
try {
const dirname = path.dirname(this.filePath);
if (!fs.existsSync(dirname)) {
log.info(`Settings directory ${dirname} does not exist, creating ...`);
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,11 @@ export class ComfySettings {
return this.settings['Comfy-Desktop.SendCrashStatistics'] ?? true;
}

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

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
26 changes: 26 additions & 0 deletions src/renderer/screens/FirstTimeSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface FirstTimeSetupProps {

const FirstTimeSetup: React.FC<FirstTimeSetupProps> = ({ onComplete, initialPath }) => {
const [selectedPath, setSelectedPath] = useState<string>(initialPath);
const [sendCrashReports, setSendCrashReports] = useState(true);
const electronAPI: ElectronAPI = (window as any).electronAPI;

const handleDirectoryChange = async () => {
Expand All @@ -30,6 +31,8 @@ const FirstTimeSetup: React.FC<FirstTimeSetupProps> = ({ onComplete, initialPath
if (selectedPath) {
log.info('Installing to directory', selectedPath);
electronAPI.selectSetupDirectory(selectedPath);
electronAPI.setSendCrashReports(sendCrashReports);

onComplete(selectedPath);
} else {
log.error('No directory selected for installation');
Expand Down Expand Up @@ -72,6 +75,16 @@ const FirstTimeSetup: React.FC<FirstTimeSetupProps> = ({ onComplete, initialPath
</button>
</div>

<div style={styles.crashReportsContainer}>
<input
title="send-crash-reports"
type="checkbox"
checked={sendCrashReports}
onChange={(e) => setSendCrashReports(e.currentTarget.checked)}
></input>
<p style={styles.sendCrashReportsText}>Send crash reports</p>
</div>

<div style={styles.buttonContainer}>
<button onClick={handleInstall} style={styles.installButton}>
Install
Expand Down Expand Up @@ -101,6 +114,11 @@ const styles = {
marginBottom: '20px',
lineHeight: '1.5',
},
sendCrashReportsText: {
textAlign: 'center' as const,
marginBottom: '20px',
lineHeight: '1.5',
},
button: {
padding: '10px 20px',
fontSize: '14px',
Expand Down Expand Up @@ -130,6 +148,14 @@ const styles = {
marginBottom: '20px',
marginTop: '10px',
},
crashReportsContainer: {
display: 'flex',
flexDirection: 'row' as const,
alignItems: 'center',
justifyContent: 'center',
gap: '10px',
marginBottom: '10px',
},
pathDisplay: {
padding: '10px',
backgroundColor: '#2d2d2d',
Expand Down
Loading