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

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

Jan 01, 2025 am 02:39 AM

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

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1664
14
CakePHP 教程
1423
52
Laravel 教程
1317
25
PHP教程
1268
29
C# 教程
1246
24
JavaScript的演變:當前的趨勢和未來前景 JavaScript的演變:當前的趨勢和未來前景 Apr 10, 2025 am 09:33 AM

JavaScript的最新趨勢包括TypeScript的崛起、現代框架和庫的流行以及WebAssembly的應用。未來前景涵蓋更強大的類型系統、服務器端JavaScript的發展、人工智能和機器學習的擴展以及物聯網和邊緣計算的潛力。

JavaScript引擎:比較實施 JavaScript引擎:比較實施 Apr 13, 2025 am 12:05 AM

不同JavaScript引擎在解析和執行JavaScript代碼時,效果會有所不同,因為每個引擎的實現原理和優化策略各有差異。 1.詞法分析:將源碼轉換為詞法單元。 2.語法分析:生成抽象語法樹。 3.優化和編譯:通過JIT編譯器生成機器碼。 4.執行:運行機器碼。 V8引擎通過即時編譯和隱藏類優化,SpiderMonkey使用類型推斷系統,導致在相同代碼上的性能表現不同。

Python vs. JavaScript:學習曲線和易用性 Python vs. JavaScript:學習曲線和易用性 Apr 16, 2025 am 12:12 AM

Python更適合初學者,學習曲線平緩,語法簡潔;JavaScript適合前端開發,學習曲線較陡,語法靈活。 1.Python語法直觀,適用於數據科學和後端開發。 2.JavaScript靈活,廣泛用於前端和服務器端編程。

JavaScript:探索網絡語言的多功能性 JavaScript:探索網絡語言的多功能性 Apr 11, 2025 am 12:01 AM

JavaScript是現代Web開發的核心語言,因其多樣性和靈活性而廣泛應用。 1)前端開發:通過DOM操作和現代框架(如React、Vue.js、Angular)構建動態網頁和單頁面應用。 2)服務器端開發:Node.js利用非阻塞I/O模型處理高並發和實時應用。 3)移動和桌面應用開發:通過ReactNative和Electron實現跨平台開發,提高開發效率。

如何使用Next.js(前端集成)構建多租戶SaaS應用程序 如何使用Next.js(前端集成)構建多租戶SaaS應用程序 Apr 11, 2025 am 08:22 AM

本文展示了與許可證確保的後端的前端集成,並使用Next.js構建功能性Edtech SaaS應用程序。 前端獲取用戶權限以控制UI的可見性並確保API要求遵守角色庫

使用Next.js(後端集成)構建多租戶SaaS應用程序 使用Next.js(後端集成)構建多租戶SaaS應用程序 Apr 11, 2025 am 08:23 AM

我使用您的日常技術工具構建了功能性的多租戶SaaS應用程序(一個Edtech應用程序),您可以做同樣的事情。 首先,什麼是多租戶SaaS應用程序? 多租戶SaaS應用程序可讓您從唱歌中為多個客戶提供服務

從C/C到JavaScript:所有工作方式 從C/C到JavaScript:所有工作方式 Apr 14, 2025 am 12:05 AM

從C/C 轉向JavaScript需要適應動態類型、垃圾回收和異步編程等特點。 1)C/C 是靜態類型語言,需手動管理內存,而JavaScript是動態類型,垃圾回收自動處理。 2)C/C 需編譯成機器碼,JavaScript則為解釋型語言。 3)JavaScript引入閉包、原型鍊和Promise等概念,增強了靈活性和異步編程能力。

JavaScript和Web:核心功能和用例 JavaScript和Web:核心功能和用例 Apr 18, 2025 am 12:19 AM

JavaScript在Web開發中的主要用途包括客戶端交互、表單驗證和異步通信。 1)通過DOM操作實現動態內容更新和用戶交互;2)在用戶提交數據前進行客戶端驗證,提高用戶體驗;3)通過AJAX技術實現與服務器的無刷新通信。

See all articles