node.js - Electron 或 Node.js 应用程序是否有访问系统级图标的标准方法?

标签 node.js electron

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

我查看了 Electron 文档,我看到的最接近的是 represented files 的条目在 macOS 中,但我还没有看到任何有关通过 Electron API 公开系统级图标的信息。

如果有一个标准的跨平台 Electron 或 Node.js API 用于加载特定应用程序和文件的系统级图标资源,我很想知道。如果做不到这一点,我欢迎使用其他 Electron 或 Node.js API 读取图标资源的建议。

编辑:这是一个潜在相关(尽管特定于平台)的问题:Display .icns file in electron renderer process

最佳答案

最明显的 Electron API 函数是 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

Fetches a path's associated icon.

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.

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

参见:app.getFileIcon() does not return the expected file icon

关于node.js - Electron 或 Node.js 应用程序是否有访问系统级图标的标准方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55579879/

相关文章:

javascript - 我正在尝试在 ejs 文件中加载 bundle.js 脚本?

javascript - Electron 自动更新

Javascript createObjectURL.URL 对 MediaStream 失败

node.js - 无法使用 Electron 构建器构建应用程序。错误: gyp failed with exit code: 1

node.js - NodeRedis client.multi() hgetall 性能

javascript - Node.js Web 抓取表,值略有不同

node.js - 需要一些帮助来理解 Node.js 的行为。为什么 koa 服务器会同步响应来自同一浏览器的两个同时请求?

node.js - docker swarm 中容器之间的通信

javascript - 无法阻止 Electron 窗口关闭

javascript - 在 Node.js 中 require 的正确方法是什么?