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>
  )
}
相关推荐
Jmyd01236 小时前
Web端3D营销展厅技术实现路径:从素材上云到线索回流的数据链路
前端·3d·性能优化·三维数字化
砚凝霜6 小时前
【软考信息安全】第二十二章 Web服务器安全分析与增强——Apache与IIS
服务器·前端·安全
u0111026758 小时前
JPG、PNG、WebP 怎么选?按透明度、体积和使用场景做判断
前端·javascript·vue.js·图像处理·ai作画
jerrywus8 小时前
让 AI 写完代码后交一份报告:我改造了 answer-me-with-html
前端·claude·cursor
派小心.9 小时前
小程序分享链路中来源参数的传递校验
大数据·前端·数据库·人工智能·小程序·数据分析
hhb_6189 小时前
一键生成数据看板,ECharts实战演示
前端·javascript·echarts
Java后端的Ai之路9 小时前
08_React组件API
前端·react.js·前端框架
小马不起床9 小时前
零基础玩转 FastAPI_09:前端基础工程构建
前端·状态模式·fastapi
风骏时光牛马11 小时前
用户管理模块接口开发
前端
彭亚川Allen11 小时前
从零手搓 RAG 之检索全流程,给大模型接上自己的知识库
前端·后端·ai编程