tauri api app 使用

tauri api app 使用

对应的代码仓库:github.com/leaf0412/ta...

app 函数

Tauri API中的 app 模块提供了获取应用程序元数据。主要有以下几个函数:

  • getName --> 获取应用程序名称
  • getTauriVersion --> 获取 Tauri 版本
  • getVersion --> 获取应用程序版本
  • hide --> 在 MacOS 上隐藏应用程序
  • show --> 在 MacOS 上显示应用程序

函数使用方式

注意事项

使用 app API 中的 hide 和 show 函数, 必须要将权限添加到 tauri.conf.json 中的tauri.allowlist.app

json 复制代码
{  
    "tauri": {  
        "allowlist": {  
            "app": {
              "all": true, 
              "show": true,
              "hide": true
            }
        }  
    }  
}

getName 获取应用程序名称

使用方式:创建 GetSoftwareName.jsx 文件

jsx 复制代码
import { getName } from '@tauri-apps/api/app';
import { useState } from 'react';

export default function GetSoftwareName() {
  const [AppName, setAppName] = useState('');
  const getAppName = async () => {
    const name = await getName();
    setAppName(name);
  }
  return (
    <div>
      <button onClick={getAppName}>获取软件名称</button>
      <p>软件名称:{AppName}</p>
    </div>
  )
}

getTauriVersion 获取 Tauri 版本

使用方式:创建 GetTauriVersion.jsx 文件

jsx 复制代码
import { getTauriVersion } from '@tauri-apps/api/app';
import { useState } from 'react';

export default function GetTauriVersion() {
  const [version, setVersion] = useState('');
  const getVersion = async () => {
    const version = await getTauriVersion();
    setVersion(version);
  }
  return (
    <div>
      <button onClick={getVersion}>获取 Tauri 版本</button>
      <p>Tauri 版本:{version}</p>
    </div>
  )
}

getVersion 获取应用程序版本

使用方式:创建 GetSoftwareVersion.jsx 文件

jsx 复制代码
import { getVersion } from '@tauri-apps/api/app';
import { useState } from 'react';

export default function GetSoftwareVersion() {
  const [version, setVersion] = useState('');
  const getSoftwareVersion = async () => {
    const version = await getVersion();
    setVersion(version);
  }
  return (
    <div>
      <button onClick={getSoftwareVersion}>获取软件版本</button>
      <p>软件版本:{version}</p>
    </div>
  )
}

hide 在 MacOS 上隐藏应用程序

使用方式:创建 HideSoftware.jsx 文件

jsx 复制代码
import { hide } from '@tauri-apps/api/app';

export default function HideSoftware() {
  const handleHide = async () => {
    await hide();
  }
  return (
    <div>
      <button onClick={handleHide}>隐藏软件</button>
    </div>
  )
}

show 在 MacOS 上显示应用程序

使用方式:创建 HideSoftware.jsx 文件

jsx 复制代码
import { show } from '@tauri-apps/api/app';

export default function ShowSoftware() {
  const handleShow = async () => {
    await show();
  }
  return (
    <div>
      <button onClick={handleShow}>显示软件</button>
    </div>
  )
}
相关推荐
太平洋月光39 分钟前
AI 快捷指令:Cursor Rules · Commands · Skills
前端·ai编程
默_笙42 分钟前
😁 LLM 不知道的事它不会说"不知道",而是会"编"——RAG 就是让它闭嘴先查资料
前端·javascript
stringwu44 分钟前
用 LangGraph 落地飞书 Bug 自动修复 Agent 实践
前端
Revolution6144 分钟前
变量提升到底提升了什么:为什么 var 是 undefined,let 却直接报错
前端·javascript
Revolution611 小时前
本地明明正常,为什么 CI 又挂了:一次前端构建失败的排查过程
前端·前端工程化
太平洋月光1 小时前
stagewise如何结合cursor开发
前端·ai编程
前端Hardy1 小时前
JavaScript 终于又进化了!ES2026 正式发布,这些新特性你必须知道!
前端
光影少年1 小时前
react navite 页面跳转、传参、路由监听、导航栏自定义
前端·react native·react.js
黑土豆1 小时前
CSS 新特性:Container Queries 到底能解决什么痛点?
前端·css
问商十三载1 小时前
2026法律行业AI引擎生成式优化怎么优化?三层专业加固提排名,零成本提33%引用率附适配表
java·前端·人工智能·算法