diff options
| -rw-r--r-- | gui/package-lock.json | 14 | ||||
| -rw-r--r-- | gui/package.json | 2 | ||||
| -rw-r--r-- | gui/src/main/ipc-event-channel.ts | 6 | ||||
| -rw-r--r-- | gui/src/renderer/components/AppButton.tsx | 5 | ||||
| -rw-r--r-- | gui/src/renderer/components/ScopeBar.tsx | 2 | ||||
| -rw-r--r-- | gui/src/renderer/context.tsx | 25 | ||||
| -rw-r--r-- | gui/src/shared/ipc-helpers.ts | 4 |
7 files changed, 27 insertions, 31 deletions
diff --git a/gui/package-lock.json b/gui/package-lock.json index f6dbdede16..7cb9754e59 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -75,7 +75,7 @@ "sinon": "^14.0.1", "ts-node": "^10.9.1", "tsc-watch": "^5.0.3", - "typescript": "^4.5.4", + "typescript": "^4.8.4", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0", "xvfb-maybe": "^0.2.1" @@ -13239,9 +13239,9 @@ } }, "node_modules/typescript": { - "version": "4.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", - "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -24728,9 +24728,9 @@ } }, "typescript": { - "version": "4.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", - "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", "dev": true }, "uglify-js": { diff --git a/gui/package.json b/gui/package.json index dbe74b2f0f..6f60512e39 100644 --- a/gui/package.json +++ b/gui/package.json @@ -81,7 +81,7 @@ "sinon": "^14.0.1", "ts-node": "^10.9.1", "tsc-watch": "^5.0.3", - "typescript": "^4.5.4", + "typescript": "^4.8.4", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0", "xvfb-maybe": "^0.2.1" diff --git a/gui/src/main/ipc-event-channel.ts b/gui/src/main/ipc-event-channel.ts index d189634950..bae499910d 100644 --- a/gui/src/main/ipc-event-channel.ts +++ b/gui/src/main/ipc-event-channel.ts @@ -1,14 +1,14 @@ import { ipcMain, WebContents } from 'electron'; -import { createIpcMain, IpcMain, Schema } from '../shared/ipc-helpers'; +import { createIpcMain, IpcMain, Notifier, Schema } from '../shared/ipc-helpers'; import { ipcSchema } from '../shared/ipc-schema'; // Type where the notify functions have been replaced with either `undefined` if no `WebContents` is // available, or with the function curried with the `WebContents`. type IpcMainBootstrappedWithWebContents<S extends Schema> = { [GK in keyof IpcMain<S>]: { - [CK in keyof IpcMain<S>[GK]]: CK extends `notify${string}` - ? undefined | ((arg: Parameters<IpcMain<S>[GK][CK]>[1]) => ReturnType<IpcMain<S>[GK][CK]>) + [CK in keyof IpcMain<S>[GK]]: IpcMain<S>[GK][CK] extends Notifier<infer T> + ? undefined | ((arg: T) => ReturnType<IpcMain<S>[GK][CK]>) : IpcMain<S>[GK][CK]; }; }; diff --git a/gui/src/renderer/components/AppButton.tsx b/gui/src/renderer/components/AppButton.tsx index a3edc78ad3..45c93e1b2a 100644 --- a/gui/src/renderer/components/AppButton.tsx +++ b/gui/src/renderer/components/AppButton.tsx @@ -54,7 +54,10 @@ const BaseButton = React.memo(function BaseButtonT(props: IProps) { if (groups.label === undefined && typeof child === 'string') { return { ...groups, label: <Label textOffset={textOffset}>{child}</Label> }; } else if (React.isValidElement(child) && child.type === Label) { - return { ...groups, label: React.cloneElement(child, { textOffset }) }; + return { + ...groups, + label: React.cloneElement(child as React.ReactElement<ILabelProps>, { textOffset }), + }; } else if (groups.label === undefined) { return { ...groups, left: [...groups.left, child] }; } else { diff --git a/gui/src/renderer/components/ScopeBar.tsx b/gui/src/renderer/components/ScopeBar.tsx index be5420b0b5..10b177c2c3 100644 --- a/gui/src/renderer/components/ScopeBar.tsx +++ b/gui/src/renderer/components/ScopeBar.tsx @@ -16,7 +16,7 @@ interface IScopeBarProps { defaultSelectedIndex?: number; onChange?: (selectedIndex: number) => void; className?: string; - children: React.ReactNode; + children: React.ReactElement<IScopeBarItemProps>[]; } export function ScopeBar(props: IScopeBarProps) { diff --git a/gui/src/renderer/context.tsx b/gui/src/renderer/context.tsx index 0867618136..3b5fcc14fb 100644 --- a/gui/src/renderer/context.tsx +++ b/gui/src/renderer/context.tsx @@ -15,24 +15,15 @@ const missingContextError = new Error( 'The context value is empty. Make sure to wrap the component in AppContext.Provider.', ); -export default function withAppContext<Props>(BaseComponent: React.ComponentType<Props>) { - // Exclude the IAppContext from props since those are injected props - const wrappedComponent = (props: Omit<Props, keyof IAppContext>) => { - return ( - <AppContext.Consumer> - {(context) => { - if (context) { - // Enforce type because Typescript does not recognize that - // (Props ~ IAppContext & IAppContext) is identical to Props. - const mergedProps = ({ ...props, ...context } as unknown) as Props; +type PropsWithoutAppContext<Props> = Omit<Props, 'app'>; - return <BaseComponent {...mergedProps} />; - } else { - throw missingContextError; - } - }} - </AppContext.Consumer> - ); +export default function withAppContext<Props>( + BaseComponent: React.ComponentType<PropsWithoutAppContext<Props> & IAppContext>, +) { + // Exclude the IAppContext from props since those are injected props + const wrappedComponent = (props: PropsWithoutAppContext<Props>) => { + const appContext = useAppContext(); + return <BaseComponent app={appContext} {...props} />; }; if (window.env.development) { diff --git a/gui/src/shared/ipc-helpers.ts b/gui/src/shared/ipc-helpers.ts index 1680b45d11..fda5c2d3b5 100644 --- a/gui/src/shared/ipc-helpers.ts +++ b/gui/src/shared/ipc-helpers.ts @@ -5,7 +5,9 @@ import { capitalize } from './string-helpers'; type Handler<T, R> = (callback: (arg: T) => R) => void; type Sender<T, R> = (arg: T) => R; -type Notifier<T> = (webContents: WebContents | undefined, arg: T) => void; +// Remove export after upgrading to Electron 21+ and removal of code to curry notifiers with +// webContents in ../main/ipc-event-channel.ts. +export type Notifier<T> = (webContents: WebContents | undefined, arg: T) => void; type Listener<T> = (callback: (arg: T) => void) => void; interface MainToRenderer<T> { |
