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>
  )
}
相关推荐
Web极客码21 小时前
WordPress 6.8有哪些新特性
前端·javascript·html
UXbot1 天前
UI设计工具推荐合集
前端·人工智能·ui
敲敲了个代码1 天前
如何优化批量图片上传?队列机制+分片处理+断点续传三连击!(附源码)
前端·javascript·学习·职场和发展·node.js
@AfeiyuO1 天前
Vue 引入全局样式scss
前端·vue·scss
光影少年1 天前
flex布局和grid布局区别,实现两边固定布局中间自适应
前端·css3·web·ai编程
全栈测试笔记1 天前
异步函数与异步生成器
linux·服务器·前端·数据库·python
EndingCoder1 天前
配置 tsconfig.json:高级选项
linux·前端·ubuntu·typescript·json
木风小助理1 天前
JavaStreamAPI的性能审视,优雅语法背后的隐形成本与优化实践
java·前端·数据库
white-persist1 天前
轻松抓包微信小程序:Proxifier+Burp Suite教程
前端·网络·安全·网络安全·微信小程序·小程序·notepad++
敲敲了个代码1 天前
多标签页强提醒不重复打扰:从“弹框轰炸”到“共享待处理队列”的实战
java·前端·javascript·面试·架构