From 742880e8b2e1a12697bfe2c3db87017b1bf28824 Mon Sep 17 00:00:00 2001 From: hollow-owl <71401395+hollow-owl@users.noreply.github.com> Date: Sun, 10 Mar 2024 23:06:47 -0500 Subject: [PATCH 1/2] Fix Mouse back button not doing anything --- packages/app/app/App.js | 24 ++++++++++++++++++++++ packages/main/src/services/window/index.ts | 10 +++++++++ 2 files changed, 34 insertions(+) diff --git a/packages/app/app/App.js b/packages/app/app/App.js index 9dab9c9d5a..e522206d38 100644 --- a/packages/app/app/App.js +++ b/packages/app/app/App.js @@ -48,11 +48,15 @@ import WindowControls from './components/WindowControls'; import SidebarMenuContainer from './containers/SidebarMenuContainer'; import { CommandPaletteContainer } from './containers/CommandPaletteContainer'; import { hot } from 'react-hot-loader'; +import { ipcRenderer } from 'electron'; @withTranslation('app') class App extends React.PureComponent { constructor(props) { super(props); + + this.handleBack = this.handleBack.bind(this); + this.handleForward = this.handleForward.bind(this); } componentDidMount() { @@ -68,6 +72,26 @@ class App extends React.PureComponent { this.updateConnectivityStatus(navigator.onLine); window.addEventListener('online', () => this.updateConnectivityStatus(true)); window.addEventListener('offline', () => this.updateConnectivityStatus(false)); + + ipcRenderer.on('navigate-back', this.handleBack); + ipcRenderer.on('navigate-forward', this.handleForward); + } + + componentWillUnmount() { + ipcRenderer.off('navigate-back', this.handleBack); + ipcRenderer.off('navigate-forward', this.handleForward); + } + + handleBack() { + if (this.props.history.index > 1) { + this.props.history.goBack(); + } + } + + handleForward() { + if (this.props.history.index < (this.props.history.length - 1)) { + this.props.history.goForward(); + } } updateConnectivityStatus = (isConnected) => { diff --git a/packages/main/src/services/window/index.ts b/packages/main/src/services/window/index.ts index 763f0b5f24..7a820c14f4 100644 --- a/packages/main/src/services/window/index.ts +++ b/packages/main/src/services/window/index.ts @@ -79,6 +79,16 @@ class Window { this.browserWindow.once('focus', () => this.browserWindow.flashFrame(false)); } + this.browserWindow.on('app-command', (e, cmd) => { + if (cmd === 'browser-backward') { + this.browserWindow.webContents.send('navigate-back'); + + } + if (cmd === 'browser-forward') { + this.browserWindow.webContents.send('navigate-forward'); + } + }); + this.isReady = new Promise((resolve) => { this.resolve = resolve; }); From f91cfe30c020cdfc9f5995a8c5c00d403d625203 Mon Sep 17 00:00:00 2001 From: hollow-owl <71401395+hollow-owl@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:17:02 -0500 Subject: [PATCH 2/2] Move ipc stuff from App to IpcContainer --- packages/app/app/App.js | 26 +------------------ .../app/app/containers/IpcContainer/index.js | 11 ++++++++ packages/core/src/ipc/events.ts | 6 ++++- packages/main/src/services/window/index.ts | 5 ++-- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/packages/app/app/App.js b/packages/app/app/App.js index e522206d38..b0dc95a25e 100644 --- a/packages/app/app/App.js +++ b/packages/app/app/App.js @@ -48,15 +48,11 @@ import WindowControls from './components/WindowControls'; import SidebarMenuContainer from './containers/SidebarMenuContainer'; import { CommandPaletteContainer } from './containers/CommandPaletteContainer'; import { hot } from 'react-hot-loader'; -import { ipcRenderer } from 'electron'; @withTranslation('app') class App extends React.PureComponent { constructor(props) { super(props); - - this.handleBack = this.handleBack.bind(this); - this.handleForward = this.handleForward.bind(this); } componentDidMount() { @@ -71,27 +67,7 @@ class App extends React.PureComponent { this.updateConnectivityStatus(navigator.onLine); window.addEventListener('online', () => this.updateConnectivityStatus(true)); - window.addEventListener('offline', () => this.updateConnectivityStatus(false)); - - ipcRenderer.on('navigate-back', this.handleBack); - ipcRenderer.on('navigate-forward', this.handleForward); - } - - componentWillUnmount() { - ipcRenderer.off('navigate-back', this.handleBack); - ipcRenderer.off('navigate-forward', this.handleForward); - } - - handleBack() { - if (this.props.history.index > 1) { - this.props.history.goBack(); - } - } - - handleForward() { - if (this.props.history.index < (this.props.history.length - 1)) { - this.props.history.goForward(); - } + window.addEventListener('offline', () => this.updateConnectivityStatus(false)); } updateConnectivityStatus = (isConnected) => { diff --git a/packages/app/app/containers/IpcContainer/index.js b/packages/app/app/containers/IpcContainer/index.js index 1b193e5d1e..f571c73dd2 100644 --- a/packages/app/app/containers/IpcContainer/index.js +++ b/packages/app/app/containers/IpcContainer/index.js @@ -108,6 +108,17 @@ class IpcContainer extends React.Component { } }); + ipcRenderer.on(IpcEvents.NAVIGATE_BACK, () => { + if (this.props.history.index > 1) { + this.props.history.goBack(); + } + }); + ipcRenderer.on(IpcEvents.NAVIGATE_FORWARD, () => { + if (this.props.history.index < (this.props.history.length - 1)) { + this.props.history.goForward(); + } + }); + } componentDidUpdate({ queue: prevQueue }) { diff --git a/packages/core/src/ipc/events.ts b/packages/core/src/ipc/events.ts index a19031bbd9..bf0584363e 100644 --- a/packages/core/src/ipc/events.ts +++ b/packages/core/src/ipc/events.ts @@ -73,7 +73,11 @@ enum IpcEvents { PLAY_STARTUP_TRACK = 'play-startup-track', - ELECTRON_TIMBER_ERROR_EVENT = '__ELECTRON_TIMBER_ERROR__' + ELECTRON_TIMBER_ERROR_EVENT = '__ELECTRON_TIMBER_ERROR__', + + NAVIGATE_BACK = 'navigate-back', + NAVIGATE_FORWARD = 'navigate-forward', + } export default IpcEvents; diff --git a/packages/main/src/services/window/index.ts b/packages/main/src/services/window/index.ts index 7a820c14f4..d2f3806bcc 100644 --- a/packages/main/src/services/window/index.ts +++ b/packages/main/src/services/window/index.ts @@ -9,6 +9,7 @@ import Config from '../config'; import Logger, { $mainLogger, $ipcLogger } from '../logger'; import Platform from '../platform'; import Store from '../store'; +import { IpcEvents } from '@nuclear/core'; const urlMapper: Record = { [Env.DEV]: url.format({ @@ -81,11 +82,11 @@ class Window { this.browserWindow.on('app-command', (e, cmd) => { if (cmd === 'browser-backward') { - this.browserWindow.webContents.send('navigate-back'); + this.browserWindow.webContents.send(IpcEvents.NAVIGATE_BACK); } if (cmd === 'browser-forward') { - this.browserWindow.webContents.send('navigate-forward'); + this.browserWindow.webContents.send(IpcEvents.NAVIGATE_FORWARD); } });