Implement server management enhancements with window close handling

- Introduced a checkbox in the ConnectionForm to allow users to keep the server running when the app closes.
- Added a setupWindowCloseHandler function to manage server shutdown based on user preference.
- Updated App component to integrate the new window close handling logic.
- Created a reusable Checkbox component for better UI consistency.
- Modified serverStore to include state management for the new setting.
This commit is contained in:
Jamie Pine
2026-01-25 12:13:35 -08:00
parent 9b7ee21e6c
commit 7b1e2295ef
6 changed files with 172 additions and 8 deletions
@@ -13,6 +13,7 @@ import {
FormMessage,
} from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { Checkbox } from '@/components/ui/checkbox';
import { useToast } from '@/components/ui/use-toast';
import { useServerStore } from '@/stores/serverStore';
@@ -25,6 +26,8 @@ type ConnectionFormValues = z.infer<typeof connectionSchema>;
export function ConnectionForm() {
const serverUrl = useServerStore((state) => state.serverUrl);
const setServerUrl = useServerStore((state) => state.setServerUrl);
const keepServerRunningOnClose = useServerStore((state) => state.keepServerRunningOnClose);
const setKeepServerRunningOnClose = useServerStore((state) => state.setKeepServerRunningOnClose);
const { toast } = useToast();
const form = useForm<ConnectionFormValues>({
@@ -68,6 +71,36 @@ export function ConnectionForm() {
<Button type="submit">Update Connection</Button>
</form>
</Form>
<div className="mt-6 pt-6 border-t">
<div className="flex items-start space-x-3">
<Checkbox
id="keepServerRunning"
checked={keepServerRunningOnClose}
onCheckedChange={(checked: boolean) => {
setKeepServerRunningOnClose(checked);
toast({
title: 'Setting updated',
description: checked
? 'Server will continue running when app closes'
: 'Server will stop when app closes',
});
}}
/>
<div className="space-y-1">
<label
htmlFor="keepServerRunning"
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
>
Keep server running when app closes
</label>
<p className="text-sm text-muted-foreground">
When enabled, the server will continue running in the background after closing the app.
Disabled by default.
</p>
</div>
</div>
</div>
</CardContent>
</Card>
);