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) {
|
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 [isMacOS, setIsMacOS] = useState(false);
|
const [isMacOS, setIsMacOS] = useState(false);
|
||||||
const [isDockSwitchDisabled, setIsDockSwitchDisabled] = useState(false);
|
const [isDockSwitchDisabled, setIsDockSwitchDisabled] = useState(false);
|
||||||
const [showNotificationModal, setShowNotificationModal] = useState(false);
|
const [showNotificationModal, setShowNotificationModal] = useState(false);
|
||||||
@@ -39,6 +40,10 @@ export default function AppSettingsSection({ scrollToSection }: AppSettingsSecti
|
|||||||
setMenuBarIconEnabled(enabled);
|
setMenuBarIconEnabled(enabled);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.electron.getQuitConfirmationState().then((enabled) => {
|
||||||
|
setQuitConfirmationEnabled(enabled);
|
||||||
|
});
|
||||||
|
|
||||||
if (isMacOS) {
|
if (isMacOS) {
|
||||||
window.electron.getDockIconState().then((enabled) => {
|
window.electron.getDockIconState().then((enabled) => {
|
||||||
setDockIconEnabled(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 (
|
return (
|
||||||
<section id="appSettings" className="px-8">
|
<section id="appSettings" className="px-8">
|
||||||
<div className="flex justify-between items-center mb-2">
|
<div className="flex justify-between items-center mb-2">
|
||||||
@@ -159,6 +172,22 @@ export default function AppSettingsSection({ scrollToSection }: AppSettingsSecti
|
|||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
|
|
||||||
{/* Help & Feedback Section */}
|
{/* 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
|
// Add file/directory selection handler
|
||||||
ipcMain.handle('select-file-or-directory', async () => {
|
ipcMain.handle('select-file-or-directory', async () => {
|
||||||
const result = (await dialog.showOpenDialog({
|
const result = (await dialog.showOpenDialog({
|
||||||
@@ -1822,6 +1845,12 @@ app.on('before-quit', async (event) => {
|
|||||||
return; // Allow normal quit behavior in dev mode
|
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
|
// Prevent the default quit behavior
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ type ElectronAPI = {
|
|||||||
getMenuBarIconState: () => Promise<boolean>;
|
getMenuBarIconState: () => Promise<boolean>;
|
||||||
setDockIcon: (show: boolean) => Promise<boolean>;
|
setDockIcon: (show: boolean) => Promise<boolean>;
|
||||||
getDockIconState: () => Promise<boolean>;
|
getDockIconState: () => Promise<boolean>;
|
||||||
|
setQuitConfirmation: (show: boolean) => Promise<boolean>;
|
||||||
|
getQuitConfirmationState: () => Promise<boolean>;
|
||||||
openNotificationsSettings: () => Promise<boolean>;
|
openNotificationsSettings: () => Promise<boolean>;
|
||||||
on: (
|
on: (
|
||||||
channel: string,
|
channel: string,
|
||||||
@@ -139,6 +141,8 @@ const electronAPI: ElectronAPI = {
|
|||||||
getMenuBarIconState: () => ipcRenderer.invoke('get-menu-bar-icon-state'),
|
getMenuBarIconState: () => ipcRenderer.invoke('get-menu-bar-icon-state'),
|
||||||
setDockIcon: (show: boolean) => ipcRenderer.invoke('set-dock-icon', show),
|
setDockIcon: (show: boolean) => ipcRenderer.invoke('set-dock-icon', show),
|
||||||
getDockIconState: () => ipcRenderer.invoke('get-dock-icon-state'),
|
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'),
|
openNotificationsSettings: () => ipcRenderer.invoke('open-notifications-settings'),
|
||||||
on: (
|
on: (
|
||||||
channel: string,
|
channel: string,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export interface Settings {
|
|||||||
envToggles: EnvToggles;
|
envToggles: EnvToggles;
|
||||||
showMenuBarIcon: boolean;
|
showMenuBarIcon: boolean;
|
||||||
showDockIcon: boolean;
|
showDockIcon: boolean;
|
||||||
|
showQuitConfirmation: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
@@ -24,6 +25,7 @@ const defaultSettings: Settings = {
|
|||||||
},
|
},
|
||||||
showMenuBarIcon: true,
|
showMenuBarIcon: true,
|
||||||
showDockIcon: true,
|
showDockIcon: true,
|
||||||
|
showQuitConfirmation: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Settings management
|
// Settings management
|
||||||
|
|||||||
Reference in New Issue
Block a user