Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: copy app & system info #101

Merged
merged 1 commit into from
Mar 26, 2023
Merged

feat: copy app & system info #101

merged 1 commit into from
Mar 26, 2023

Conversation

orangelckc
Copy link
Member

No description provided.

VITE_CONFIG_PATH=com.ChatGPT-Desktop No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码看起来非常简短,只做了一项微小的更改。在这个 patch 中,删除了 VITE_APP_NAME 变量的定义,但保留了 VITE_CONFIG_PATH 变量的定义。

从这个 patch 看来,没有明显的错误或风险。如果您想要进一步改进代码,请考虑添加注释或者对提交信息进行描述,以提高代码可读性。

<script type="module" src="/src/main.ts"></script>
</body>

</html> No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码看起来没什么问题,主要是对 HTML 页面进行了一些修改:

  • 将页面标题从 "ChatGPT" 改为了 "ChatGPT-Desktop"。
  • 在文档末尾添加了一个换行符,以避免一些 Git 工具出现错误提示。

如果需要改进的话,可以考虑:

  • 为 HTML 标签添加 lang 属性,以便屏幕阅读器等工具能够更好地理解页面内容。
  • 添加必要的 Meta 信息,如描述标签和关键字标签,以提高搜索引擎优化(SEO)效果。

@@ -7,7 +7,7 @@
"withGlobalTauri": false
},
"package": {
"productName": "ChatGPT",
"productName": "ChatGPT-Desktop",
"version": "../package.json"
},
"tauri": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码的变化看起来很小,只是将产品名称从 "ChatGPT" 改为 "ChatGPT-Desktop"。这个更改似乎没有引入任何风险或错误。

关于改进建议,可能需要更多的上下文信息。如果这是一个完整的文件,并且没有其他更改,那么这个文件看起来很短,因此我们无法对其进行更多的改进建议。

@ayangweb ayangweb merged commit 000994a into master Mar 26, 2023
<a class="cursor-pointer">复制电脑信息</a>
<span>{{ appInfo.appName }}</span>
<span>v{{ appInfo.appVersion }}</span>
<a class="cursor-pointer" @click="copyInfo">复制电脑信息</a>
<a href="https://github.com/ChatGPT-Desktop/ChatGPT-Desktop/issues/new">
BUG 反馈
</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码使用了@tauri-apps/api库中的一些函数,用于获取应用程序的相关信息和操作剪贴板。在onMounted生命周期钩子函数中,通过调用相应的API函数来获取应用程序名称、版本号、Tauri版本号、平台、操作系统以及处理器架构等信息,并将其存储到响应式变量appInfo中。同时,还通过异步请求获取Contributors列表。页面中显示了应用程序名称、版本号和一个“复制电脑信息”的链接,当用户点击该链接时,会触发copyInfo函数,将当前获取到的应用程序信息和用户代理信息生成JSON字符串并复制到剪贴板中。

建议改进:

  1. 建议给appInfo添加注释,说明每个属性的用途。
  2. 在copyInfo函数中,建议对错误进行捕获和处理,例如使用try-catch语句捕获可能出现的异常,并在失败时弹出提示框告知用户。
  3. 为了提高应用程序的安全性,建议对从剪贴板获取的数据进行验证或过滤,以防止不必要的攻击或意外情况。

// 下载图片到 download 文件夹
await writeBinaryFile(
{
path: `ChatGPT-Desktop-${Date.now()}.png`,
path: `${appName}-${Date.now()}.png`,
contents: uint8Array
},
{ dir: BaseDirectory.Download }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码的意思是:

在导入了 @tauri-apps/api/app 和其他一些依赖之后,定义了一个名为 saveImage 的异步函数。该函数接收一个字符串类型的 nodeId 参数。

在函数内部,首先使用 html2canvas 库生成一个 canvas 对象,并将其转换成 PNG 格式的数据 URL。然后使用 fetch 函数将数据 URL 转换成二进制格式的数组缓冲区,并将其存储在 uint8Array 变量中。

接下来,使用 getName 函数获取当前应用程序的名称,并将其存储在 appName 变量中。

最后,调用 writeBinaryFile 函数将 uint8Array 中的数据写入到下载文件夹中,文件名为 ${appName}-${Date.now()}.png

从安全性角度来看,这段代码没有明显的问题。但有一个可以改进的地方是,在编写保存文件的路径时建议使用 path.join() 方法,以确保路径分隔符正确匹配目标平台。

@orangelckc orangelckc deleted the dev/KC branch March 27, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants