MyCrypto/electron-app/main/window.ts

88 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

import { BrowserWindow, Menu, shell } from 'electron';
import { URL } from 'url';
Electron Ledger + Trezor Support (#1836) * Initial scaffold of enclave * Cleanup types * Add comments * Do not truncate errors, pretty output * Introduce helpers for sagas * Update yarn lock * Convert enclave into its own lib. Implement client and server. * Check in progress * Initial types * Remove unused lib * Finish types * cleanup * Switch over to using electron protocol, remove code thats no longer necessary * Refactor Ledger and Trezor wallets to provide all functionality via libs. Run chain code generation thru Enclave. * Check in trezor work * Transaction signing * Message signing * Display address * Fix deallocation of trezor * Adjust API * Remove unused getAddresses * Fix imports and filenames to cooperate with internal typings * Fix type uncertainty * Add persistent message to Ledger unlock. * Update ledger help link to kb * Convert ledger over to updated libs * Fix jest config * Enclave README * Unnecessary assertion * Adjust tip * Type ledger errors * Reduce enclave client code. * No default exports * l18n user facing enclave errors * Reduce repeated enclave code by splitting it into its own wallet lib. Fix some types * tslint * Reduce repeated enclave code by splitting it into its own wallet lib. Fix some types and error messages. * Electron TREZOR Support (#1946) * Type trezor connect. * Check in trezor code * Implement TREZOR wallet * Convert TREZOR to use enclave class like Ledger. * Switch to mycrypto fork of trezor lib. Remove unused dependencies. * remove unnecessary window attachment * tslint
2018-06-15 23:25:29 +00:00
import path from 'path';
import MENU from './menu';
import popupContextMenu from './contextMenu';
import { APP_TITLE } from '../constants';
const isDevelopment = process.env.NODE_ENV !== 'production';
// Cached reference, preventing recreations
let window: BrowserWindow | null;
// Construct new BrowserWindow
export default function getWindow() {
if (window) {
return window;
}
window = new BrowserWindow({
title: APP_TITLE,
backgroundColor: '#fbfbfb',
width: 1220,
height: process.platform === 'darwin' ? 680 : 720,
minWidth: 480,
minHeight: 400,
titleBarStyle: 'hidden',
webPreferences: {
devTools: true,
nodeIntegration: false,
Electron Ledger + Trezor Support (#1836) * Initial scaffold of enclave * Cleanup types * Add comments * Do not truncate errors, pretty output * Introduce helpers for sagas * Update yarn lock * Convert enclave into its own lib. Implement client and server. * Check in progress * Initial types * Remove unused lib * Finish types * cleanup * Switch over to using electron protocol, remove code thats no longer necessary * Refactor Ledger and Trezor wallets to provide all functionality via libs. Run chain code generation thru Enclave. * Check in trezor work * Transaction signing * Message signing * Display address * Fix deallocation of trezor * Adjust API * Remove unused getAddresses * Fix imports and filenames to cooperate with internal typings * Fix type uncertainty * Add persistent message to Ledger unlock. * Update ledger help link to kb * Convert ledger over to updated libs * Fix jest config * Enclave README * Unnecessary assertion * Adjust tip * Type ledger errors * Reduce enclave client code. * No default exports * l18n user facing enclave errors * Reduce repeated enclave code by splitting it into its own wallet lib. Fix some types * tslint * Reduce repeated enclave code by splitting it into its own wallet lib. Fix some types and error messages. * Electron TREZOR Support (#1946) * Type trezor connect. * Check in trezor code * Implement TREZOR wallet * Convert TREZOR to use enclave class like Ledger. * Switch to mycrypto fork of trezor lib. Remove unused dependencies. * remove unnecessary window attachment * tslint
2018-06-15 23:25:29 +00:00
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
}
});
const appUrl = isDevelopment ? `http://localhost:3000` : `file://${__dirname}/index.html`;
window.loadURL(appUrl);
window.on('closed', () => {
window = null;
});
window.webContents.on('new-window', (ev: any, urlStr: string) => {
// Kill all new window requests by default
ev.preventDefault();
// Only allow HTTPS urls to actually be opened
const url = new URL(urlStr);
if (url.protocol === 'https:') {
shell.openExternal(urlStr);
} else {
console.warn(`Blocked request to open new window '${urlStr}', only HTTPS links are allowed`);
}
});
window.webContents.on('context-menu', (_, props) => {
popupContextMenu(window!, isDevelopment, props);
});
// TODO: Figure out updater release process
// window.webContents.on('did-finish-load', () => {
// updater(window!);
// });
window.webContents.on('devtools-opened', () => {
window!.focus();
setImmediate(() => {
window!.focus();
});
});
window.webContents.on('will-navigate', (event: any) => {
event.preventDefault();
});
if (isDevelopment) {
window.webContents.on('did-fail-load', () => {
setTimeout(() => {
if (window && window.webContents) {
window.webContents.reload();
}
}, 500);
});
}
Menu.setApplicationMenu(Menu.buildFromTemplate(MENU));
return window;
}