diff --git a/src/browser/components/MainPage.jsx b/src/browser/components/MainPage.jsx index 304c24b9..f9e50451 100644 --- a/src/browser/components/MainPage.jsx +++ b/src/browser/components/MainPage.jsx @@ -76,6 +76,17 @@ export default class MainPage extends React.Component { } getTabWebContents(index = this.state.key || 0, teams = this.props.teams) { + const allWebContents = remote.webContents.getAllWebContents(); + const openDevTools = allWebContents.find((webContents) => webContents.getURL().includes('chrome-devtools') && webContents.isFocused()); + if (openDevTools) { + return openDevTools; + } + + if (this.state.showNewTeamModal) { + const indexURL = '/browser/index.html'; + return allWebContents.find((webContents) => webContents.getURL().includes(indexURL)); + } + if (!teams || !teams.length || index > teams.length) { return null; } @@ -83,7 +94,7 @@ export default class MainPage extends React.Component { if (!tabURL) { return null; } - return remote.webContents.getAllWebContents().find((webContents) => webContents.getURL().includes(tabURL)); + return allWebContents.find((webContents) => webContents.getURL().includes(tabURL) || webContents.getURL().includes(this.refs[`mattermostView${index}`].getSrc())); } componentDidMount() { diff --git a/src/browser/components/SettingsPage.jsx b/src/browser/components/SettingsPage.jsx index f76cc77f..a6977d9b 100644 --- a/src/browser/components/SettingsPage.jsx +++ b/src/browser/components/SettingsPage.jsx @@ -38,6 +38,10 @@ export default class SettingsPage extends React.Component { this.saveQueue = []; } + getTabWebContents() { + return remote.webContents.getFocusedWebContents(); + } + componentDidMount() { config.on('update', (configData) => { this.updateSaveState(); @@ -75,6 +79,84 @@ export default class SettingsPage extends React.Component { ipcRenderer.on('switch-tab', (event, key) => { backToIndex(key); }); + + ipcRenderer.on('zoom-in', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + if (activeTabWebContents.getZoomLevel() >= 9) { + return; + } + activeTabWebContents.setZoomLevel(activeTabWebContents.getZoomLevel() + 1); + }); + + ipcRenderer.on('zoom-out', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + if (activeTabWebContents.getZoomLevel() <= -8) { + return; + } + activeTabWebContents.setZoomLevel(activeTabWebContents.getZoomLevel() - 1); + }); + + ipcRenderer.on('zoom-reset', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.setZoomLevel(0); + }); + + ipcRenderer.on('undo', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.undo(); + }); + + ipcRenderer.on('redo', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.redo(); + }); + + ipcRenderer.on('cut', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.cut(); + }); + + ipcRenderer.on('copy', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.copy(); + }); + + ipcRenderer.on('paste', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.paste(); + }); + + ipcRenderer.on('paste-and-match', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.pasteAndMatchStyle(); + }); } convertConfigDataToState = (configData, currentState = {}) => { diff --git a/src/browser/updater.jsx b/src/browser/updater.jsx index 3503305c..356b7faa 100644 --- a/src/browser/updater.jsx +++ b/src/browser/updater.jsx @@ -19,6 +19,10 @@ class UpdaterPageContainer extends React.Component { this.state = props.initialState; } + getTabWebContents() { + return remote.webContents.getFocusedWebContents(); + } + componentDidMount() { ipcRenderer.on('start-download', () => { this.setState({ @@ -30,6 +34,83 @@ class UpdaterPageContainer extends React.Component { progress, }); }); + ipcRenderer.on('zoom-in', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + if (activeTabWebContents.getZoomLevel() >= 9) { + return; + } + activeTabWebContents.setZoomLevel(activeTabWebContents.getZoomLevel() + 1); + }); + + ipcRenderer.on('zoom-out', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + if (activeTabWebContents.getZoomLevel() <= -8) { + return; + } + activeTabWebContents.setZoomLevel(activeTabWebContents.getZoomLevel() - 1); + }); + + ipcRenderer.on('zoom-reset', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.setZoomLevel(0); + }); + + ipcRenderer.on('undo', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.undo(); + }); + + ipcRenderer.on('redo', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.redo(); + }); + + ipcRenderer.on('cut', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.cut(); + }); + + ipcRenderer.on('copy', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.copy(); + }); + + ipcRenderer.on('paste', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.paste(); + }); + + ipcRenderer.on('paste-and-match', () => { + const activeTabWebContents = this.getTabWebContents(); + if (!activeTabWebContents) { + return; + } + activeTabWebContents.pasteAndMatchStyle(); + }); } render() {