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>
);
+36
View File
@@ -0,0 +1,36 @@
import * as React from 'react';
import { cn } from '@/lib/utils/cn';
export interface CheckboxProps extends React.InputHTMLAttributes<HTMLInputElement> {
onCheckedChange?: (checked: boolean) => void;
}
const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
({ className, onCheckedChange, ...props }, ref) => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (onCheckedChange) {
onCheckedChange(e.target.checked);
}
// Call original onChange if provided
if (props.onChange) {
props.onChange(e);
}
};
return (
<input
type="checkbox"
className={cn(
'h-4 w-4 rounded border-gray-300 text-primary focus:ring-2 focus:ring-primary focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
ref={ref}
onChange={handleChange}
{...props}
/>
);
},
);
Checkbox.displayName = 'Checkbox';
export { Checkbox };