Repository navigation
Add an API to fetch file icon - #7851
Conversation
|
Note to self: optional args handling |
|
@deepak1556 I'm having troubles trying to understand how to detect when icon is empty for implementing node-style callbacks. It seems on linux/kde5 it always returns this icon for non-existent files: |
|
Faced the problem with extraction of icons from executable files. It seems like API call only uses mime type to get the "generic" icon /cc @deepak1556 |
|
Found the problem: path should be normalized: |
|
@YurySolovyov Pass the path through |
| * `options` Object (optional) | ||
| * `size` String - Defaults to `normal`. Can be `small`, `normal`, `large` | ||
| * `callback` Function | ||
| * `Icon` [NativeImage](native-image.md) |
|
@MarshallOfSound problem with normalize is that it is in js and my code is in C++, so I have to state it in docs or expose only the binding to js and do normalization there |
8406c23 to
0ed1678
Compare
| v8::Isolate* isolate = v8::Isolate::GetCurrent(); | ||
| if (icon && !icon->IsEmpty()) { | ||
| v8::Locker locker(isolate); | ||
| v8::HandleScope handle_scope(isolate); |
There was a problem hiding this comment.
locker and scope should be moved to top level of the function.
| #include "atom/browser/api/event_emitter.h" | ||
| #include "atom/browser/atom_browser_client.h" | ||
| #include "atom/browser/browser_observer.h" | ||
| #include "atom/common/api/atom_api_native_image.h" |
|
Tests(not only the added ones) are somewhat unstable, even locally they pass and fail time-to-time |
| return dict.GetHandle(); | ||
| } | ||
| }; | ||
|
|
There was a problem hiding this comment.
Kill the random new line plz 👍
|
|
||
| * `path` String | ||
| * `options` Object (optional) | ||
| * `size` String - Defaults to `normal`. Can be `small`, `normal`, `large` |
There was a problem hiding this comment.
Can be small, normal or large
| * `videos` Directory for a user's videos. | ||
| * `pepperFlashSystemPlugin` Full path to the system version of the Pepper Flash plugin. | ||
|
|
||
| ### `app.getFileIcon(path, [options], callback)` |
There was a problem hiding this comment.
When did this move from NativeImage.from to an app API. Personally I liked it better the other way round. The app module is already polluted as it is and IMO it shouldn't just become a dumping ground for new methods 👍
There was a problem hiding this comment.
I chatted about it with @deepak1556 and he suggested doing it under app namespace
There was a problem hiding this comment.
Is that discussion on this PR somewhere or was it private?
There was a problem hiding this comment.
|
|
||
| it('fetches large icons', function (done) { | ||
| if (process.platform === 'darwin') { | ||
| return this.skip() // macOS does not support large icons |
There was a problem hiding this comment.
If this is the case it should also be in the docs
|
I kind of agree that placing this API to NativeImage is more natural, especially w.r.t. running from both renderer and main processes and I'm happy to move it, but it would be nice to hear from @zcbenz. |
kevinsawicki
left a comment
There was a problem hiding this comment.
Left a few minor comments.
Also vendor/brigthray is showing up in the diff, it doesn't need to change as part of this pull request right? Might want to revert that change if it was unintended.
| } | ||
|
|
||
| if (!args->GetNext(&callback)) { | ||
| args->ThrowError(); |
There was a problem hiding this comment.
Could a helpful message be added to this error? Maybe "Missing required callback function"?
| large: 48 | ||
| } | ||
|
|
||
| it('fetches non-empty icon', function (done) { |
There was a problem hiding this comment.
it is one icon per API call, so not sure it is plural here
There was a problem hiding this comment.
The other specs are fetches small icons and fetches normal icons though, so either this should be fetches non-empty icons or fetches a non-empty icon. Currently the grammar is a little off.
| }) | ||
|
|
||
| describe('getFileIcon() API', function () { | ||
| const iconPath = path.join(process.cwd(), 'fixtures/assets/icon.ico') |
There was a problem hiding this comment.
Probably want to use __dirname instead of process.cwd().
const iconPath = path.join(__dirname, 'fixtures', 'assets', 'icon.ico')|
|
||
| * `path` String | ||
| * `options` Object (optional) | ||
| * `size` String - Can be `small`, `normal`, `large`. Except for `large` on _macOS_ |
There was a problem hiding this comment.
Except for
largeon macOS
What do you think about:
The
largesize is not supported on macOS
There was a problem hiding this comment.
I'm fine with it.
| * `callback` Function | ||
| * `error` Error | ||
| * `icon` [NativeImage](native-image.md) | ||
|
|
There was a problem hiding this comment.
This API could use a sentence (or two) description about what it does.
There was a problem hiding this comment.
I guess I can take it from one of the c++ headers, and reword it a bit.
|
@kevinsawicki Thanks, I'll address these as I get home. Any thoughts on where this API should belong? |
I'm not 100% sure, both |
0d9c8ff to
c4f16d0
Compare
|
I would personally prefer having it under NativeImage. Are you ok with it @deepak1556 ? |
|
I am fine with it, but there are certain things you need to take care of. The |
|
|
||
| * `path` String | ||
| * `options` Object (optional) | ||
| * `size` String - Can be `small`, `normal`, `large`. The `large` size is not supported on _macOS_ |
There was a problem hiding this comment.
What happens if I call this API with size: 'large' on macOS? Is there something like a fallback to normal or what could be the best behaviour?
There was a problem hiding this comment.
I have a no idea tbh, and no Apple device to test it.
what could be the best behaviour?
I think the best would be to fetch normal one. This is what happens on windows too, where normal and large icons are equal.
I'll see what I can do to test it
There was a problem hiding this comment.
I think it should be noted in the docs that there is no difference between normal and large on Windows (and macOS).
| assert.equal(err, null) | ||
| assert.equal(size.height, sizes.normal) | ||
| assert.equal(size.width, sizes.normal) | ||
| done() |
There was a problem hiding this comment.
normal gets passed instead of large
02da0bf to
54e94bb
Compare
|
@deepak1556 any examples in existing APIs of how this IPC messaging could/should look like? |
|
@YurySolovyov none of the common apis currently are dependent on ipc for implementation. You could probably define the api in |
|
@deepak1556 maybe I can expose API as binding to App, and then call it directly or via IPC depending on the process as you suggested. |
|
How about adding it to |
|
Hey, I'm interested in this API: how can I help? What is remaining to be done? |
|
@alexstrat it is awaiting for some advice form @zcbenz to decide where this API belongs. |
|
Any updates on which API this belongs to? Looking forward to implement this on my app. |
54e94bb to
a9dae24
Compare
|
Thanks for this @YurySolovyov, @deepak1556, and @MarshallOfSound 👍 🚢 🚀 |
|
Huge thanks to @MarshallOfSound, @deepak1556 for help and @kevinsawicki for finishing this up. |





Fixes #6397
Huge thanks to @deepak1556 and @MarshallOfSound who did most of the work and helped a lot.
TODO:
normalsize by default.