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

Separate Settings from the background page, and use it directly in options.html/popup.html #1599

Merged
merged 9 commits into from May 29, 2015

Conversation

mrmr1993
Copy link
Contributor

This PR decouples the Settings object from the background page, with a view to merging it with settings in the front-end, creating a unified chrome.storage-backed implementation.

It also uses the decoupled Settings to provide settings information directly to the options page and the browser icon popup, instead of via the background page.

The diff here is really quite unfriendly, but I've tried to keep every commit so that it

  • only makes one, small & obvious, set of changes,
  • compiles/passes tests, and
  • behaves the same (from a black-box perspective) as master.

@smblott-github
Copy link
Collaborator

Thanks @mrmr1993. I'll look at this soon, once the 1.50 issues calm down.

@mrmr1993
Copy link
Contributor Author

Rebased onto master.

@mrmr1993
Copy link
Contributor Author

Rebased onto master.

@mrmr1993
Copy link
Contributor Author

Rebased onto master.

@smblott-github
Copy link
Collaborator

@mrmr1993. I looked at this a while ago (but forgot to comment -- sorry!). Thoughts...

Does this go far enough?

It would be good to:

  • Get rid of settings in the front end entirely.
  • Use a single Settings.get "setting" method uniformly in both the front end and the back end.
  • Be able to write Settings.use "setting", (value) -> ... anywhere in the front end or back end, without having to consider whether setting is cached or not.

@mrmr1993
Copy link
Contributor Author

Does this go far enough?

I was already planning to do all of those things, this is just a step along the way. The diff is already unweildy, so I decided not to make it worse by touching all the frontend code that uses settings too.

If there are no issues, it would be great to see this merged so I have a base to start working on unified settings from.

This function does nothing related to Sync, and only affects Settings.
This stops Sync from being referred to from anywhere except
settings.coffee and settings_test.coffee.
This completely decouples settings.coffee from all other background
source files, so that it can (eventually) also be used in the frontend.
The Settings object used by the background page now uses 1 of 3 caches,
depending on the context it is available in:
* localStorage - in the background page
* a copy of localStorage - in non-background extension pages
  (options.html, popup.html, etc.)
* an empty object - in all other pages (where localStorage doesn't point
  to the extension's localStorage object).

For any extension page which is *not* the background page, a copy of
localStorage is used instead of true localStorage:
* Once localStorage is updated by one background page, the others can
  only see the updated copy.
  - Pages with an updated cache can't tell which changes are new, and so
    don't know which postUpdateHooks to run.
* By copying localStorage's contents into a new object, extension pages
  can still access settings synchronously.
  - This is especially important to options.html and popup.html; they
    will not work without it.
Instead of directly accessing the background page's Settings object,
the options page and the page popup now have their own.
@mrmr1993
Copy link
Contributor Author

Rebased onto master.


root.Settings = Settings =
cache: settingsCache
init: -> Sync.init()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we only initialise Sync on the background page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Starting to use chrome.storage (via Sync) everywhere is the point of this PR, so we can stop moving settings data between contexts manually.

@smblott-github
Copy link
Collaborator

I can see the elegance of what you're getting at with this. It's not too far from the three "should-we-not-go-further" issues I mentioned above.

Idea:

  • When using this in the front end, you'll have to deal with isLoaded and load (or event listeners). That's easily done with an AsyncDataFetcher.

smblott-github added a commit that referenced this pull request May 29, 2015
Separate Settings from the background page, and use it directly in options.html/popup.html
@smblott-github smblott-github merged commit c5babce into philc:master May 29, 2015
@smblott-github
Copy link
Collaborator

Thanks, @mrmr1993. It would be great if you could push on with the next steps.

@mrmr1993 mrmr1993 deleted the settings-refactor branch May 29, 2015 11:49
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.

None yet

2 participants