Page MenuHomePhabricator

D5630.id18636.diff
No OneTemporary

D5630.id18636.diff

diff --git a/desktop/main.cjs b/desktop/main.cjs
--- a/desktop/main.cjs
+++ b/desktop/main.cjs
@@ -1,4 +1,4 @@
-const { app, BrowserWindow, shell, Menu } = require('electron');
+const { app, BrowserWindow, shell, Menu, ipcMain } = require('electron');
const fs = require('fs');
const path = require('path');
@@ -79,6 +79,21 @@
titleBarStyle: 'hidden',
trafficLightPosition: { x: 20, y: 24 },
backgroundColor: '#0A0A0A',
+ webPreferences: {
+ preload: path.join(__dirname, 'preload.cjs'),
+ },
+ });
+
+ const updateNavigationState = () => {
+ win.webContents.send('on-navigate', {
+ canGoBack: win.webContents.canGoBack(),
+ canGoForward: win.webContents.canGoForward(),
+ });
+ };
+ win.webContents.on('did-navigate-in-page', updateNavigationState);
+ ipcMain.on('clear-history', () => {
+ win.webContents.clearHistory();
+ updateNavigationState();
});
win.webContents.setWindowOpenHandler(({ url: openURL }) => {
diff --git a/desktop/preload.cjs b/desktop/preload.cjs
new file mode 100644
--- /dev/null
+++ b/desktop/preload.cjs
@@ -0,0 +1,12 @@
+const { contextBridge, ipcRenderer } = require('electron');
+
+const bridge = {
+ onNavigate: callback => {
+ const withEvent = (event, ...args) => callback(...args);
+ ipcRenderer.on('on-navigate', withEvent);
+ return () => ipcRenderer.removeListener('on-navigate', withEvent);
+ },
+ clearHistory: () => ipcRenderer.send('clear-history'),
+};
+
+contextBridge.exposeInMainWorld('electronContextBridge', bridge);
diff --git a/web/app.react.js b/web/app.react.js
--- a/web/app.react.js
+++ b/web/app.react.js
@@ -32,6 +32,7 @@
import Chat from './chat/chat.react';
import { TooltipProvider } from './chat/tooltip-provider';
import NavigationArrows from './components/navigation-arrows.react';
+import electron from './electron';
import InputStateContainer from './input/input-state-container.react';
import LoadingIndicator from './loading-indicator.react';
import { MenuProvider } from './menu-provider.react';
@@ -127,6 +128,9 @@
history.replace(newURL);
}
}
+ if (loggedIn !== prevProps.loggedIn) {
+ electron?.clearHistory();
+ }
}
onWordmarkClicked = () => {
@@ -175,9 +179,8 @@
}
}
- const shouldShowNavigationArrows = false;
let navigationArrows = null;
- if (shouldShowNavigationArrows) {
+ if (electron) {
navigationArrows = <NavigationArrows />;
}
diff --git a/web/components/navigation-arrows.css b/web/components/navigation-arrows.css
--- a/web/components/navigation-arrows.css
+++ b/web/components/navigation-arrows.css
@@ -8,3 +8,8 @@
display: flex;
align-items: center;
}
+
+.disabled {
+ pointer-events: none;
+ color: var(--color-disabled);
+}
diff --git a/web/components/navigation-arrows.react.js b/web/components/navigation-arrows.react.js
--- a/web/components/navigation-arrows.react.js
+++ b/web/components/navigation-arrows.react.js
@@ -1,7 +1,9 @@
// @flow
+import classnames from 'classnames';
import * as React from 'react';
+import electron from '../electron.js';
import history from '../router-history.js';
import SWMansionIcon from '../SWMansionIcon.react.js';
import css from './navigation-arrows.css';
@@ -16,12 +18,29 @@
[],
);
+ const [disableBack, setDisableBack] = React.useState(false);
+ const [disableFoward, setDisableForward] = React.useState(false);
+
+ React.useEffect(
+ () =>
+ electron?.onNavigate(({ canGoBack, canGoForward }) => {
+ setDisableBack(!canGoBack);
+ setDisableForward(!canGoForward);
+ }),
+ [],
+ );
+
+ const goBackClasses = classnames(css.button, { [css.disabled]: disableBack });
+ const goForwardClasses = classnames(css.button, {
+ [css.disabled]: disableFoward,
+ });
+
return (
<div className={css.container}>
- <a className={css.button} onClick={goBack}>
+ <a className={goBackClasses} onClick={goBack}>
<SWMansionIcon icon="arrow-left" size={24} />
</a>
- <a className={css.button} onClick={goForward}>
+ <a className={goForwardClasses} onClick={goForward}>
<SWMansionIcon icon="arrow-right" size={24} />
</a>
</div>
diff --git a/web/electron.js b/web/electron.js
new file mode 100644
--- /dev/null
+++ b/web/electron.js
@@ -0,0 +1,16 @@
+// @flow
+
+declare var electronContextBridge;
+
+type OnNavigateListener = ({
+ +canGoBack: boolean,
+ +canGoForward: boolean,
+}) => void;
+
+const electron: null | {
+ // Returns a callback that you can call to remove the listener
+ +onNavigate: OnNavigateListener => () => void,
+ +clearHistory: () => void,
+} = typeof electronContextBridge === 'undefined' ? null : electronContextBridge;
+
+export default electron;

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 7:58 AM (8 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2682634
Default Alt Text
D5630.id18636.diff (4 KB)

Event Timeline