import { type } from "@tauri-apps/plugin-os"; import { useFonts } from "@yaakapp-internal/fonts"; import { useLicense } from "@yaakapp-internal/license"; import type { EditorKeymap, Settings } from "@yaakapp-internal/models"; import { patchModel, settingsAtom } from "@yaakapp-internal/models"; import { useAtomValue } from "jotai"; import { useState } from "react"; import { activeWorkspaceAtom } from "../../hooks/useActiveWorkspace"; import { clamp } from "../../lib/clamp"; import { showConfirm } from "../../lib/confirm"; import { invokeCmd } from "../../lib/tauri"; import { CargoFeature } from "../CargoFeature"; import { Button } from "../core/Button"; import { Checkbox } from "../core/Checkbox"; import { Heading } from "../core/Heading"; import { Icon } from "../core/Icon"; import { Link } from "../core/Link"; import { Select } from "../core/Select"; import { HStack, VStack } from "../core/Stacks"; const NULL_FONT_VALUE = "__NULL_FONT__"; const fontSizeOptions = [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, ].map((n) => ({ label: `${n}`, value: `${n}` })); const keymaps: { value: EditorKeymap; label: string }[] = [ { value: "default", label: "Default" }, { value: "vim", label: "Vim" }, { value: "vscode", label: "VSCode" }, { value: "emacs", label: "Emacs" }, ]; export function SettingsInterface() { const workspace = useAtomValue(activeWorkspaceAtom); const settings = useAtomValue(settingsAtom); const fonts = useFonts(); if (settings == null || workspace == null) { return null; } return (
Interface

Tweak settings related to the user interface.

({ label: f, value: f, })) ?? []), // Some people like monospace fonts for the UI ...(fonts.data.editorFonts.map((f) => ({ label: f, value: f, })) ?? []), ]} onChange={async (v) => { const interfaceFont = v === NULL_FONT_VALUE ? null : v; await patchModel(settings, { interfaceFont }); }} /> )} ({ label: f, value: f, })) ?? []), ]} onChange={async (v) => { const editorFont = v === NULL_FONT_VALUE ? null : v; await patchModel(settings, { editorFont }); }} /> )} } size="sm" name="editorKeymap" label="Editor keymap" value={`${settings.editorKeymap}`} options={keymaps} onChange={(v) => patchModel(settings, { editorKeymap: v })} /> patchModel(settings, { editorSoftWrap })} /> patchModel(settings, { coloredMethods })} /> {type() !== "macos" && ( patchModel(settings, { hideWindowControls })} /> )}
); } function NativeTitlebarSetting({ settings }: { settings: Settings }) { const [nativeTitlebar, setNativeTitlebar] = useState(settings.useNativeTitlebar); return (
{settings.useNativeTitlebar !== nativeTitlebar && ( )}
); } function LicenseSettings({ settings }: { settings: Settings }) { const license = useLicense(); if (license.check.data?.status !== "personal_use") { return null; } return ( { if (hideLicenseBadge) { const confirmed = await showConfirm({ id: "hide-license-badge", title: "Confirm Personal Use", confirmText: "Confirm", description: (

Hey there ๐Ÿ‘‹๐Ÿผ

Yaak is free for personal projects and learning.{" "} If youโ€™re using Yaak at work, a license is required.

Licenses help keep Yaak independent and sustainable.{" "} Purchase a License โ†’

), requireTyping: "Personal Use", color: "info", }); if (!confirmed) { return; // Cancel } } await patchModel(settings, { hideLicenseBadge }); }} /> ); }