mirror of
https://github.com/aljazceru/goose.git
synced 2026-01-05 15:34:30 +01:00
Add a setting for the quit confirmation dialog (#2901)
This commit is contained in:
@@ -13,6 +13,7 @@ interface AppSettingsSectionProps {
|
||||
export default function AppSettingsSection({ scrollToSection }: AppSettingsSectionProps) {
|
||||
const [menuBarIconEnabled, setMenuBarIconEnabled] = useState(true);
|
||||
const [dockIconEnabled, setDockIconEnabled] = useState(true);
|
||||
const [quitConfirmationEnabled, setQuitConfirmationEnabled] = useState(true);
|
||||
const [isMacOS, setIsMacOS] = useState(false);
|
||||
const [isDockSwitchDisabled, setIsDockSwitchDisabled] = useState(false);
|
||||
const [showNotificationModal, setShowNotificationModal] = useState(false);
|
||||
@@ -39,6 +40,10 @@ export default function AppSettingsSection({ scrollToSection }: AppSettingsSecti
|
||||
setMenuBarIconEnabled(enabled);
|
||||
});
|
||||
|
||||
window.electron.getQuitConfirmationState().then((enabled) => {
|
||||
setQuitConfirmationEnabled(enabled);
|
||||
});
|
||||
|
||||
if (isMacOS) {
|
||||
window.electron.getDockIconState().then((enabled) => {
|
||||
setDockIconEnabled(enabled);
|
||||
@@ -86,6 +91,14 @@ export default function AppSettingsSection({ scrollToSection }: AppSettingsSecti
|
||||
}
|
||||
};
|
||||
|
||||
const handleQuitConfirmationToggle = async () => {
|
||||
const newState = !quitConfirmationEnabled;
|
||||
const success = await window.electron.setQuitConfirmation(newState);
|
||||
if (success) {
|
||||
setQuitConfirmationEnabled(newState);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<section id="appSettings" className="px-8">
|
||||
<div className="flex justify-between items-center mb-2">
|
||||
@@ -159,6 +172,22 @@ export default function AppSettingsSection({ scrollToSection }: AppSettingsSecti
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<h3 className="text-textStandard">Quit Confirmation</h3>
|
||||
<p className="text-xs text-textSubtle 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>
|
||||
</div>
|
||||
|
||||
{/* Help & Feedback Section */}
|
||||
|
||||
@@ -872,6 +872,29 @@ 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;
|
||||
}
|
||||
});
|
||||
|
||||
// Add file/directory selection handler
|
||||
ipcMain.handle('select-file-or-directory', async () => {
|
||||
const result = (await dialog.showOpenDialog({
|
||||
@@ -1822,6 +1845,12 @@ app.on('before-quit', async (event) => {
|
||||
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();
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ type ElectronAPI = {
|
||||
getMenuBarIconState: () => Promise<boolean>;
|
||||
setDockIcon: (show: boolean) => Promise<boolean>;
|
||||
getDockIconState: () => Promise<boolean>;
|
||||
setQuitConfirmation: (show: boolean) => Promise<boolean>;
|
||||
getQuitConfirmationState: () => Promise<boolean>;
|
||||
openNotificationsSettings: () => Promise<boolean>;
|
||||
on: (
|
||||
channel: string,
|
||||
@@ -139,6 +141,8 @@ const electronAPI: ElectronAPI = {
|
||||
getMenuBarIconState: () => ipcRenderer.invoke('get-menu-bar-icon-state'),
|
||||
setDockIcon: (show: boolean) => ipcRenderer.invoke('set-dock-icon', show),
|
||||
getDockIconState: () => ipcRenderer.invoke('get-dock-icon-state'),
|
||||
setQuitConfirmation: (show: boolean) => ipcRenderer.invoke('set-quit-confirmation', show),
|
||||
getQuitConfirmationState: () => ipcRenderer.invoke('get-quit-confirmation-state'),
|
||||
openNotificationsSettings: () => ipcRenderer.invoke('open-notifications-settings'),
|
||||
on: (
|
||||
channel: string,
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface Settings {
|
||||
envToggles: EnvToggles;
|
||||
showMenuBarIcon: boolean;
|
||||
showDockIcon: boolean;
|
||||
showQuitConfirmation: boolean;
|
||||
}
|
||||
|
||||
// Constants
|
||||
@@ -24,6 +25,7 @@ const defaultSettings: Settings = {
|
||||
},
|
||||
showMenuBarIcon: true,
|
||||
showDockIcon: true,
|
||||
showQuitConfirmation: true,
|
||||
};
|
||||
|
||||
// Settings management
|
||||
|
||||
Reference in New Issue
Block a user