customProtocols.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { protocol } = require('electron');
  2. protocol.registerHttpProtocol(
  3. 'mist',
  4. (request, callback) => {
  5. // callback({mimeType: 'text/html', data: new Buffer('<h5>Response</h5>')});
  6. console.log(
  7. request.url.indexOf('mist://interface') !== -1
  8. ? global.interfaceAppUrl + request.url.replace('mist://interface', '')
  9. : ''
  10. );
  11. const call = {
  12. url:
  13. request.url.indexOf('mist://interface') !== -1
  14. ? global.interfaceAppUrl + request.url.replace('mist://interface', '')
  15. : '', // 'http://localhost:3050/' + request.url.replace('mist://',''),
  16. method: request.method,
  17. referrer: request.referrer
  18. };
  19. console.log(call);
  20. // console.log(call);
  21. callback(call);
  22. },
  23. error => {
  24. if (error) {
  25. console.error('Failed to register protocol');
  26. }
  27. }
  28. );
  29. // protocol.registerProtocol('eth', function(request) {
  30. // var url = request.url.substr(7)
  31. // return new protocol.RequestStringJob({data: 'Hello'});
  32. // });
  33. // protocol.registerProtocol('bzz', function(request) {
  34. // var url = request.url.substr(7)
  35. // return new protocol.RequestStringJob({data: 'Hello'});
  36. // });
  37. // protocol.registerStandardSchemes(['mist','eth', 'bzz']); //'eth', 'bzz'