unityLoaded never gets called

Bug #1073397 reported by Andrew Flegg
120
This bug affects 24 people
Affects Status Importance Assigned to Milestone
unity-webapps-gmail (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

This is a continuation of bug #1059051 which seems to be resolved for some but not others.

I'm using 2.4.7 of unity-webapps-gmail in Firefox 16.0.2+build1-0ubuntu0.12.10.1 in Quantal.

As described on bug #1059051, the request to install appears, but nothing appears in the launcher - nor are there any menu or other integrations.

No errors appear in the console if Firefox is launched from a terminal.

By using a bit of judicious `window.alert' debugging in /usr/share/unity-webapps/userscripts/unity-webapps-gmail/GMail.user.js, everything is executing perfectly up until the invocation of Unity.init towards the end of the script. A window.alert immediately before this works, but an alert at the top of unityLoaded() doesn't.

I'm guessing that the delay introduced by setTimeout/wrapCallback and the inner "wait()" function is what's causing the problem. Neither unity-webapps-googlecalendar nor unity-webapps-launchpad have that extra delay step. Unfortunately, removing the delay isn't feasible either because of the dynamic loading of Gmail.

Without knowing more about Unity.init and the purpose of "wrapCallback", I'm not sure what's going on. Is there any documentation?

Tags: patch
Revision history for this message
Andrew Flegg (aflegg) wrote :

Found it, it's the passing of "login" which doesn't work. Removing "login" from the call to `Unity.init' gets me a launcher icon:

----8<----
        Unity.init({ name: "GMail",
                     iconUrl: "icon://unity-webapps-gmail",
                     homepage: 'https://mail.google.com',
                     domain: 'mail.google.com',
                     onInit: wrapCallback(unityLoaded) });
---->8----

Revision history for this message
Andrew Flegg (aflegg) wrote :

Once passed that there are a couple of other issues:

1) `checkMessangesCount()' [sic] doesn't handle the fact that there could be newlines/whitespace after the "Mail" (there is in my DOM)
2) The label identification code is completely wrong for my setup.

The attached patch to GMail.user.js includes the changes necessary for the integration to work for me:

0) Removes the 'login' attribute to Unity.init. This should be replaced with something else so that the intended functionality still works!
1) Strip any trailing whitespace off before comparing the text content to 'Gmail' or 'Mail'
2) Use an XPath very similar to that used to find the 'Inbox' link.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in unity-webapps-gmail (Ubuntu):
status: New → Confirmed
Revision history for this message
Andrew Flegg (aflegg) wrote :

The patch's fix to the labels isn't quite right. I'm getting the ones below the "More v" fold appear in the messaging menu, rather than the ones above it. Should be an easy fix, though.

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "Gmail.user.patch" of this bug report has been identified as being a patch. The ubuntu-reviewers team has been subscribed to the bug report so that they can review the patch. In the event that this is in fact not a patch you can resolve this situation by removing the tag 'patch' from the bug report and editing the attachment so that it is not flagged as a patch. Additionally, if you are member of the ubuntu-reviewers team please also unsubscribe the team from this bug report.

[This is an automated message performed by a Launchpad user owned by Brian Murray. Please contact him regarding any issues with the action taken in this bug report.]

tags: added: patch
Revision history for this message
Stefan Sommer (stefan-nefan) wrote :

The patch didn't work for me - still no gmail in the launcher or other integration.

Revision history for this message
Andrew Flegg (aflegg) wrote :

Another patch. This one corrects the XPath to get the correct labels and ALSO includes three window.alert debug points:

1) Script initialisation
2) When isCorrectPage() returns true
3) After Unity integration has initialised

If the patch still isn't working for you, please record which of these three messages you get. We _might_ have to get your HTML structure saved off (I used Firefox's built-in inspector to copy the outer HTML of the <html> element). I'd suggest not attaching it to the bug, though, at least without some very careful content scrubbing.

Revision history for this message
Stefan Sommer (stefan-nefan) wrote :

Thanks. I get the first initialization alert but it fails on isCorrectPage(). With Firefox's inspector I can see that the body element contains elements with id="js_frame" and id="hist_frame" but the script fails to find any of them. Is it possible that the document is not correctly passed to the script? I'm not very versed in javascript so I'll be happy e.g. mail you my html.

Btw., I'm using google apps if it makes any difference.

Revision history for this message
Andrew Flegg (aflegg) wrote :

Would be happy to see your HTML if you email it to me. I'm using Google Apps too; so, some follow-up questions:

1) What language/country is Google Apps in?
2) What kind of connection are you using? How fast is it?
3) What browser are you using on what hardware?

I wonder if speed of initialisation means a race condition, and that the "if (isCorrectPage())" should be inside the callback function, which it's otherwise wrapping.

Revision history for this message
Andrew Flegg (aflegg) wrote :

Stefan's helped me do more debugging and moving the isCorrectPage() call *inside* the timeout (to mitigate the Gmail dynamic loading) has got it working for him.

Gmail3.user.patch is a consolidated patch which should work in more circumstances.

Revision history for this message
Stefan Sommer (stefan-nefan) wrote :

Thanks, Andrew. I tested the patch on several machines and it does the job on all of them.

Revision history for this message
Stefan Sommer (stefan-nefan) wrote :

Same issue for google calendar and google plus. Patch attached.

Revision history for this message
Stefan Sommer (stefan-nefan) wrote :
Revision history for this message
Chad Wright (deerewright) wrote :

How does one go about applying these patches????

Revision history for this message
Stefan Sommer (stefan-nefan) wrote :

Chad, in a terminal do something like

cd; wget https://bugs.launchpad.net/ubuntu/+source/unity-webapps-gmail/+bug/1073397/+attachment/3424017/+files/Gmail3.user.patch; cd /usr/share/unity-webapps/userscripts/unity-webapps-gmail/; sudo patch GMail.user.js < ~/Gmail3.user.patch

for the gmail patch.

Revision history for this message
Ramin (raminzeb) wrote :

will they officially fix this or do we have to apply that patch? how does it work? should i choose to install the gmail webapp through firefox and then apply the patch or apply it first?

its pretty frustrating they havent fixed this to be honest

Revision history for this message
Ramin (raminzeb) wrote :

its ok ive applied the patch. i wonder if they'll put out an official fix for this?

Revision history for this message
mozon laurent (laurent-mozon) wrote :

thx for job
iv applied the patch and the icon in launcher appear. but no integration in the message indicator (no icone and so no unread message).

is this patch solved every thing for you ??? or juste as me the launcher icon ?

Revision history for this message
Jean-Luc Thirion (jlinho) wrote :

I also applied the "Consolidated path" from Andrew Flegg (aflegg) - message from 2012-11-04.

But I get the same issue as laurent-mozon, I have an icon but:
- no message count
- nor integration in the message indicator applet.

Revision history for this message
Jean-Luc Thirion (jlinho) wrote :

Here is a basic patch for French Gmail users.

Note that the original script does work only for English GMail, since
there is an explicit référence to english text in function
"checkMessangesCount()". '//div[@aria-label="Navigate to"]/span'. In
the french GMail version the XPath translates to: '//div[@aria-
label="Accéder à"]/span'. Please find another XPath that is language
independent.

For french users that can't wait for an official patch, I attached a
quick fix *FOR FRENCH USERS ONLY*

To apply:

sudo apt-get install --reinstall unity-webapps-gmail
cd;
wget https://bugs.launchpad.net/ubuntu/+source/unity-webapps-gmail/+bug/1073397/+attachment/XXXXX/+files/GMail.user.js.patch.fr;
cd /usr/share/unity-webapps/userscripts/unity-webapps-gmail/;
sudo patch GMail.user.js < ~/GMail.user.js.patch.fr;

Notice that I retired the "Compose message" entry because I did not manage to make it work properly.

Revision history for this message
Olivier Febwin (febcrash) wrote :

What's about the official patch ?

Revision history for this message
Simon Charette (charettes) wrote :

Jean-Luc, your patch works perfectly for me using fr-CA gmail :) Thank you!

Revision history for this message
Fernando Geraldo Mantoan (fernandouhu) wrote :

I had the same problem here, regarding the function checkMessagesCount().

What happens is that the variable "tag" is null when the evaluate() function doesn't find what it's looking for. Then, the following line will raise an exception:

if (tag.textContent != 'Gmail' && tag.textContent != 'Mail') {

I changed to:

if (tag != null && tag.textContent != 'Gmail' && tag.textContent != 'Mail') {

Now the GMail integration is working for me!

Revision history for this message
Fernando Geraldo Mantoan (fernandouhu) wrote :

A workaround for GMail in Brazilian Portuguese:

var tag = document.evaluate('//div[@aria-label="Navegar para"]/span', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;

Revision history for this message
Wayne Do Rego (waynebow) wrote :

I've made a few changes that seem to get some simple notifications going...

Add the following line:

    var lastMessanges = 0;

After:

    var pane = null;

Then add:

    if (lastMessanges < numMessanges) {
    lastMessanges = numMessanges
    if (lastMessanges == 1) {
     Unity.Notification.showNotification("Gmail", "You have " + lastMessanges + " unread message.", null);
     }
    if (lastMessanges > 1) {
     Unity.Notification.showNotification("Gmail", "You have " + lastMessanges + " unread messages.", null);
     }
    }
    lastMessanges = numMessanges

After:

    Unity.Launcher.setCount(Number(numMessanges));

The attached file contains the above changes as well as Fernando and Andrew's changes.

This my first attempt at Java Script so feedback would be most welcome!

Revision history for this message
londumas (helion331990) wrote :

The patch only works for me if I use Firefox and if gmail.com is open. I use Chromium and I don't see the use of having a launcher count emails only if I can see them direcly. I used Jean-Luc Thirion (jlinho) patch.

Thank you if you have any idea, maybe someting should be changed in dconf ? I folowed the code lines of Jean-Luc Thirion (jlinho).

Revision history for this message
Jean-Luc Thirion (jlinho) wrote : Re: [Bug 1073397] Re: unityLoaded never gets called

@Helion

Unity Web integration works only when the related web site is open in your
browser.

2013/5/16 Hélion du Mas des Bourboux <email address hidden>

> The patch only works for me if I use Firefox and if gmail.com is open. I
> use Chromium and I don't see the use of having a launcher count emails
> only if I can see them direcly. I used Jean-Luc Thirion (jlinho) patch.
>
> Thank you if you have any idea, maybe someting should be changed in
> dconf ? I folowed the code lines of Jean-Luc Thirion (jlinho).
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1073397
>
> Title:
> unityLoaded never gets called
>
> To manage notifications about this bug go to:
>
> https://bugs.launchpad.net/ubuntu/+source/unity-webapps-gmail/+bug/1073397/+subscriptions
>

Revision history for this message
Arnaud Ober (user-deactivated-80571) wrote :

I used the "Google Plus" patch. What have I to do after this patch? Just restart session?

Revision history for this message
londumas (helion331990) wrote :

@Jean-Luc Thirion (jlinho)

Thank for your answer. If it only work when the website is open, I have dificulties to understand what is the purpose of it. Why see the number of unread email in the launcher when I can see it directly on the page.
The real solution is then to make the gmail webapp using kind of the same code as unity-Mail. Just adding the posibility of installing it when first logging to a gmail account.

Webapps will be realy usefull when they will do this work and have the normal ubuntu notification.

Thank you for your answer.

Revision history for this message
Mark Hannon (markhannon) wrote :

This bug recently (last month) started to impact me. The removal of the login attribute as described in comment #1 fixed things for me. (I have login credentials stored with Lastpass in both firefox and chromium if that provides any hints)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.