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

Add option to use native emoji #731

Merged
merged 30 commits into from
Feb 20, 2019

Conversation

felixfbecker
Copy link
Contributor

@felixfbecker felixfbecker commented Jan 18, 2019

Closes #672

image

image

Adds a new option "native" to the emoji menu.

Uses a MutationObserver to swap emoji img elements with the actual emoji text, and injects CSS to show the native emoji in the editor.

Also added a bunch more docblocks with type info.

I did not enable it by default because unfortunately some emoji are rendered as multiple characters, which is an Electron bug I wasn't able to work around: electron/electron#11874

Despite this flaw (which I hope will be fixed in the future) I would still use this option and think it is good to have.

Copy link
Collaborator

@CvX CvX left a comment

Choose a reason for hiding this comment

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

Hey, thank you for this PR! 🙂 I like the idea of using native (or specifically, Apple's) emoji.

There are some things that need to be fixed first, though. Other than these, I'll also look into electron/electron#11874 issue.

@felixfbecker
Copy link
Contributor Author

felixfbecker commented Jan 20, 2019

@CvX resolved all outstanding issues

@felixfbecker
Copy link
Contributor Author

Build for testing: https://we.tl/t-9V4ZMO0boX

@CvX
Copy link
Collaborator

CvX commented Jan 20, 2019

Some things are still broken:

  • Native emoji is displayed with various alpha color values (0.7 in the sidebar, 0.9 in the conversation when using the dark mode, etc.). .native-emoji should have its color set to something like rgba(0, 0, 0, 255).
  • Emojis in the reaction popover are misaligned:
    screen shot 2019-01-20 at 15 13 31
  • Emojis in the "insert emoji" popover are misaligned too:
    screen shot 2019-01-20 at 15 13 44
  • Emoticons (e.g. ":)") in the message composer are no longer being replaced with emoji while typing the message

@felixfbecker
Copy link
Contributor Author

Native emoji is displayed with various alpha color values (0.7 in the sidebar, 0.9 in the conversation when using the dark mode, etc.). .native-emoji should have its color set to something like rgba(0, 0, 0, 255).

Could you elaborate on this? Shouldn't the emoji be displayed like the surrounding text?

@CvX
Copy link
Collaborator

CvX commented Jan 20, 2019

I think emoji should always be displayed as they are – full opacity, no tinting. That's how they are displayed with other emoji sets anyway.

@CvX
Copy link
Collaborator

CvX commented Jan 20, 2019

Ouch, here's a biggie:

  • Send ":)", restart Caprine, send another ":P". The last message in the conversation list doesn't update. Try sending "test", you end up with this:

screen shot 2019-01-20 at 15 26 15

@felixfbecker
Copy link
Contributor Author

The error that causes the "Could not display composer" is

DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
    at Xg (https://static.xx.fbcdn.net/rsrc.php/v3iLl54/yp/l/en_US/EYCXyA9EU03.js:47:81303)
    at fi (https://static.xx.fbcdn.net/rsrc.php/v3iLl54/yp/l/en_US/EYCXyA9EU03.js:47:101019)
    at ei (https://static.xx.fbcdn.net/rsrc.php/v3iLl54/yp/l/en_US/EYCXyA9EU03.js:47:98043)
    at ci (https://static.xx.fbcdn.net/rsrc.php/v3iLl54/yp/l/en_US/EYCXyA9EU03.js:47:97387)
    at ji (https://static.xx.fbcdn.net/rsrc.php/v3iLl54/yp/l/en_US/EYCXyA9EU03.js:47:104465)
    at hd (https://static.xx.fbcdn.net/rsrc.php/v3iLl54/yp/l/en_US/EYCXyA9EU03.js:47:32140)
    at HTMLDocument.n (https://static.xx.fbcdn.net/rsrc.php/v3/yF/r/KAUB_fijJwW.js:103:2698)
    at Object.applyWithGuard (https://static.xx.fbcdn.net/rsrc.php/v3/yF/r/KAUB_fijJwW.js:55:2237)
    at t.fire (https://static.xx.fbcdn.net/rsrc.php/v3/yF/r/KAUB_fijJwW.js:263:7487)
    at HTMLDocument.<anonymous> (https://static.xx.fbcdn.net/rsrc.php/v3/yF/r/KAUB_fijJwW.js:263:6644)

It seems like messenger doesn't like us messing with their DOM nodes?

@CvX
Copy link
Collaborator

CvX commented Jan 20, 2019

Yeah… 😕

…I have an idea… that involves removing the MutationObserver and rendering emojis to canvas. 🙈

You know how currently the emoji replacement introduced in #720 uses redirects to change which emoji image is getting displayed? Well, it's possible to redirect to a dataURL! 😃

So we can render emoji (taken from the original URL and processes with String.fromCodePoint()) on-demand to a canvas, convert them to dataURL format and redirect to it. 😃

@felixfbecker
Copy link
Contributor Author

I'm kind of out of ideas on this one. I think what we're seeing here is React holding a references to the old img that we replaced with a span. When it discovers that it needs to remove that img as part of a rerender, it calls removeChild(), which fails because the img is not anymore in the DOM and it really should be removing the new span instead.

The emojis in the message editor are possible to replace without this error because they use spans with background-image, so we can modify the element's textContent in place and just remove the background-image style. But emojis in the message list are imgs, which cannot have contents, not even with display: contents or pseudo elements.

@felixfbecker
Copy link
Contributor Author

Yeah… 😕

…I have an idea… that involves removing the MutationObserver and rendering emojis to canvas. 🙈

You know how currently the emoji replacement introduced in #720 uses redirects to change which emoji image is getting displayed? Well, it's possible to redirect to a dataURL! 😃

So we can render emoji (taken from the original URL and processes with String.fromCodePoint()) on-demand to a canvas, convert them to dataURL format and redirect to it. 😃

Nice, that should work. But it'll have to be done through IPC I think since the interceptor is defined in the main process.

@CvX
Copy link
Collaborator

CvX commented Jan 20, 2019

Yup, the strategy would be pretty much like in #731 (comment). 🙂

@felixfbecker
Copy link
Contributor Author

It's a bit annoying that there is no real IPC layer used yet, like JSON RPC or comlink.

@felixfbecker
Copy link
Contributor Author

Seems to work

@felixfbecker
Copy link
Contributor Author

Need to tweak sizing on Windows

image

@felixfbecker
Copy link
Contributor Author

Should be all fixed! 🎉

@CvX
Copy link
Collaborator

CvX commented Jan 27, 2019

  • There are a couple of broken emojis:
    screen shot 2019-01-21 at 03 23 27 screen shot 2019-01-21 at 03 23 57

An update on "broken emojis" issue:

As per electron/electron#16530 Electron 5.0.0-beta.1 contains a newer Chromium version that fixes most (though not all) emoji rendering problems:

emojis 1 emojis 2

It seems that there's a change in emoji's vertical offset when rendering, so on 5.0.0-beta.1 they're cut off a bit at the top. It's something to look out for when we upgrade after 5.0 stabilizes.

Anyway, I'm marking this one as "fixed".
The other 3 issues remain (128px emojis, "MaxListenersExceededWarning", and facebook's thumbs-up).

@felixfbecker
Copy link
Contributor Author

The earliest I can get to this is next week, anyone is welcome to push/PR to the branch.

@felixfbecker
Copy link
Contributor Author

Merged in master with change to TypeScript

@CvX
Copy link
Collaborator

CvX commented Jan 30, 2019

Thank you! 🎉🚀

@CvX
Copy link
Collaborator

CvX commented Jan 31, 2019

Merged in the master once again, and fixed the Facebook's thumbs-up:

@felixfbecker
Copy link
Contributor Author

Btw I just discovered OffscreenCanvas which is also available in WebWorkers. I wonder if it's available in the Electron main process?

@CvX
Copy link
Collaborator

CvX commented Feb 2, 2019

When I suggested the use of canvas I originally thought we could use the offscreen variant, but when I tried it… nope! 😄 Wasn't available in the context of the main process.

@sindresorhus
Copy link
Owner

@CvX
Copy link
Collaborator

CvX commented Feb 3, 2019

Hm, I don't think Electron's offscreen rendering is a good fit here. Keeping a spare (hidden) frameless window just for rendering emoji seems excessive. 😃

Copy link
Collaborator

@CvX CvX left a comment

Choose a reason for hiding this comment

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

🚀

@felixfbecker
Copy link
Contributor Author

All done!

@CvX CvX requested a review from sindresorhus February 19, 2019 09:46
@sindresorhus sindresorhus merged commit 1d1c2d5 into sindresorhus:master Feb 20, 2019
sindresorhus pushed a commit that referenced this pull request Feb 20, 2019
@sindresorhus
Copy link
Owner

Nice work, everyone! 🎉

@felixfbecker
Copy link
Contributor Author

:shipit: 🚢

@felixfbecker felixfbecker deleted the native-emoji branch February 22, 2019 15:58
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.

Option to use native Apple emoji
4 participants