Broadcast messages to announce changes to Places

RESOLVED FIXED

Status

Firefox OS
Gaia::System::Browser Chrome
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: benfrancis, Assigned: Jovan Gerodetti, NeedInfo)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

2 years ago
The homescreen needs to know when a pinned site or pinned page changes so that it can update itself.

I think we need to send messages using postMessage https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage on a BroadcastChannel https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel

The homescreen needs to know when a site or page is pinned or unpinned. It might also be useful to include the URL of the site or page which changed so that the homescreen can do something smarter than just reloading the whole list.
(Reporter)

Comment 1

2 years ago
Jovan, do you think you'd be able to have a go at this?

Let me or Alberto know if you need some help.
Flags: needinfo?(titannanomail)
Flags: needinfo?(apastor)
(Assignee)

Comment 2

2 years ago
Yes I think I can give it a try :)

Where should this message be broadcasted? 
In the system browser UI I guess, but which files should I check out to get started?
Flags: needinfo?(titannanomail) → needinfo?(bfrancis)
(Reporter)

Comment 3

2 years ago
Great!

These actions are triggered from AppChrome:
pinSite https://github.com/mozilla-b2g/gaia/blob/kanikani/apps/system/js/app_chrome.js#L449
unpinSite https://github.com/mozilla-b2g/gaia/blob/kanikani/apps/system/js/app_chrome.js#L497
pinPage https://github.com/mozilla-b2g/gaia/blob/kanikani/apps/system/js/app_chrome.js#L406
unpinPage https://github.com/mozilla-b2g/gaia/blob/kanikani/apps/system/js/app_chrome.js#L428

But the actual database access takes place in Places:
pinSite https://github.com/mozilla-b2g/gaia/blob/kanikani/apps/system/js/places.js#L397
setPinned (for pages) https://github.com/mozilla-b2g/gaia/blob/kanikani/apps/system/js/places.js#L357

We probably want to send the messages once we know the database modification has actually happened, in a callback or when a Promise resolves.

Warning: This code is a bit of a mess at the moment as it's in transition from the old DataStores to the new IndexedDB database.
Flags: needinfo?(bfrancis)
(Assignee)

Comment 4

2 years ago
Do Homescreen and System app share the same window object? 
Can I broadcast the event on the system app window object?
Flags: needinfo?(bfrancis)
Nope, they don't, but you can still broadcast messages via BroadcastChannel as both iframes are in the same domain. You can see an example on the Search app

https://github.com/mozilla-b2g/gaia/blob/kanikani/apps/search/js/search.js#L57

Let me know if you have any other question!
Flags: needinfo?(bfrancis)
Flags: needinfo?(apastor)
(Assignee)

Comment 6

2 years ago
I finished the broadcasting part. I'd create a pull so one of you can have a look. 
Who should I set for review?
Flags: needinfo?(bfrancis)
Flags: needinfo?(apastor)
(Assignee)

Comment 7

2 years ago
I finished the broadcasting part. I'd create a pull so one of you can have a look. 
Who should I set for review?
(Reporter)

Comment 8

2 years ago
Great :) Either of us is fine, I'm happy to review this.
Flags: needinfo?(bfrancis)
Created attachment 8749162 [details] [review]
[gaia] TitanNano:fix_1270102 > mozilla-b2g:kanikani
(Assignee)

Comment 10

2 years ago
did I messup the review flag? I can't find one on my patch.
Flags: needinfo?(bfrancis)
Assignee: nobody → titannanomail
Flags: needinfo?(apastor)
Attachment #8749162 - Flags: review?(bfrancis)
(Reporter)

Comment 11

2 years ago
Comment on attachment 8749162 [details] [review]
[gaia] TitanNano:fix_1270102 > mozilla-b2g:kanikani

This is great! Thanks Jovan.

We'll want to figure out what to do when a site or page is unpinned, but this is a great start.
Flags: needinfo?(bfrancis)
Attachment #8749162 - Flags: review?(bfrancis) → review+
(Reporter)

Comment 12

2 years ago
Landed on kanikani https://github.com/mozilla-b2g/gaia/commit/3322b12d0f173ebd1bf02e8a7c6685b537c0ef54
Status: NEW → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → FIXED
(Assignee)

Comment 13

2 years ago
great! I'm interested to continue working on the homescreen. 
So if you have other bugs I can work on, I'll be happy to take a look that them :)
Flags: needinfo?(bfrancis)
You need to log in before you can comment on or make changes to this bug.