1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 09:23:21 +01:00

Refactoring isManifestV3 variable (#15568)

This commit is contained in:
Jyoti Puri 2022-08-16 20:51:42 +05:30 committed by GitHub
parent f008c50bbd
commit eb85fc266d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 10 deletions

View File

@ -100,7 +100,7 @@ const initApp = async (remotePort) => {
log.info('MetaMask initialization complete.');
};
if (isManifestV3()) {
if (isManifestV3) {
browser.runtime.onConnect.addListener(initApp);
} else {
// initialization flow
@ -402,7 +402,7 @@ function setupController(initState, initLangCode, remoteSourcePort) {
//
// connect to other contexts
//
if (isManifestV3() && remoteSourcePort) {
if (isManifestV3 && remoteSourcePort) {
connectRemote(remoteSourcePort);
}
@ -476,7 +476,7 @@ function setupController(initState, initLangCode, remoteSourcePort) {
controller.isClientOpen = true;
controller.setupTrustedCommunication(portStream, remotePort.sender);
if (isManifestV3()) {
if (isManifestV3) {
// Message below if captured by UI code in app/scripts/ui.js which will trigger UI initialisation
// This ensures that UI is initialised only after background is ready
// It fixes the issue of blank screen coming when extension is loaded, the issue is very frequent in MV3
@ -605,7 +605,7 @@ function setupController(initState, initLangCode, remoteSourcePort) {
label = String(count);
}
// browserAction has been replaced by action in MV3
if (isManifestV3()) {
if (isManifestV3) {
browser.action.setBadgeText({ text: label });
browser.action.setBadgeBackgroundColor({ color: '#037DD6' });
} else {

View File

@ -44,7 +44,7 @@ if (
) {
setupPhishingStream();
} else if (shouldInjectProvider()) {
if (!isManifestV3()) {
if (!isManifestV3) {
injectScript(inpageBundle);
}
setupStreams();

View File

@ -35,7 +35,7 @@ const WORKER_KEEP_ALIVE_MESSAGE = 'WORKER_KEEP_ALIVE_MESSAGE';
* if service worker is inactive it is reactivated and script re-loaded
* Time has been kept to 1000ms but can be reduced for even faster re-activation of service worker
*/
if (isManifestV3()) {
if (isManifestV3) {
setInterval(() => {
browser.runtime.sendMessage({ name: WORKER_KEEP_ALIVE_MESSAGE });
}, WORKER_KEEP_ALIVE_INTERVAL);
@ -62,7 +62,7 @@ async function start() {
* In case of MV3 the issue of blank screen was very frequent, it is caused by UI initialising before background is ready to send state.
* Code below ensures that UI is rendered only after background is ready.
*/
if (isManifestV3()) {
if (isManifestV3) {
/*
* In case of MV3 the issue of blank screen was very frequent, it is caused by UI initialising before background is ready to send state.
* Code below ensures that UI is rendered only after CONNECTION_READY message is received thus background is ready.

View File

@ -1,4 +1,4 @@
import browser from 'webextension-polyfill';
export const isManifestV3 = () =>
export const isManifestV3 =
browser.runtime.getManifest().manifest_version === 3;

View File

@ -6,7 +6,9 @@ import { JSDOM } from 'jsdom';
process.env.IN_TEST = true;
global.chrome = { runtime: { id: 'testid' } };
global.chrome = {
runtime: { id: 'testid', getManifest: () => ({ manifest_version: 2 }) },
};
nock.disableNetConnect();
nock.enableNetConnect('localhost');

View File

@ -1,3 +1,3 @@
module.exports = {
runtime: {},
runtime: { getManifest: () => ({ manifest_version: 2 }) },
};