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

Enable tray icon on Linux without breaking Windows #23

Merged
merged 6 commits into from
Sep 7, 2016
Merged

Enable tray icon on Linux without breaking Windows #23

merged 6 commits into from
Sep 7, 2016

Conversation

ConorIA
Copy link
Contributor

@ConorIA ConorIA commented Aug 27, 2016

Here is a suggestion to resolve issue #22, and offer a more elegant solution to issue #1. The png icons are of my own making, having traced the ico files in inkscape. They can and maybe should be replaced by official icons, but they do the trick for now!

@ConorIA ConorIA mentioned this pull request Aug 27, 2016
@@ -24,14 +24,22 @@ const {app, BrowserWindow, Menu, Tray} = require('electron');
const path = require('path');
const config = require('./../config');

const iconPath = path.join(app.getAppPath(), 'img', 'tray.ico');
const iconBadgePath = path.join(app.getAppPath(), 'img', 'tray.badge.ico');
var iconExt = null;
Copy link
Contributor

@lipis lipis Aug 30, 2016

Choose a reason for hiding this comment

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

var iconExt = 'png';

@lipis
Copy link
Contributor

lipis commented Aug 30, 2016

You should also update this part: https://github.com/wireapp/wire-desktop/blob/master/electron/js/util.js#L59-L69

to something like:

if (process.platform === 'darwin') {
  app.dock.setBadge(count ? count[1] : '');
} else if (count) {
  tray.useBadgeIcon();
} else {
  tray.useDefaultIcon();
}

@lipis
Copy link
Contributor

lipis commented Aug 30, 2016

Having done all that.. it doesn't work on my Ubuntu 16.04 :/ Can you send us a screenshot wiht yours?

@ConorIA
Copy link
Contributor Author

ConorIA commented Aug 30, 2016

I'm out of town / away from my laptop today. I'll send a screenshot over as soon as I can.

@lipis
Copy link
Contributor

lipis commented Aug 30, 2016

🌴 🍺 🍸

@ConorIA
Copy link
Contributor Author

ConorIA commented Aug 30, 2016

There's the icon with the context menu open. I use the 'top icons' extension on Gnome, so on other systems it will be in a tray on the bottom left corner. This is using the build based on my PR. I will try with the changes you have suggested.

screenshot from 2016-08-30 16-56-43

@ConorIA
Copy link
Contributor Author

ConorIA commented Aug 30, 2016

Yay! I got a message! 😉
screenshot from 2016-08-30 17-30-08

aaaaand I read it!
screenshot from 2016-08-30 17-38-06

@lipis
Copy link
Contributor

lipis commented Aug 30, 2016

Your next task is to make the travis tests green.. and we'll ask our designers to provide the correct PNGs :)

@ConorIA
Copy link
Contributor Author

ConorIA commented Aug 31, 2016

Getting a type error now. A little over my head. Any suggestions? Also, if you want to ask your designers for an SVG app icon to go with the PNG tray icons, that'd be great! 😃

@ConorIA
Copy link
Contributor Author

ConorIA commented Sep 1, 2016

Played around a little, but still no luck. I tried replacing line 33 (let appIcon = null;) with var appIcon = new Tray(iconPath);, but I get an error:

TypeError: Error processing argument at index 0, conversion failure from /home/conor/git/wire-desktop/node_modules/electron-prebuilt/dist/resources/default_app.asar/img/tray.png

Might it be related to: electron/electron#1006

@bennycode
Copy link
Contributor

TypeError: Cannot read property 'setImage' of null
at Object.useBadgeIcon (/home/travis/build/wireapp/wire-desktop/electron/js/menu/tray.js:63:12)

It looks like appIcon isn't defined?

@ConorIA
Copy link
Contributor Author

ConorIA commented Sep 1, 2016

As far as I can tell, the app icon is originally set to null but should be replaced as long as we're not on Darwin. Not sure why it isn't getting replaced later on. I'm not familiar with JS, so I might be reading it wrong.

@ConorIA ConorIA changed the title Enable tray icon on Linux withouth breaking Windows Enable tray icon on Linux without breaking Windows Sep 2, 2016
@ConorIA
Copy link
Contributor Author

ConorIA commented Sep 2, 2016

Could it be that the test is simply timing out before the badge updates? On my machine, when I run npm test --verbose, the window barely opens before it is closed and warns:

  util
    #updateBadge()
TypeError: Cannot read property 'setImage' of null
    at Object.useBadgeIcon (/home/conor/wire-desktop/electron/js/menu/tray.js:63:12)
    at Timeout._onTimeout (/home/conor/wire-desktop/electron/js/util.js:62:14)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
TypeError: Cannot read property 'setImage' of null
    at Object.useBadgeIcon (/home/conor/wire-desktop/electron/js/menu/tray.js:63:12)
    at Timeout._onTimeout (/home/conor/wire-desktop/electron/js/util.js:62:14)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
      1) should update badge according to window title
      ✓ should update badge according to window title (1498ms)

I have tried to adjust the timeout with this.timeout, but it seems that the use of arrow functions breaks that option (https://mochajs.org/; mochajs/mocha#2018).

@lipis
Copy link
Contributor

lipis commented Sep 6, 2016

Can you add please these images for now and we'll deal with the exact resolutions later on..

@ConorIA
Copy link
Contributor Author

ConorIA commented Sep 6, 2016

Done! 😄

@lipis
Copy link
Contributor

lipis commented Sep 6, 2016

As for the tests it's failing because the tray.createTrayIcon() is never called and it's a bigger thing ATM.. For now just to fix the test and have it green.. update the code in tray.js to something like that:

  useDefaultIcon: function() {
    if (appIcon == null) return;
    appIcon.setImage(iconPath);
  },

  useBadgeIcon: function() {
    if (appIcon == null) return;
    appIcon.setImage(iconBadgePath);
  }

@lipis
Copy link
Contributor

lipis commented Sep 6, 2016

Also.. did you sign our CLA?

@lipis
Copy link
Contributor

lipis commented Sep 6, 2016

Let's see if Travis is going to wake up today! :)

Can you post screenshots of the two icons from your machine?

@ConorIA
Copy link
Contributor Author

ConorIA commented Sep 6, 2016

Strange, Travis just passed on the commit before the Travis fixes you suggested!

I'll get the screenshots and CLA to you as soon as I'm back in my office after a meeting.

Who should I send the CLA to? EDIT: Nevermind, found the address. We're good to go.

@ConorIA
Copy link
Contributor Author

ConorIA commented Sep 6, 2016

Here is the icon with no messages. I'm not very popular today, but I will send an image with the badge if someone writes to me. 😉

screenshot from 2016-09-06 16-48-18

And here it is with the badge.

screenshot from 2016-09-06 23-42-15

@david-wire
Copy link

CLA approved

@lipis lipis merged commit 0fadf07 into wireapp:master Sep 7, 2016
@lipis
Copy link
Contributor

lipis commented Sep 7, 2016

Boom..

@ConorIA ConorIA deleted the tray branch September 7, 2016 16:40
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.

5 participants