Don't show a confirm dialog for quitting (#4225)
This commit is contained in:
@@ -18,7 +18,6 @@ interface AppSettingsSectionProps {
|
|||||||
export default function AppSettingsSection({ scrollToSection }: AppSettingsSectionProps) {
|
export default function AppSettingsSection({ scrollToSection }: AppSettingsSectionProps) {
|
||||||
const [menuBarIconEnabled, setMenuBarIconEnabled] = useState(true);
|
const [menuBarIconEnabled, setMenuBarIconEnabled] = useState(true);
|
||||||
const [dockIconEnabled, setDockIconEnabled] = useState(true);
|
const [dockIconEnabled, setDockIconEnabled] = useState(true);
|
||||||
const [quitConfirmationEnabled, setQuitConfirmationEnabled] = useState(true);
|
|
||||||
const [wakelockEnabled, setWakelockEnabled] = useState(true);
|
const [wakelockEnabled, setWakelockEnabled] = useState(true);
|
||||||
const [isMacOS, setIsMacOS] = useState(false);
|
const [isMacOS, setIsMacOS] = useState(false);
|
||||||
const [isDockSwitchDisabled, setIsDockSwitchDisabled] = useState(false);
|
const [isDockSwitchDisabled, setIsDockSwitchDisabled] = useState(false);
|
||||||
@@ -144,10 +143,6 @@ export default function AppSettingsSection({ scrollToSection }: AppSettingsSecti
|
|||||||
setMenuBarIconEnabled(enabled);
|
setMenuBarIconEnabled(enabled);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.electron.getQuitConfirmationState().then((enabled) => {
|
|
||||||
setQuitConfirmationEnabled(enabled);
|
|
||||||
});
|
|
||||||
|
|
||||||
window.electron.getWakelockState().then((enabled) => {
|
window.electron.getWakelockState().then((enabled) => {
|
||||||
setWakelockEnabled(enabled);
|
setWakelockEnabled(enabled);
|
||||||
});
|
});
|
||||||
@@ -199,14 +194,6 @@ export default function AppSettingsSection({ scrollToSection }: AppSettingsSecti
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleQuitConfirmationToggle = async () => {
|
|
||||||
const newState = !quitConfirmationEnabled;
|
|
||||||
const success = await window.electron.setQuitConfirmation(newState);
|
|
||||||
if (success) {
|
|
||||||
setQuitConfirmationEnabled(newState);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleWakelockToggle = async () => {
|
const handleWakelockToggle = async () => {
|
||||||
const newState = !wakelockEnabled;
|
const newState = !wakelockEnabled;
|
||||||
const success = await window.electron.setWakelock(newState);
|
const success = await window.electron.setWakelock(newState);
|
||||||
@@ -295,23 +282,6 @@ export default function AppSettingsSection({ scrollToSection }: AppSettingsSecti
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Quit Confirmation */}
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div>
|
|
||||||
<h3 className="text-text-default text-xs">Quit confirmation</h3>
|
|
||||||
<p className="text-xs text-text-muted max-w-md mt-[2px]">
|
|
||||||
Show confirmation dialog when quitting the app
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center">
|
|
||||||
<Switch
|
|
||||||
checked={quitConfirmationEnabled}
|
|
||||||
onCheckedChange={handleQuitConfirmationToggle}
|
|
||||||
variant="mono"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Prevent Sleep */}
|
{/* Prevent Sleep */}
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1267,29 +1267,6 @@ ipcMain.handle('open-notifications-settings', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle quit confirmation setting
|
|
||||||
ipcMain.handle('set-quit-confirmation', async (_event, show: boolean) => {
|
|
||||||
try {
|
|
||||||
const settings = loadSettings();
|
|
||||||
settings.showQuitConfirmation = show;
|
|
||||||
saveSettings(settings);
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error setting quit confirmation:', error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle('get-quit-confirmation-state', () => {
|
|
||||||
try {
|
|
||||||
const settings = loadSettings();
|
|
||||||
return settings.showQuitConfirmation ?? true;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error getting quit confirmation state:', error);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle wakelock setting
|
// Handle wakelock setting
|
||||||
ipcMain.handle('set-wakelock', async (_event, enable: boolean) => {
|
ipcMain.handle('set-wakelock', async (_event, enable: boolean) => {
|
||||||
try {
|
try {
|
||||||
@@ -2317,48 +2294,6 @@ app.on('will-quit', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS or if we have a tray icon.
|
|
||||||
// Add confirmation dialog when quitting with Cmd+Q (skip in dev mode)
|
|
||||||
app.on('before-quit', async (event) => {
|
|
||||||
// Skip confirmation dialog in development mode
|
|
||||||
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
|
|
||||||
return; // Allow normal quit behavior in dev mode
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if quit confirmation is enabled in settings
|
|
||||||
const settings = loadSettings();
|
|
||||||
if (!settings.showQuitConfirmation) {
|
|
||||||
return; // Allow normal quit behavior if confirmation is disabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent the default quit behavior
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
// Show confirmation dialog
|
|
||||||
try {
|
|
||||||
const result = (await dialog.showMessageBox({
|
|
||||||
type: 'question',
|
|
||||||
buttons: ['Quit', 'Cancel'],
|
|
||||||
defaultId: 1, // Default to Cancel
|
|
||||||
title: 'Confirm Quit',
|
|
||||||
message: 'Are you sure you want to quit Goose?',
|
|
||||||
detail: 'Any unsaved changes may be lost.',
|
|
||||||
})) as unknown as { response: number };
|
|
||||||
|
|
||||||
if (result.response === 0) {
|
|
||||||
// User clicked "Quit"
|
|
||||||
// Set a flag to avoid showing the dialog again
|
|
||||||
app.removeAllListeners('before-quit');
|
|
||||||
// Force quit the app
|
|
||||||
process.nextTick(() => {
|
|
||||||
app.exit(0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error showing quit dialog:', error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
// Only quit if we're not on macOS or don't have a tray icon
|
// Only quit if we're not on macOS or don't have a tray icon
|
||||||
if (process.platform !== 'darwin' || !tray) {
|
if (process.platform !== 'darwin' || !tray) {
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ type ElectronAPI = {
|
|||||||
getSettings: () => Promise<unknown | null>;
|
getSettings: () => Promise<unknown | null>;
|
||||||
getSecretKey: () => Promise<string>;
|
getSecretKey: () => Promise<string>;
|
||||||
setSchedulingEngine: (engine: string) => Promise<boolean>;
|
setSchedulingEngine: (engine: string) => Promise<boolean>;
|
||||||
setQuitConfirmation: (show: boolean) => Promise<boolean>;
|
|
||||||
getQuitConfirmationState: () => Promise<boolean>;
|
|
||||||
setWakelock: (enable: boolean) => Promise<boolean>;
|
setWakelock: (enable: boolean) => Promise<boolean>;
|
||||||
getWakelockState: () => Promise<boolean>;
|
getWakelockState: () => Promise<boolean>;
|
||||||
openNotificationsSettings: () => Promise<boolean>;
|
openNotificationsSettings: () => Promise<boolean>;
|
||||||
@@ -177,8 +175,6 @@ const electronAPI: ElectronAPI = {
|
|||||||
getSettings: () => ipcRenderer.invoke('get-settings'),
|
getSettings: () => ipcRenderer.invoke('get-settings'),
|
||||||
getSecretKey: () => ipcRenderer.invoke('get-secret-key'),
|
getSecretKey: () => ipcRenderer.invoke('get-secret-key'),
|
||||||
setSchedulingEngine: (engine: string) => ipcRenderer.invoke('set-scheduling-engine', engine),
|
setSchedulingEngine: (engine: string) => ipcRenderer.invoke('set-scheduling-engine', engine),
|
||||||
setQuitConfirmation: (show: boolean) => ipcRenderer.invoke('set-quit-confirmation', show),
|
|
||||||
getQuitConfirmationState: () => ipcRenderer.invoke('get-quit-confirmation-state'),
|
|
||||||
setWakelock: (enable: boolean) => ipcRenderer.invoke('set-wakelock', enable),
|
setWakelock: (enable: boolean) => ipcRenderer.invoke('set-wakelock', enable),
|
||||||
getWakelockState: () => ipcRenderer.invoke('get-wakelock-state'),
|
getWakelockState: () => ipcRenderer.invoke('get-wakelock-state'),
|
||||||
openNotificationsSettings: () => ipcRenderer.invoke('open-notifications-settings'),
|
openNotificationsSettings: () => ipcRenderer.invoke('open-notifications-settings'),
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ export interface Settings {
|
|||||||
showMenuBarIcon: boolean;
|
showMenuBarIcon: boolean;
|
||||||
showDockIcon: boolean;
|
showDockIcon: boolean;
|
||||||
schedulingEngine: SchedulingEngine;
|
schedulingEngine: SchedulingEngine;
|
||||||
showQuitConfirmation: boolean;
|
|
||||||
enableWakelock: boolean;
|
enableWakelock: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ const defaultSettings: Settings = {
|
|||||||
showMenuBarIcon: true,
|
showMenuBarIcon: true,
|
||||||
showDockIcon: true,
|
showDockIcon: true,
|
||||||
schedulingEngine: 'builtin-cron',
|
schedulingEngine: 'builtin-cron',
|
||||||
showQuitConfirmation: true,
|
|
||||||
enableWakelock: false,
|
enableWakelock: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user