Is there a standard way for an Electron or Node.js app to access system-level icons?

限于喜欢 提交于 2021-01-29 05:33:16

问题


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?

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.

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.

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


回答1:


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(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.

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



来源:https://stackoverflow.com/questions/55579879/is-there-a-standard-way-for-an-electron-or-node-js-app-to-access-system-level-ic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!