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

Fixes #110 #134

Merged
merged 11 commits into from
Apr 17, 2017
Merged

Fixes #110 #134

merged 11 commits into from
Apr 17, 2017

Conversation

Lplenka
Copy link
Collaborator

@Lplenka Lplenka commented Apr 2, 2017

There was no support for showing unread count in the Tray icon, I have added the functionality.
trayicon

There is no support for overlay icon in Linux as of now please refer issue #9020.

This fix works fine.
Any suggestions are welcome 😄

@sinwar
Copy link

sinwar commented Apr 2, 2017

@Lplenka It'll be great if you use different branch than master to create pull request.

@akashnimare
Copy link
Member

It'll be great if you use different branch than master to create pull request.
🙏

window.tray = null;
}
} else {
window.createTray();
Copy link
Member

Choose a reason for hiding this comment

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

should be createTray()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, will change it.

@akashnimare
Copy link
Member

on macOs -
image

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 2, 2017

Size issue on different OS. Have to make the config OS specific.

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 2, 2017

Fixed the errors in Mac & Windows.
Everything looks & works perfect now. 😄

Mac OS:
mac_trayicon

Windows:

windowstrayicon

@akashnimare
Copy link
Member

The one big problem with this PR is that we don't want to completely replace the tray icon with that canvas image. The ideal solution is to set that canvas on top of Zulip tray icon. Something like this -

icon

So that it look like this -

screen shot 2017-04-04 at 12 34 55 am

You gotta use setOverlayIcon method for this. As of now this method only supports Windows as mentioned here.
More info -
electron/electron#4011
electron/electron#3148

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 3, 2017

Okay, Since there is no support to overlay tray in Linux & MacOS I thought this will work for the time being. Because we cannot implement something which electron doesn't have itself.

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 3, 2017

The original zulip Icon will always be there if no unread messages are present.
If new messages come canvas will appear with the specific unread count.
This is the best fix I could find until the electron actually supports overlay.
I hope I am making sense.

@akashnimare
Copy link
Member

Wait on. Let me try to setup setOverlayIcon on windows and see if we still can get something like this (atleast on windows) -

@akashnimare
Copy link
Member

akashnimare commented Apr 3, 2017

The original zulip Icon will always be there if no unread messages are present.
If new messages come canvas will appear with the specific unread count.
This is the best fix I could find until the electron actually supports overlay.
I hope I am making sense.

Definitely, it makes sense. It's probably a good fix until electron supports this api on macOS + Linux 😃

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 3, 2017

Yes, we can handle this differently in different OS. If Windows has overlay we can use that, but then we will have a different implementation in different OS. Would that be fine?
I have seen other electron apps too, none of them has this feature of Overlay, so I could only come up with this idea or workaround till Electron supports Overlay in Tray. We can always implement that then. 😄

@akashnimare
Copy link
Member

akashnimare commented Apr 3, 2017

If Windows has overlay we can use that, but then we will have a different implementation in different OS. Would that be fine?

Yes.

@timabbott
Copy link
Member

For the webapp, we just have a collection of 100 generated images that we use for favicons (if the number exceeds 100, we just show an infinity symbol). So one doesn't need overlay support -- just the ability to change the image -- to produce arbitrary numbers.

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 3, 2017

@timabbott yes I feel like that's the only one more possible way to deal with this Issue.

This approach is even easier to implement than the way I used i.e. generate new canvas every time a new message comes. But here is twist we have to make 100 icons for Windows, 100 for Linux and 100 for MacOS because tray Icon size differs in three of them

I couldn't make those icons for all OS. Found html canvas is the only way till Electron supports overlay for all OS.

@akashnimare
Copy link
Member

I think we could get these favicons using -

	page.on('page-favicon-updated', (event, favicons) => {
		console.log(favicons.slice(-1)[0]);
	});

output -

➜  zulip-electron git:(master) ✗ npm start

> zulip@0.5.8 start /Users/akka/dev/zulipwork/zulip-electron
> electron ./app/main

Wait for app ready
Server StatusCode: 200
You are connected to: chat.zulip.org
https://chat.zulip.org/static/images/favicon/favicon-38.png
https://chat.zulip.org/static/images/favicon/favicon-93.png
https://chat.zulip.org/static/images/favicon/favicon-93.png
https://chat.zulip.org/static/images/favicon/favicon-93.png

I was just wondering if somehow we could set these favicon to our tray icon 🤔

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 3, 2017

I was just wondering if somehow we could set these favicon to our tray icon 🤔.

We can receive the image using http request to specific URL like

request
.get('https://chat.zulip.org/static/images/favicon/favicon-93.png')
.on('error', function(err) {
console.log(err)
})
.pipe(fs.createWriteStream('favicon-93.png'))'

But I think size issue will still remain for different OS 😕

@akashnimare
Copy link
Member

Will try to run this PR on windows tonight plus I'll see if we could use setOverlayIcon.

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 5, 2017

Will try to run this PR on windows tonight plus I'll see if we could use setOverlayIcon.

Okay 👍
I have checked in windows 10 also. Hopefully, you won't find any issues with the PR. Sorry, I by mistake clicked the close PR button 😅

@Lplenka Lplenka closed this Apr 5, 2017
@Lplenka Lplenka reopened this Apr 5, 2017
@akashnimare
Copy link
Member

Will review it again on Monday.

@akashnimare
Copy link
Member

akashnimare commented Apr 16, 2017

Does it work on Windows 10? Can you paste a screenshot?

@akashnimare
Copy link
Member

akashnimare commented Apr 16, 2017

Please move this file -

  • app/renderer/js/tray.js to app/main/tray.js (tray.js should be in the browser process)

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 17, 2017

Does it work on Windows 10? Can you paste a screenshot?

Yes works perfectly fine, here are some screenshots.

screenshot 36
screenshot 37
screenshot 38
windwostray

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 17, 2017

@akashnimare Is this necessary?

Please move this file -
app/renderer/js/tray.js to app/main/tray.js (tray.js should be in the browser process)

Initially, I tried running this file in app/main/tray.js but things didn't work if tray.js was imported into app/main/index.js, the tray icon image was never rendered. So I shifted to Renderer process and everything worked as expected.

I have added every functionality of Tray icon using IpcMain and IpcRenderer for proper communication between Main and Renderer processes. The icon works perfectly well while switching servers, reloading page, logging in/out etc.

Also if Tray icon is in renderer process it will be helpful to add required functionalities for our "Multiple Server Support" feature.

@akashnimare
Copy link
Member

Initially, I tried running this file in app/main/tray.js but things didn't work if tray.js was imported into app/main/index.js, the tray icon image was never rendered. So I shifted to Renderer process and everything worked as expected.

You can't import tray.js in Main process since it belongs to Renderer.

Also if Tray icon is in renderer process it will be helpful to add required functionalities for our "Multiple Server Support" feature.

Make sense.

@akashnimare
Copy link
Member

@Lplenka why does it create multiple tray icon in some cases (ex. navigating to a new URL)? Although it gets disappeared after few seconds. Can we prevent this event?

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 17, 2017

You can't import tray.js in Main process since it belongs to Renderer.

I meant currently our app does that, we import app/main/tray.js to app/main/index.js and call function tray.create();.

While In this PR since I shifted tray.js file to renderer, I am just calling this file in app/main/preload.js so the file runs every time app's window is created.

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 17, 2017

@Lplenka why does it create multiple tray icon in some cases (ex. navigating to a new URL)? Although it gets disappeared after few seconds. Can we prevent this event?

Yes I specifically dealt with this problem in index.js, Added this,

     //  To destroy tray icon when navigate to a new URL
win.webContents.on('will-navigate', e => {
	if (e) {
		win.webContents.send('destroytray');
	}
});

This probably happens because preload.js is called while navigating to a new URL, so I added this code to destroy tray icon during navigation and new tray icon appears as the page loads.

@akashnimare I am sure this part of code dealt with the problem you mentioned because I don't find this problem anymore. I can share the gif if you want.

@akashnimare akashnimare merged commit f290732 into zulip:master Apr 17, 2017
@akashnimare
Copy link
Member

Cross tested this PR on all the platforms. Works great. This is probably the best solution to show unreadcounts in the tray icon. We could improve it later once electron officially support it with setOverlayicon etc. @Lplenka keep in mind that eventually we should add something like this
https://github.com/zulip/zulip-electron/pull/134#issuecomment-291244986

Note - Sorry for the delay. Thanks for all the work 🚀 ❤️

@Lplenka
Copy link
Collaborator Author

Lplenka commented Apr 17, 2017

Cross tested this PR on all the platforms. Works great. This is probably the best solution to show unreadcounts in the tray icon. We could improve it later once electron officially support it with setOverlayicon etc. @Lplenka keep in mind that eventually we should add something like this
#134 (comment)
Note - Sorry for the delay. Thanks for all the work 🚀 ❤️

Thanks! 😄 and yes I will definitely work on that as soon as required feature is implemented in Electron.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants