Make window miniizeable
This commit is contained in:
@@ -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"
|
||||||
]
|
]
|
||||||
}
|
}
|
@@ -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);
|
||||||
@@ -161,7 +160,7 @@ const Index = () => {
|
|||||||
const trimmedContent = cleanContent(content);
|
const trimmedContent = cleanContent(content);
|
||||||
const { mostFrequentLetter, mostFrequentLetterFrequency, letterCount } = calculateLetterFrequency(trimmedContent);
|
const { mostFrequentLetter, mostFrequentLetterFrequency, letterCount } = calculateLetterFrequency(trimmedContent);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
const document = {
|
const document = {
|
||||||
id: generateRandomString(32),
|
id: generateRandomString(32),
|
||||||
date: now.getTime(),
|
date: now.getTime(),
|
||||||
@@ -199,7 +198,7 @@ const Index = () => {
|
|||||||
setNoteCache(prev => [newNote, ...prev]);
|
setNoteCache(prev => [newNote, ...prev]);
|
||||||
setPreviousNote(newNote);
|
setPreviousNote(newNote);
|
||||||
setCurrentNoteIndex(0);
|
setCurrentNoteIndex(0);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "Note saved",
|
title: "Note saved",
|
||||||
description: "Your note has been saved successfully.",
|
description: "Your note has been saved successfully.",
|
||||||
@@ -536,24 +535,28 @@ 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 = () => {
|
||||||
const trimmedContent = currentNote.trim();
|
return new Promise<void>((resolve) => {
|
||||||
|
const trimmedContent = currentNote.trim();
|
||||||
// Clear any pending save timeout
|
|
||||||
if (saveTimeoutRef.current) {
|
|
||||||
clearTimeout(saveTimeoutRef.current);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only save if there's content and it's different from last saved
|
// Clear any pending save timeout
|
||||||
if (trimmedContent && trimmedContent !== lastSavedContentRef.current) {
|
if (saveTimeoutRef.current) {
|
||||||
|
clearTimeout(saveTimeoutRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only save if there's content and it's different from last saved
|
||||||
|
if (trimmedContent && trimmedContent !== lastSavedContentRef.current) {
|
||||||
// Set a timeout to prevent multiple saves in quick succession
|
// Set a timeout to prevent multiple saves in quick succession
|
||||||
saveTimeoutRef.current = setTimeout(async () => {
|
saveTimeoutRef.current = setTimeout(async () => {
|
||||||
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,37 +628,48 @@ 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);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
searchInputRef.current?.focus();
|
searchInputRef.current?.focus();
|
||||||
}, 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()) {
|
||||||
// Save previous note if it has been modified
|
await handleSaveCurrentNote();
|
||||||
if (previousNote && isPreviousNoteModified) {
|
}
|
||||||
handlePreviousNoteBlur();
|
// Save previous note if it has been modified
|
||||||
}
|
if (previousNote && isPreviousNoteModified) {
|
||||||
// Save scratch pad if it has content
|
await handlePreviousNoteBlur();
|
||||||
if (scratchPad.trim()) {
|
}
|
||||||
saveScratch(scratchPad);
|
// Save scratch pad if it has content
|
||||||
}
|
if (scratchPad.trim()) {
|
||||||
// Quit the application
|
await saveScratch(scratchPad);
|
||||||
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keydown', handleKeyDown);
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
// Clear any pending save timeout on cleanup
|
// Clear any pending save timeout on cleanup
|
||||||
if (saveTimeoutRef.current) {
|
if (saveTimeoutRef.current) {
|
||||||
clearTimeout(saveTimeoutRef.current);
|
clearTimeout(saveTimeoutRef.current);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [currentNote, previousNote, scratchPad, isPreviousNoteModified]);
|
}, [currentNote, previousNote, scratchPad, isPreviousNoteModified]);
|
||||||
|
|
||||||
@@ -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')}`}
|
||||||
@@ -1133,7 +1146,7 @@ const Index = () => {
|
|||||||
<div className={`${getTextClass('xl')} text-slate-400 mb-2`}>
|
<div className={`${getTextClass('xl')} text-slate-400 mb-2`}>
|
||||||
{formatDate(note.epochTime)}
|
{formatDate(note.epochTime)}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`${getTextClass('2xl')} text-slate-200 whitespace-pre-wrap`}
|
className={`${getTextClass('2xl')} text-slate-200 whitespace-pre-wrap`}
|
||||||
dangerouslySetInnerHTML={{ __html: note.snippet || note.content }}
|
dangerouslySetInnerHTML={{ __html: note.snippet || note.content }}
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user