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