首頁 >web前端 >js教程 >Tauri(部分 - 首先正確設定視窗配置

Tauri(部分 - 首先正確設定視窗配置

Susan Sarandon
Susan Sarandon原創
2025-01-01 02:39:10283瀏覽

Tauri (Part - Get the window configuration right first

前言

在開發桌面應用程式時,理解並正確配置視窗參數至關重要。它有助於簡化功能並優化用戶體驗。

以下內容基於Tauri 2官方文檔,提供了WindowConfig配置參數的詳細說明,包括其功能、預設值和適用性。

基本視窗行為

參數 類型 描述 預設值
接受FirstMouse 布林值 視窗是否接受第一個滑鼠事件(僅限 macOS)。
永遠在底部 布林值 視窗是否始終放置在其他視窗的下方。
永遠在最上面 布林值 視窗是否始終放置在其他視窗之上。
背景顏色 字串 視窗的背景顏色(十六進位格式)。 無預設值
中心 布林值 視窗是否位於螢幕中央。
可關閉 布林值 是否可以關閉視窗。 真實
內容受保護 布林值 保護視窗內容不被擷取或記錄(部分支援)。
裝飾品 布林值 是否顯示視窗裝飾(如標題列和邊框)。 真實
dragDropEnabled 布林值 是否啟用拖放功能。 真實
焦點 布林值 視窗啟動時是否獲得焦點。 真實
全螢幕 布林值 視窗是否以全螢幕模式啟動。
隱藏標題 布林值 隱藏標題列(僅限 macOS)。
隱身 布林值 啟用隱身模式以防止資料追蹤。
標籤 字串 視窗的唯一識別碼(必需)。 無預設值
最大化 布林值 視窗是否可以最大化。 真實
最大化 布林值 視窗是否開始最大化。
可最小化 布林值 視窗是否可以最小化。 真實
可調整大小 布林值 是否可以調整視窗大小 真實
跳過工作列 布林值 隱藏工作列上的視窗(取決於平台)。
tabbingIdentifier 字串 用於分組視窗的識別碼(僅限 macOS)。 無預設值
主題 “亮”或“暗” 視窗預設主題,部分支援。 系統預設
標題 字串 視窗標題。 「Tauri 應用程式」
titleBarStyle 字串 標題列的樣式(取決於平台,例如 macOS)。 預設樣式
透明 布林值 啟用視窗透明度(部分支援)。
用戶代理 字串 視窗的自訂用戶代理程式。 無預設值
可見 布林值 視窗是否可見。 真實
所有工作空間可見 布林值 使視窗在所有工作區上可見(僅限 macOS)。
視窗類別名稱 字串 自訂視窗類別名稱(僅限 Windows)。 無預設值
縮放熱鍵已啟用 布林值 啟用視窗縮放熱鍵。 真實

尺寸和定位

Parameter Type Description Default Value
width number Initial width of the window (in pixels). 800
height number Initial height of the window (in pixels). 600
minWidth number Minimum width of the window (in pixels). No default value
minHeight number Minimum height of the window (in pixels). No default value
maxWidth number Maximum width of the window (in pixels). No default value
maxHeight number Maximum height of the window (in pixels). No default value
x number Initial X-axis position of the window (from screen top-left). Centered
y number Initial Y-axis position of the window (from screen top-left). Centered
參數 型別 描述 預設值 標題> 寬度 數字 視窗的初始寬度(以像素為單位)。 800 身高 數字 視窗的初始高度(以像素為單位)。 600 最小寬度 數字 視窗的最小寬度(以像素為單位)。 無預設值 最小高度 數字 視窗的最小高度(以像素為單位)。 無預設值 最大寬度 數字 視窗的最大寬度(以像素為單位)。 無預設值 最高高度 數字 視窗的最大高度(以像素為單位)。 無預設值 x 數字 視窗的初始 X 軸位置(從螢幕左上角開始)。 居中 y 數字 視窗的初始 Y 軸位置(從螢幕左上角開始)。 居中

瀏覽器功能

Parameter Type Description Default Value
additionalBrowserArgs string Additional command-line arguments for the browser. No default value
browserExtensionsEnabled boolean Enables support for browser extensions. false
proxyUrl string Custom proxy URL. No default value
useHttpsScheme boolean Forces the use of HTTPS. false

視窗效果

Parameter Type Description Default Value
shadow boolean Whether the window shows a shadow (platform-dependent). true
windowEffects string Custom window effects (e.g., blur, transparency). No default value

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,它是開源。請考慮給它一個星星? .

這是我的第一個 Tauri 項目,我正在邊做邊學。希望能與志同道合的人一起探索、一起成長。

參考

https://v2.tauri.app/reference/config/#windowconfig

以上是Tauri(部分 - 首先正確設定視窗配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn