Make window miniizeable

This commit is contained in:
2025-06-28 01:20:04 +02:00
parent ecc900161a
commit 4bf0f366eb
2 changed files with 63 additions and 47 deletions

View File

@@ -2,9 +2,12 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"windows": [
"main"
],
"permissions": [
"core:default",
"opener:default"
"opener:default",
"core:window:allow-minimize"
]
}

View File

@@ -8,7 +8,7 @@ import { Input } from '@/components/ui/input';
import { Slider } from '@/components/ui/slider';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { toast } from '@/hooks/use-toast';
import { Quit } from '../../wailsjs/go/main/App';
import { Window } from '@tauri-apps/api/window';
interface Note {
id: string;
@@ -52,7 +52,6 @@ const Index = () => {
const [minLetterCount, setMinLetterCount] = useState([10]);
const [isInitialized, setIsInitialized] = useState(false);
const [fontSize, setFontSize] = useState('medium');
const [isCurrentNoteModified, setIsCurrentNoteModified] = useState(false);
const [isPreviousNoteModified, setIsPreviousNoteModified] = useState(false);
const previousNoteRef = useRef<HTMLDivElement>(null);
@@ -536,7 +535,8 @@ const Index = () => {
};
// Handle current note save with debounce and content check
const handleSaveCurrentNote = async () => {
const handleSaveCurrentNote = () => {
return new Promise<void>((resolve) => {
const trimmedContent = currentNote.trim();
// Clear any pending save timeout
@@ -551,9 +551,12 @@ const Index = () => {
await createNote(currentNote);
lastSavedContentRef.current = trimmedContent;
setCurrentNote('');
setIsCurrentNoteModified(false);
resolve();
}, 300); // 300ms debounce
} else {
resolve();
}
});
};
// Handle previous note scroll (reversed direction)
@@ -625,7 +628,8 @@ const Index = () => {
// Update the keyboard shortcuts effect
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
const handleKeyDown = async (e: KeyboardEvent) => {
try {
if (e.ctrlKey && e.key === 'f') {
e.preventDefault();
setIsSearchOpen(true);
@@ -634,18 +638,28 @@ const Index = () => {
}, 100);
} else if (e.key === 'Escape') {
e.preventDefault();
// Save current note if it has content - no need for additional check since handleSaveCurrentNote has debounce
handleSaveCurrentNote();
// Save current note if it has content
if (currentNote.trim()) {
await handleSaveCurrentNote();
}
// Save previous note if it has been modified
if (previousNote && isPreviousNoteModified) {
handlePreviousNoteBlur();
await handlePreviousNoteBlur();
}
// Save scratch pad if it has content
if (scratchPad.trim()) {
saveScratch(scratchPad);
await saveScratch(scratchPad);
}
// Quit the application
Quit();
// Minimize the window
try {
const win = await Window.getCurrent();
await win.minimize();
} catch (error) {
console.error('Failed to minimize window:', error);
}
}
} catch (error) {
console.error('Error in keyboard handler:', error);
}
};
@@ -1085,7 +1099,6 @@ const Index = () => {
value={currentNote}
onChange={(e) => {
setCurrentNote(e.target.value);
setIsCurrentNoteModified(true);
}}
onBlur={handleCurrentNoteBlur}
className={`h-[calc(100%-2rem)] border-0 resize-none focus:ring-0 text-slate-200 bg-transparent ${getTextClass('2xl')}`}