toast stuff?
This commit is contained in:
parent
0e886d2239
commit
3bd65da75a
4 changed files with 44 additions and 6 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
|
@ -25,6 +25,7 @@
|
||||||
"@tauri-apps/plugin-upload": "~2",
|
"@tauri-apps/plugin-upload": "~2",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
|
"sonner": "^2.0.7",
|
||||||
"tailwindcss": "^4.0.2",
|
"tailwindcss": "^4.0.2",
|
||||||
"tauri-plugin-macos-permissions-api": "^2.0.4",
|
"tauri-plugin-macos-permissions-api": "^2.0.4",
|
||||||
"zod": "^3.24.4"
|
"zod": "^3.24.4"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import Footer from "./components/footer";
|
||||||
import HandyTextLogo from "./components/icons/HandyTextLogo";
|
import HandyTextLogo from "./components/icons/HandyTextLogo";
|
||||||
import Onboarding from "./components/onboarding";
|
import Onboarding from "./components/onboarding";
|
||||||
import { Settings } from "./components/settings/Settings";
|
import { Settings } from "./components/settings/Settings";
|
||||||
|
import { Toaster } from "sonner";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [showOnboarding, setShowOnboarding] = useState<boolean | null>(null);
|
const [showOnboarding, setShowOnboarding] = useState<boolean | null>(null);
|
||||||
|
|
@ -43,6 +44,7 @@ function App() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex flex-col w-full">
|
<div className="min-h-screen flex flex-col w-full">
|
||||||
|
<Toaster />
|
||||||
<div className="flex flex-col items-center pt-6 gap-8 px-4 flex-1">
|
<div className="flex flex-col items-center pt-6 gap-8 px-4 flex-1">
|
||||||
<HandyTextLogo width={240} />
|
<HandyTextLogo width={240} />
|
||||||
<AccessibilityPermissions />
|
<AccessibilityPermissions />
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import ResetIcon from "../icons/ResetIcon";
|
||||||
import { SettingContainer } from "../ui/SettingContainer";
|
import { SettingContainer } from "../ui/SettingContainer";
|
||||||
import { useSettings } from "../../hooks/useSettings";
|
import { useSettings } from "../../hooks/useSettings";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
interface HandyShortcutProps {
|
interface HandyShortcutProps {
|
||||||
descriptionMode?: "inline" | "tooltip";
|
descriptionMode?: "inline" | "tooltip";
|
||||||
|
|
@ -38,7 +39,7 @@ export const HandyShortcut: React.FC<HandyShortcutProps> = ({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const detectOsType = async () => {
|
const detectOsType = async () => {
|
||||||
try {
|
try {
|
||||||
const detectedType = await type();
|
const detectedType = type();
|
||||||
let normalizedType: OSType;
|
let normalizedType: OSType;
|
||||||
|
|
||||||
switch (detectedType) {
|
switch (detectedType) {
|
||||||
|
|
@ -75,8 +76,18 @@ export const HandyShortcut: React.FC<HandyShortcutProps> = ({
|
||||||
const handleKeyDown = async (e: KeyboardEvent) => {
|
const handleKeyDown = async (e: KeyboardEvent) => {
|
||||||
if (e.repeat) return; // ignore auto-repeat
|
if (e.repeat) return; // ignore auto-repeat
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
// Cancel recording
|
// Cancel recording and restore original binding
|
||||||
if (editingShortcutId) {
|
if (editingShortcutId && originalBinding) {
|
||||||
|
try {
|
||||||
|
await updateBinding(editingShortcutId, originalBinding);
|
||||||
|
await invoke("resume_binding", { id: editingShortcutId }).catch(
|
||||||
|
console.error,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to restore original binding:", error);
|
||||||
|
toast.error("Failed to restore original shortcut");
|
||||||
|
}
|
||||||
|
} else if (editingShortcutId) {
|
||||||
await invoke("resume_binding", { id: editingShortcutId }).catch(
|
await invoke("resume_binding", { id: editingShortcutId }).catch(
|
||||||
console.error,
|
console.error,
|
||||||
);
|
);
|
||||||
|
|
@ -129,6 +140,20 @@ export const HandyShortcut: React.FC<HandyShortcutProps> = ({
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to change binding:", error);
|
console.error("Failed to change binding:", error);
|
||||||
|
toast.error(`Failed to set shortcut: ${error}`);
|
||||||
|
|
||||||
|
// Reset to original binding on error
|
||||||
|
if (originalBinding) {
|
||||||
|
try {
|
||||||
|
await updateBinding(editingShortcutId, originalBinding);
|
||||||
|
await invoke("resume_binding", { id: editingShortcutId }).catch(
|
||||||
|
console.error,
|
||||||
|
);
|
||||||
|
} catch (resetError) {
|
||||||
|
console.error("Failed to reset binding:", resetError);
|
||||||
|
toast.error("Failed to reset shortcut to original value");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit editing mode and reset states
|
// Exit editing mode and reset states
|
||||||
|
|
@ -141,11 +166,21 @@ export const HandyShortcut: React.FC<HandyShortcutProps> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add click outside handler
|
// Add click outside handler
|
||||||
const handleClickOutside = (e: MouseEvent) => {
|
const handleClickOutside = async (e: MouseEvent) => {
|
||||||
const activeElement = shortcutRefs.current.get(editingShortcutId);
|
const activeElement = shortcutRefs.current.get(editingShortcutId);
|
||||||
if (activeElement && !activeElement.contains(e.target as Node)) {
|
if (activeElement && !activeElement.contains(e.target as Node)) {
|
||||||
// Cancel shortcut recording - the hook will handle rollback
|
// Cancel shortcut recording and restore original binding
|
||||||
if (editingShortcutId) {
|
if (editingShortcutId && originalBinding) {
|
||||||
|
try {
|
||||||
|
await updateBinding(editingShortcutId, originalBinding);
|
||||||
|
await invoke("resume_binding", { id: editingShortcutId }).catch(
|
||||||
|
console.error,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to restore original binding:", error);
|
||||||
|
toast.error("Failed to restore original shortcut");
|
||||||
|
}
|
||||||
|
} else if (editingShortcutId) {
|
||||||
invoke("resume_binding", { id: editingShortcutId }).catch(
|
invoke("resume_binding", { id: editingShortcutId }).catch(
|
||||||
console.error,
|
console.error,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue