-
Notifications
You must be signed in to change notification settings - Fork 2
/
extensions.js
72 lines (60 loc) · 2.5 KB
/
extensions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const fs = require('fs');
const path = require('path');
const { ipcMain, BrowserWindow } = require('electron');
const METAMASK_ID = 'nkbihfbeogaeaoehlefnkodbefgpgknn';
const METAMASK_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlcgI4VVL4JUvo6hlSgeCZp9mGltZrzFvc2Asqzb1dDGO9baoYOe+QRoh27/YyVXugxni480Q/R147INhBOyQZVMhZOD5pFMVutia9MHMaZhgRXzrK3BHtNSkKLL1c5mhutQNwiLqLtFkMSGvka91LoMEC8WTI0wi4tACnJ5FyFZQYzvtqy5sXo3VS3gzfOBluLKi7BxYcaUJjNrhOIxl1xL2qgK5lDrDOLKcbaurDiwqofVtAFOL5sM3uJ6D8nOO9tG+T7hoobRFN+nxk43PHgCv4poicOv+NMZQEk3da1m/xfuzXV88NcE/YRbRLwAS82m3gsJZKc6mLqm4wZHzBwIDAQAB';
const getMetamaskPath = (isDev) => {
if (isDev) {
return path.join(__dirname,`extensions/metamask/`);
}
return path.resolve(__dirname,`../../app.asar.unpacked/dist/extensions/metamask/`);
};
const loadMetamaskFromManifest = (session, metamaskPath) => {
fs.readFile(`${metamaskPath}/manifest.json`, 'utf8', function (err, data) {
if (err) throw err;
manifest = JSON.parse(data);
manifest.content_scripts[0].matches = ['chrome://brave/**/*'];
manifest.key = METAMASK_KEY;
session.defaultSession.extensions.load(metamaskPath, manifest, 'component');
});
};
const loadMetamask = (session, window, isDev) => {
let manifest;
let metamaskPopup;
let metamaskNotification;
let mainWindow = window;
const metamaskPath = getMetamaskPath(isDev);
loadMetamaskFromManifest(session, metamaskPath);
ipcMain.on('open-metamask-popup', (event, arg) => {
if(metamaskPopup && !metamaskPopup.isDestroyed()) metamaskPopup.close();
metamaskPopup = new BrowserWindow({
title: 'MetaMask',
width: 360,
height: 520,
type: 'popup',
resizable: false
});
metamaskPopup.loadURL(`chrome-extension://${METAMASK_ID}/popup.html`);
});
ipcMain.on('open-metamask-notification', (event, arg) => {
if(metamaskNotification && !metamaskNotification.isDestroyed()) metamaskNotification.close();
metamaskNotification = new BrowserWindow({
title: 'MetaMask',
width: 360,
height: 520,
type: 'popup',
resizable: false
});
metamaskNotification.loadURL(`chrome-extension://${METAMASK_ID}/notification.html`);
});
ipcMain.on('close-metamask-notification', (event, arg) => {
if(metamaskPopup && !metamaskPopup.isDestroyed()) metamaskPopup.close();
});
ipcMain.on('reload-metamask', (event, arg) => {
loadMetamaskFromManifest(session, metamaskPath);
session.defaultSession.extensions.enable(METAMASK_ID)
});
};
module.exports = {
loadMetamask
};