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

action menu - create settings page #52

Merged
merged 17 commits into from
Apr 20, 2023

Conversation

baruchiro
Copy link
Collaborator

@baruchiro baruchiro commented Apr 3, 2023

First work of #27.

In this PR I created the infrastructure for controlling the state of the extension from its popup.

See the review comments for specific implementation details.

tinywow_Recording 2023-04-03 200726_18612307

Copy link
Collaborator Author

@baruchiro baruchiro left a comment

Choose a reason for hiding this comment

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

My suggestion is to review this PR commit-by-commit.

gulpfile.js Show resolved Hide resolved
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created by npm create vue and then I cleaned some files.

};
},
mounted() {
chrome.storage.local.get('showSnyk').then(({ showSnyk }) => (this.showSnyk = showSnyk));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using chrome.storage.local. Most of the docs use chrome.storage.sync so the settings will be synced with the account logged in another computer.

chrome.storage.local
.set({ showSnyk })
.then(() => chrome.storage.local.get())
.then(sendEventSettingsChanged);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The popup is running on the extension context, and to pass the settings to the injected script, we need to send a message to the content script, which can send a message to the webpage (where the injected script is live).

Comment on lines 29 to 42
export const usePackageInfo = (type, name) =>
computed(() => {
const packageInfo = store.packages[type]?.[name];
if (!packageInfo) return null;

const filteredSources = Object.entries(packageInfo.sources).reduce((acc, [key, value]) => {
if (settings[key] !== false && value) {
acc[key] = value;
}
return acc;
}, {});

return { ...packageInfo, sources: filteredSources };
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/content.js Outdated
@@ -27,6 +28,8 @@ export const mountContentScript = (contentScript) => {
return;
}

events.sendEventSettingsChangedToWebapp();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Send the settings to the injected script after it is loaded.

@baruchiro baruchiro requested a review from jossef April 4, 2023 07:57
@baruchiro baruchiro marked this pull request as ready for review April 4, 2023 07:57
@baruchiro baruchiro marked this pull request as draft April 4, 2023 12:39
@baruchiro
Copy link
Collaborator Author

gulpfile.js Show resolved Hide resolved
gulpfile.js Show resolved Hide resolved
gulpfile.js Outdated Show resolved Hide resolved
gulpfile.js Outdated Show resolved Hide resolved
gulpfile.js Outdated Show resolved Hide resolved
gulpfile.js Outdated Show resolved Hide resolved
}
if (!store.packages[type][name]) {
store.packages[type][name] = {
const packageStoreID = ({ type, name }) => `${type}$${name}`;
Copy link
Member

Choose a reason for hiding this comment

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

I prefer using / as a separator in package ids instead of $. Also, I think renaming the object packageID -> package

Suggested change
const packageStoreID = ({ type, name }) => `${type}$${name}`;
const getPackageId = (package) => `${package.type}/${package.name}`;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I avoided using / because it is an allowed character in packages like @scoped/package.

I remember I saw a "package identifier convention" in one of the advisories, I will search for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can we use : instead of $$ or /?

Copy link
Member

Choose a reason for hiding this comment

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

yes : is also ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

src/custom-elements/store.js Show resolved Hide resolved
src/popup/src/Popup.vue Outdated Show resolved Hide resolved
@github-actions
Copy link

New devDevelopment

@types/firefox-webext-browser

DescriptionTypeScript definitions for WebExtension Development in FireFox
LicenseMIT
ContributorsJasmin Bom
Snyk Advisor Score

@baruchiro baruchiro marked this pull request as ready for review April 13, 2023 13:43
@baruchiro baruchiro requested a review from jossef April 18, 2023 08:38
@jossef jossef merged commit 5a77ae4 into master Apr 20, 2023
@jossef jossef deleted the baruchiro/action-menu---create-settings-page branch April 20, 2023 16:27
@baruchiro baruchiro mentioned this pull request Apr 23, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants