是否有Electron或Node.js应用程序访问系统级图标的标准方法? [英] Is there a standard way for an Electron or Node.js app to access system-level icons?

查看:45
本文介绍了是否有Electron或Node.js应用程序访问系统级图标的标准方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在基于电子的实用程序(例如启动器和文件检查器)中显示系统级应用程序和文件图标.电子或Node.js应用程序是否有访问系统级图标的标准方法?

I would like to be able to display system-level application and file icons in Electron-based utilities such as launchers and file-inspectors. Is there a standard way for an Electron or Node.js app to access system-level icons?

我查看了Electron文档,发现最接近的东西是代表文件的条目在macOS中,但是我还没有看到有关通过Electron API公开的系统级图标的任何信息.

I have looked in the Electron docs and the closest thing I saw was the entry for represented files in macOS, but I have not yet seen anything about system-level icons being exposed via the Electron APIs.

如果有一个标准的跨平台Electron或Node.js API可以为特定的应用程序和文件加载系统级图标资源,我想了解一下.失败的话,我欢迎您建议使用其他Electron或Node.js API读取图标资源.

If there is a standard cross-platform Electron or Node.js API for loading system-level icon resources for specific applications and files I would love to know about it. Failing that, I welcome suggestions for reading icon resources with other Electron or Node.js APIs.

这是一个潜在的相关问题(尽管特定于平台):在电子渲染器过程中显示.icns文件

Here is a potentially relevant (although platform-specific) question: Display .icns file in electron renderer process

推荐答案

最明显的Electron API函数是 app.getFileIcon ,但似乎只能为应用程序和文档提供通用图标,这可能对您的应用程序来说足够好了……

The most obvious Electron API function is app.getFileIcon but it seems it can only provide generic icons for apps and documents, which may be good enough for your app, or not...

app.getFileIcon(路径[,选项],回调)

app.getFileIcon(path[, options], callback)

path String

options Object (optional)

    size String
        small - 16x16
        normal - 32x32
        large - 48x48 on Linux, 32x32 on Windows, unsupported on macOS.

callback Function
    error Error
    icon NativeImage

获取路径的相关图标.

在Windows上,有2种图标:

On Windows, there a 2 kinds of icons:

Icons associated with certain file extensions, like .mp3, .png, etc.
Icons inside the file itself, like .exe, .dll, .ico.

在Linux和macOS上,图标取决于与文件mime类型.

On Linux and macOS, icons depend on the application associated with file mime type.

请参阅: app.getFileIcon()不返回预期的文件图标

这篇关于是否有Electron或Node.js应用程序访问系统级图标的标准方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆