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

Update functions.js #2056

Open
Durgesh4993 opened this issue Mar 3, 2024 · 4 comments
Open

Update functions.js #2056

Durgesh4993 opened this issue Mar 3, 2024 · 4 comments
Labels
Feature request Wish or idea good first issue A GitHub standard for inviting (new) contributors *Congratulations in advance!* help wanted Just an old github standard we add automatically. (The team can remove it when working on it.) up-for-grabs (a github standard for inviting new contributors) - Welcome! ♥

Comments

@Durgesh4993
Copy link

Description:

Using this alternative approach simplifies the code by leveraging the built-in capabilities of the browser's storage synchronization mechanism, eliminating the need for custom export/import logic. It also ensures that the extension's settings are automatically synchronized across the user's devices without requiring explicit user actions for exporting/importing data.

In this alternative approach:

  • The chrome.storage.sync API is used directly to synchronize extension settings with the user's Google Account, enabling automatic data synchronization across devices where the user is signed in.
  • The syncSettings function saves the entire extension storage data to the synced storage.
  • The pullSettings function retrieves all data from the synced storage and updates the extension's local storage with the synced data.

Code Changes:

var attributes = {
        theme: true,
        improvedtube_home: true,
        title_version: true,
        it_general: true,
        it_appearance: true,
        it_themes: true,
        it_player: true,
        it_playlist: true,
        it_channel: true,
        it_shortcuts: true,
        it_blocklist: true,
        it_analyzer: true,
        layer_animation_scale: false
    };

    for (var attribute in attributes) {
        var value = satus.storage.get(attribute);

        if (attribute === 'improvedtube_home') {
            attribute = 'home-style';
        }

        if (satus.isset(value)) {
            extension.skeleton.rendered.setAttribute(attribute.replace('it_', '').replace(/_/g, '-'), value);
        }
    }
@Durgesh4993 Durgesh4993 added Feature request Wish or idea good first issue A GitHub standard for inviting (new) contributors *Congratulations in advance!* help wanted Just an old github standard we add automatically. (The team can remove it when working on it.) up-for-grabs (a github standard for inviting new contributors) - Welcome! ♥ labels Mar 3, 2024
@raszpl
Copy link
Contributor

raszpl commented Mar 3, 2024

Wait a minute, not everyone uses chrome, and not everyone uses sync.

chrome.storage.sync.set

While this addition might be beneficial to those that do, it shouldnt remove settings raw file import/export like your pull request does.

@timtoo
Copy link

timtoo commented Mar 3, 2024

Wait a minute, not everyone uses chrome, and not everyone uses sync.

Firefox implements the storage.sync api, though I don't know the details of how it works if you don't have sync enabled.

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync

@ImprovedTube
Copy link
Member

ImprovedTube commented Mar 6, 2024

hi and thanks! @Durgesh4993 @raszpl @timtoo

  • we allow the use chrome.storage.sync on press of a button since @josephShokry's last PR Sync settings in cloud storage #1994

    • (makes sense when user doesn't have the exact same settings on two device. Could come with logic also comparing display resolution or so.)
  • we use chrome.storage.local in all browsers

    • in chrome, chrome.storage.sync can be used synonym if the user is not logged in.
      • If there is a browser not supporting the later (or both), then we can define the variable conditionally (or add that to specific build actions per browser)

@raszpl
Copy link
Contributor

raszpl commented Mar 6, 2024

Hah I didnt even notice sync was already supported, so this patch just deletes manual file settings import/export while breaking sync. Weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Wish or idea good first issue A GitHub standard for inviting (new) contributors *Congratulations in advance!* help wanted Just an old github standard we add automatically. (The team can remove it when working on it.) up-for-grabs (a github standard for inviting new contributors) - Welcome! ♥
Projects
None yet
Development

No branches or pull requests

4 participants