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>
  )
}
相关推荐
拿破轮19 小时前
使用通义灵码解决复杂正则表达式替换字符串的问题.
java·服务器·前端
whltaoin19 小时前
【 Web认证 】Cookie、Session 与 JWT Token:Web 认证机制的原理、实现与对比
前端·web·jwt·cookie·session·认证机制
Aerelin20 小时前
爬虫playwright入门讲解
前端·javascript·html·playwright
5***o50020 小时前
前端在移动端中的NativeBase
前端
灵魂学者20 小时前
Vue3.x —— 父子通信
前端·javascript·vue.js·github
1***Q78420 小时前
前端跨域解决方案
前端
小雨青年21 小时前
MateChat 进阶实战:打造零后端、隐私安全的“端侧记忆”智能体
前端·华为·ai·华为云·状态模式
勇气要爆发21 小时前
问:ES5和ES6的区别
前端·ecmascript·es6
永不停歇的蜗牛21 小时前
Maven的POM文件相关标签作用
服务器·前端·maven
芳草萋萋鹦鹉洲哦1 天前
【vue/js】文字超长悬停显示的几种方式
前端·javascript·vue.js