Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement live editor preview #209

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

marcustyphoon
Copy link
Collaborator

@marcustyphoon marcustyphoon commented Sep 13, 2024

User-facing changes

Adds a checkbox to the manage palettes page that, when checked, makes the colors you're currently adjusting update live in all of your Tumblr tabs in real time. This is, IMO, awesome for palette creation.

Tested and working with #206, which is pretty fun; one can navigate to a page that uses the new system variables and see the color-mix generated colors live.

Technical explanation

See comments.

Issues this closes

I never bothered to make an issue to request this, apparently.

@marcustyphoon

This comment was marked as outdated.

@marcustyphoon
Copy link
Collaborator Author

marcustyphoon commented Sep 13, 2024

Okay, let's see how much of this improved state machine I can explain...

  • There's a checkbox to toggle live previews in the manage palettes interface. If there are multiple manage palettes interfaces open, only one will live preview at a time, as opening a new manage palettes interfaces or toggling on live preview in a manage palettes interface toggles the others' live preview modes off (via a function set as a window property and referenced via browser.extension.getViews()).
  • When live previews are toggled on, the previewPalette storage variable is set to the live palette object. When live previews are toggled off or the manage palettes interface is closed (pagehide event; best effort), the storage variable is deleted.
  • When the previewPalette storage variable is set, the content script applies this "previewPalette" palette. When it isn't, it doesn't.
  • The content script periodically checks if it's in "previewPalette" mode but no manage palettes interfaces are open (by checking if any respond to browser.runtime.sendMessage). This can occur if the manage palettes interface is closed without the pagehide event firing, which is apparently a thing (crash the manage palettestab to simulate this). The content script deletes the previewPalette storage variable if this occurs.

One could probably remove the previewPalette storage variable entirely and just use messaging to communicate the live preview mode information, which could potentially be more elegant, but without a background script this would be rather annoying, as sendMessage's one-point-to-one-point paradigm breaks down when you can have multiple tabs and no one is really in control.

@marcustyphoon marcustyphoon marked this pull request as ready for review September 13, 2024 09:10
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant