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

added altair-crx #2757

Merged
merged 6 commits into from
Feb 2, 2025
Merged

added altair-crx #2757

merged 6 commits into from
Feb 2, 2025

Conversation

imolorhe
Copy link
Collaborator

@imolorhe imolorhe commented Jan 27, 2025

Fixes

Fixes #2504

Checks

  • Ran yarn test-build
  • Updated relevant documentations
  • Updated matching config options in altair-static
  • Test in chrome
  • Test in firefox
  • Extension altair app
  • Extension options
  • CI builds

Changes proposed in this pull request:

Summary by Sourcery

Add Altair Chrome extension.

New Features:

  • Added a new Chrome extension for Altair.

Tests:

  • Updated tests to include the Chrome extension.

Copy link

sourcery-ai bot commented Jan 27, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new package, altair-crx, for the Altair GraphQL Client Chrome extension. It also updates the altair-static package to support serving initial options in a separate request.

Class diagram for RenderOptions changes

classDiagram
    class RenderOptions {
        +boolean|string serveInitialOptionsInSeperateRequest
        +string baseURL
    }

    class AltairStatic {
        +renderAltair(options: RenderOptions)
        +renderInitialOptions(options: RenderOptions)
        +renderInitSnippet(options: RenderOptions)
    }

    RenderOptions -- AltairStatic
Loading

File-Level Changes

Change Details Files
Added altair-crx package
  • Added dependencies for react, react-dom, and @crxjs/vite-plugin.
  • Added devDependencies for @types/chrome, @types/react, @types/react-dom, @vitejs/plugin-react, recursive-copy, rimraf, typescript, vite, vite-plugin-static-copy, and web-ext.
pnpm-lock.yaml
Updated altair-static package to support serving initial options in a separate request
  • Added a new option serveInitialOptionsInSeperateRequest to the RenderOptions interface.
  • Modified renderAltair function to handle the new option, serving initial options in a separate js file.
  • Added a new function renderInitSnippet to render the Altair init JS snippet.
packages/altair-static/src/index.ts
Added background script for the chrome extension
  • Added a background script to handle extension lifecycle events.
  • Added logic to open the extension in a new tab or focus on an existing tab.
  • Added logic to show a notification on extension update.
packages/altair-crx/public/js/background.js
packages/altair-crx/src/background.ts
Added manifest configuration for the chrome extension
  • Added a manifest configuration file for the chrome extension.
  • Configured permissions, background scripts, options UI, and content security policy.
packages/altair-crx/manifest.config.ts
Added donation page for the chrome extension
  • Added a donation page for the chrome extension.
  • Added logic to handle donation via Chrome In-App Payments.
packages/altair-crx/public/donate.html
packages/altair-crx/public/js/donate.js
packages/altair-crx/public/js/buy.js
Added options page for the chrome extension
  • Added an options page for the chrome extension.
  • Added logic to save and restore options.
packages/altair-crx/public/js/options.js
packages/altair-crx/public/options.html
packages/altair-crx/src/options.html
Added a basic react app for the chrome extension
  • Added a basic react app for the chrome extension.
  • Configured vite for the react app.
  • Added a basic index.html file.
packages/altair-crx/src/App.tsx
packages/altair-crx/src/App.css
packages/altair-crx/vite.config.ts
packages/altair-crx/src/vite-env.d.ts
packages/altair-crx/.gitignore
packages/altair-crx/src/favicon.svg
packages/altair-crx/src/logo.svg
packages/altair-crx/src/main.tsx
packages/altair-crx/tsconfig.json
packages/altair-crx/tsconfig.node.json
packages/altair-crx/indexold.html
packages/altair-crx/src/index.css
Added init script for the chrome extension
  • Added an init script to initialize Altair after the assets have been added.
packages/altair-crx/public/js/init.js
Added prebuild script for the chrome extension
  • Added a prebuild script to copy the altair app and generate the index.html file.
packages/altair-crx/bin/prebuild.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @imolorhe - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider removing commented out code blocks in vite.config.ts and background.ts to keep the codebase cleaner
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 20 to 30
function createNewTab() {
chrome.tabs.create({ url: 'index.html' }, function(tab) {
curTab = {
id: tab.id,
url: tab.url,
};

// Handle donation logic
// handleDonation();
});
}
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

Comment on lines 33 to 36
function focusTab(tabId) {
const updateProperties = { active: true };
chrome.tabs.update(tabId, updateProperties, function(tab) {});
}
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

Comment on lines 38 to 58
function openChangeLog() {
chrome.storage.sync.get(
{
showChangeLog: true,
},
function(items) {
if (items.showChangeLog) {
chrome.tabs.create(
{
url: 'https://altairgraphql.dev/updated',
},
function(tab) {
console.log(
'New tab launched with https://altairgraphql.dev/updated'
);
}
);
}
}
);
}
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

Comment on lines 60 to 88
function handleDonation() {
if (!chrome.runtime.getBrowserInfo) {
// FIXME: A chrome extension
chrome.storage.sync.get(
{
userDonated: false,
extLoadCount: 0,
},
function(items) {
if (!items.userDonated) {
console.log('extension loaded count: ', items.extLoadCount);
if (items.extLoadCount > MAX_EXT_LOAD_COUNT) {
// show donation page
chrome.tabs.create({ url: 'donate.html' }, function(tab) {
console.log('New tab launched with donation.');
});
chrome.storage.sync.set({
extLoadCount: 0,
});
} else {
chrome.storage.sync.set({
extLoadCount: items.extLoadCount + 1,
});
}
}
}
);
}
}
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

@@ -0,0 +1,2 @@
(function() { var f=this,g=function(a,d){var c=a.split("."),b=window||f;c[0]in b||!b.execScript||b.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)c.length||void 0===d?b=b[e]?b[e]:b[e]={}:b[e]=d};var h=function(a){var d=chrome.runtime.connect("nmmhkkegccagdldgiimedpiccmgmieda",{}),c=!1;d.onMessage.addListener(function(b){c=!0;"response"in b&&!("errorType"in b.response)?a.success&&a.success(b):a.failure&&a.failure(b)});d.onDisconnect.addListener(function(){!c&&a.failure&&a.failure({request:{},response:{errorType:"INTERNAL_SERVER_ERROR"}})});d.postMessage(a)};g("google.payments.inapp.buy",function(a){a.method="buy";h(a)});
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Use const or let instead of var. (avoid-using-var)

Explanation`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.

From the Airbnb JavaScript Style Guide


function onPurchase(purchase) {
console.log('onPurchase', purchase);
const orderId = purchase.response.orderId;
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
const orderId = purchase.response.orderId;
const {orderId} = purchase.response;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

Comment on lines 23 to 27
function onPurchaseFailed(purchase) {
console.log('onPurchaseFailed', purchase);
var reason = purchase.response.errorType;
resultSection.innerHTML = 'Donation failed. ' + reason;
}
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.


function onPurchaseFailed(purchase) {
console.log('onPurchaseFailed', purchase);
var reason = purchase.response.errorType;
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Use const or let instead of var. (avoid-using-var)

Explanation`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.

From the Airbnb JavaScript Style Guide

@@ -0,0 +1,28 @@
// Saves options to chrome.storage
function save_options() {
var showChangeLog = document.getElementById('show_changelog').checked;
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Use const or let instead of var. (avoid-using-var)

Explanation`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.

From the Airbnb JavaScript Style Guide

showChangeLog: showChangeLog
}, function () {
// Update status to let user know options were saved.
var status = document.getElementById('status');
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Use const or let instead of var. (avoid-using-var)

Explanation`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code). `let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than function-scoped.

From the Airbnb JavaScript Style Guide

Copy link

github-actions bot commented Jan 27, 2025

Visit the preview URL for this PR (updated for commit 9fa9898):

https://altair-gql--pr2757-imolorhe-browser-ext-x42bdg23.web.app

(expires Wed, 05 Feb 2025 07:19:02 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 02d6323d75a99e532a38922862e269d63351a6cf

@imolorhe imolorhe added this pull request to the merge queue Feb 2, 2025
Merged via the queue into master with commit 9653ea3 Feb 2, 2025
13 checks passed
@imolorhe imolorhe deleted the imolorhe/browser-extension-mv3 branch February 2, 2025 18:55
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.

Migrate chrome extension to mv3
1 participant