Tauri(3)- 首先正确配置窗口
前言
在开发桌面应用程序时,了解并正确配置窗口参数至关重要。它有助于简化功能并优化用户体验。
以下内容基于**Tauri 2**官方文档,对`WindowConfig`配置参数进行了详细的描述,包括其功能、默认值和适用性。
基本窗口行为
尺寸和定位
浏览器功能
窗口效果
JSON 配置示例
**src-tauri/tauri.conf.json**
{ "$schema": "https://schema.tauri.app/config/2.0.0", "productName": "Coco AI", "version": "0.1.0", "identifier": "rs.coco.app", "build": { "beforeDevCommand": "pnpm dev", "devUrl": "http://localhost:1420", "beforeBuildCommand": "pnpm build", "frontendDist": "../dist" }, "app": { "macOSPrivateApi": true, "windows": [ { "acceptFirstMouse": false, // Whether the first mouse event is accepted "additionalBrowserArgs": "", // Additional arguments passed to the browser "alwaysOnBottom": false, // Whether the window always stays at the bottom "alwaysOnTop": false, // Whether the window always stays on top "backgroundColor": "#ffffff", // Background color of the window (default is white) "browserExtensionsEnabled": false, // Whether browser extensions are enabled "center": true, // Whether the window is centered "closable": true, // Whether the window can be closed "contentProtected": false, // Whether content protection is enabled (prevents screenshots) "create": true, // Whether to display the window when created "decorations": true, // Whether to display window decorations "devtools": false, // Whether developer tools are enabled (disabled by default in production) "dragDropEnabled": true, // Whether drag-and-drop functionality is enabled "focus": true, // Whether the window is focused "fullscreen": false, // Whether the window is in fullscreen mode "height": 600, // Window height (default 600px) "hiddenTitle": false, // Whether the window title bar is hidden "incognito": false, // Whether incognito mode is enabled "label": "main", // Unique label (identifier) of the window "maxHeight": null, // Maximum height of the window (default is unlimited) "maximizable": true, // Whether the window can be maximized "maximized": false, // Whether the window is maximized by default "maxWidth": null, // Maximum width of the window (default is unlimited) "minHeight": 300, // Minimum height of the window (default 300px) "minimizable": true, // Whether the window can be minimized "minWidth": 300, // Minimum width of the window (default 300px) "parent": null, // Parent window (default is none) "proxyUrl": "", // Proxy URL "resizable": true, // Whether the window is resizable "shadow": true, // Whether the window shadow is displayed "skipTaskbar": false, // Whether to skip showing the window in the taskbar "tabbingIdentifier": null, // Identifier for grouping windows "theme": "light", // Window theme (default is light) "title": "Tauri App", // Window title "titleBarStyle": "default", // Title bar style "transparent": false, // Whether the window is transparent "url": "/", // Default URL of the window "useHttpsScheme": false, // Whether to enforce HTTPS "userAgent": null, // Custom user agent (default is null) "visible": true, // Whether the window is visible "visibleOnAllWorkspaces": false, // Whether the window is visible on all workspaces "width": 800, // Window width (default 800px) "windowClassname": "", // Window class name (customizable) "windowEffects": null, // Window effects (default is none) "x": null, // Initial X-coordinate of the window position "y": null, // Initial Y-coordinate of the window position "zoomHotkeysEnabled": true // Whether zoom hotkeys are enabled } ], "security": { "csp": null } } }
结论
配置窗口参数是 Tauri 开发中至关重要的一步。
了解每个参数的用途和默认值不仅有助于有效实施,而且还可以避免潜在的跨平台兼容性问题。
有关准确的配置和更多详细信息,请参阅 Tauri 官方文档。
欢迎探索我最近的 Tauri 项目 github.com/infinilabs/coco-app,它是 **开源**。请考虑给它一个 **star** 🌟。
这是我的第一个 Tauri 项目,我边做边学,希望能结识到志同道合的人,一起探索、一起成长。
参考
https://v2.tauri.app/reference/config/#windowconfig