mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-21 17:37:01 +01:00
Refactoring isManifestV3 variable (#15568)
This commit is contained in:
parent
f008c50bbd
commit
eb85fc266d
@ -100,7 +100,7 @@ const initApp = async (remotePort) => {
|
|||||||
log.info('MetaMask initialization complete.');
|
log.info('MetaMask initialization complete.');
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isManifestV3()) {
|
if (isManifestV3) {
|
||||||
browser.runtime.onConnect.addListener(initApp);
|
browser.runtime.onConnect.addListener(initApp);
|
||||||
} else {
|
} else {
|
||||||
// initialization flow
|
// initialization flow
|
||||||
@ -402,7 +402,7 @@ function setupController(initState, initLangCode, remoteSourcePort) {
|
|||||||
//
|
//
|
||||||
// connect to other contexts
|
// connect to other contexts
|
||||||
//
|
//
|
||||||
if (isManifestV3() && remoteSourcePort) {
|
if (isManifestV3 && remoteSourcePort) {
|
||||||
connectRemote(remoteSourcePort);
|
connectRemote(remoteSourcePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,7 +476,7 @@ function setupController(initState, initLangCode, remoteSourcePort) {
|
|||||||
controller.isClientOpen = true;
|
controller.isClientOpen = true;
|
||||||
controller.setupTrustedCommunication(portStream, remotePort.sender);
|
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
|
// 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
|
// 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
|
// 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);
|
label = String(count);
|
||||||
}
|
}
|
||||||
// browserAction has been replaced by action in MV3
|
// browserAction has been replaced by action in MV3
|
||||||
if (isManifestV3()) {
|
if (isManifestV3) {
|
||||||
browser.action.setBadgeText({ text: label });
|
browser.action.setBadgeText({ text: label });
|
||||||
browser.action.setBadgeBackgroundColor({ color: '#037DD6' });
|
browser.action.setBadgeBackgroundColor({ color: '#037DD6' });
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,7 +44,7 @@ if (
|
|||||||
) {
|
) {
|
||||||
setupPhishingStream();
|
setupPhishingStream();
|
||||||
} else if (shouldInjectProvider()) {
|
} else if (shouldInjectProvider()) {
|
||||||
if (!isManifestV3()) {
|
if (!isManifestV3) {
|
||||||
injectScript(inpageBundle);
|
injectScript(inpageBundle);
|
||||||
}
|
}
|
||||||
setupStreams();
|
setupStreams();
|
||||||
|
@ -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
|
* 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
|
* Time has been kept to 1000ms but can be reduced for even faster re-activation of service worker
|
||||||
*/
|
*/
|
||||||
if (isManifestV3()) {
|
if (isManifestV3) {
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
browser.runtime.sendMessage({ name: WORKER_KEEP_ALIVE_MESSAGE });
|
browser.runtime.sendMessage({ name: WORKER_KEEP_ALIVE_MESSAGE });
|
||||||
}, WORKER_KEEP_ALIVE_INTERVAL);
|
}, 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.
|
* 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.
|
* 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.
|
* 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.
|
* Code below ensures that UI is rendered only after CONNECTION_READY message is received thus background is ready.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
|
|
||||||
export const isManifestV3 = () =>
|
export const isManifestV3 =
|
||||||
browser.runtime.getManifest().manifest_version === 3;
|
browser.runtime.getManifest().manifest_version === 3;
|
||||||
|
@ -6,7 +6,9 @@ import { JSDOM } from 'jsdom';
|
|||||||
|
|
||||||
process.env.IN_TEST = true;
|
process.env.IN_TEST = true;
|
||||||
|
|
||||||
global.chrome = { runtime: { id: 'testid' } };
|
global.chrome = {
|
||||||
|
runtime: { id: 'testid', getManifest: () => ({ manifest_version: 2 }) },
|
||||||
|
};
|
||||||
|
|
||||||
nock.disableNetConnect();
|
nock.disableNetConnect();
|
||||||
nock.enableNetConnect('localhost');
|
nock.enableNetConnect('localhost');
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
runtime: {},
|
runtime: { getManifest: () => ({ manifest_version: 2 }) },
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user