cleanup and type fixes

This commit is contained in:
Labhansh Agrawal 2023-06-25 17:57:42 +05:30
parent 8991dfab61
commit e31d72cc31
12 changed files with 45 additions and 40 deletions

View file

@ -76,21 +76,16 @@ export default (win: BrowserWindow) => {
const {rpc} = win;
const onupdate = (
ev: Event,
releaseNotes: string,
releaseName: string,
date: Date,
updateUrl: string,
onQuitAndInstall: any
) => {
const onupdate = (ev: Event, releaseNotes: string, releaseName: string, date: Date, updateUrl: string) => {
const releaseUrl = updateUrl || `https://github.com/vercel/hyper/releases/tag/${releaseName}`;
rpc.emit('update available', {releaseNotes, releaseName, releaseUrl, canInstall: !!onQuitAndInstall});
rpc.emit('update available', {releaseNotes, releaseName, releaseUrl, canInstall: !isLinux});
};
const eventName: any = isLinux ? 'update-available' : 'update-downloaded';
autoUpdater.on(eventName, onupdate);
if (isLinux) {
autoUpdater.on('update-available', onupdate);
} else {
autoUpdater.on('update-downloaded', onupdate);
}
rpc.once('quit and install', () => {
autoUpdater.quitAndInstall();
@ -111,6 +106,10 @@ export default (win: BrowserWindow) => {
});
win.on('close', () => {
autoUpdater.removeListener(eventName, onupdate);
if (isLinux) {
autoUpdater.removeListener('update-available', onupdate);
} else {
autoUpdater.removeListener('update-downloaded', onupdate);
}
});
};

View file

@ -30,7 +30,7 @@ const fileName =
function memoize<T extends (...args: any[]) => any>(fn: T): T {
let hasResult = false;
let result: any;
return ((...args: any[]) => {
return ((...args: Parameters<T>) => {
if (!hasResult) {
result = fn(...args);
hasResult = true;

View file

@ -191,8 +191,10 @@ const main = (argv: string[]) => {
version: false,
mri: {
boolean: ['v', 'verbose']
}
} as any);
},
mainColor: 'yellow',
subColor: 'dim'
});
if (commandPromise) {
return commandPromise;

View file

@ -31,7 +31,7 @@ import parseUrl from 'parse-url';
import {HyperState, HyperDispatch, HyperActions, ITermGroups} from '../hyper';
import {stat, Stats} from 'fs';
export function openContextMenu(uid: string, selection: any) {
export function openContextMenu(uid: string, selection: string) {
return (dispatch: HyperDispatch, getState: () => HyperState) => {
dispatch({
type: UI_CONTEXTMENU_OPEN,

View file

@ -24,13 +24,14 @@ export default class SplitPane extends React.PureComponent<SplitPaneProps, {drag
}
}
setupPanes(ev: any) {
this.panes = Array.from(ev.target.parentNode.childNodes);
this.paneIndex = this.panes.indexOf(ev.target);
setupPanes(ev: React.MouseEvent<HTMLDivElement>) {
const target = ev.target as HTMLDivElement;
this.panes = Array.from(target.parentElement?.children || []);
this.paneIndex = this.panes.indexOf(target);
this.paneIndex -= Math.ceil(this.paneIndex / 2);
}
handleAutoResize = (ev: React.MouseEvent) => {
handleAutoResize = (ev: React.MouseEvent<HTMLDivElement>) => {
ev.preventDefault();
this.setupPanes(ev);
@ -46,8 +47,7 @@ export default class SplitPane extends React.PureComponent<SplitPaneProps, {drag
this.props.onResize(sizes_);
};
handleDragStart = (ev: any) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
handleDragStart = (ev: React.MouseEvent<HTMLDivElement>) => {
ev.preventDefault();
this.setState({dragging: true});
window.addEventListener('mousemove', this.onDrag);
@ -64,10 +64,10 @@ export default class SplitPane extends React.PureComponent<SplitPaneProps, {drag
this.d3 = 'clientX';
}
this.dragTarget = ev.target;
const target = ev.target as HTMLDivElement;
this.dragTarget = target;
this.dragPanePosition = this.dragTarget.getBoundingClientRect()[this.d2];
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.panesSize = ev.target.parentNode.getBoundingClientRect()[this.d1];
this.panesSize = target.parentElement!.getBoundingClientRect()[this.d1];
this.setupPanes(ev);
};

View file

@ -41,6 +41,7 @@ export interface SessionAddDataAction {
}
export interface SessionPtyDataAction {
type: typeof SESSION_PTY_DATA;
data: string;
uid: string;
now: number;
}

View file

@ -85,7 +85,7 @@ const mapDispatchToProps = (dispatch: HyperDispatch) => {
dispatch(closeSearch(uid));
},
onContextMenu(uid: string, selection: any) {
onContextMenu(uid: string, selection: string) {
dispatch(setActiveSession(uid));
dispatch(openContextMenu(uid, selection));
}

View file

@ -29,7 +29,7 @@ const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].includes(navigator.plat
const allowedCursorShapes = new Set(['BEAM', 'BLOCK', 'UNDERLINE']);
const allowedCursorBlinkValues = new Set([true, false]);
const allowedBells = new Set(['SOUND', 'false', false]);
const allowedHamburgerMenuValues = new Set([true, false]);
const allowedHamburgerMenuValues = new Set([true, false, '']);
const allowedWindowControlsValues = new Set([true, false, 'left']);
// Populate `config-default.js` from this :)
@ -239,7 +239,7 @@ const reducer: IUiReducer = (state = initial, action) => {
ret.modifierKeys = config.modifierKeys;
}
if (allowedHamburgerMenuValues.has(config.showHamburgerMenu as any)) {
if (allowedHamburgerMenuValues.has(config.showHamburgerMenu)) {
ret.showHamburgerMenu = config.showHamburgerMenu;
}

View file

@ -1,10 +1,11 @@
import {HyperActions, HyperState} from '../hyper';
import terms from '../terms';
import {Middleware} from 'redux';
import {Dispatch, Middleware} from 'redux';
// the only side effect we perform from middleware
// is to write to the react term instance directly
// to avoid a performance hit
const writeMiddleware: Middleware = () => (next) => (action) => {
const writeMiddleware: Middleware<{}, HyperState, Dispatch<HyperActions>> = () => (next) => (action: HyperActions) => {
if (action.type === 'SESSION_PTY_DATA') {
const term = terms[action.uid];
if (term) {

View file

@ -1,3 +1,5 @@
import {Dispatch, Middleware} from 'redux';
import {HyperActions, HyperState} from '../hyper';
/**
* Simple redux middleware that executes
* the `effect` field if provided in an action
@ -6,8 +8,7 @@
* defer or add to existing side effects at will
* as the result of an action being triggered.
*/
import {Middleware} from 'redux';
const effectsMiddleware: Middleware = () => (next) => (action) => {
const effectsMiddleware: Middleware<{}, HyperState, Dispatch<HyperActions>> = () => (next) => (action) => {
const ret = next(action);
if (action.effect) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call

View file

@ -9,7 +9,7 @@ import {basename} from 'path';
// patching Module._load
// so plugins can `require` them without needing their own version
// https://github.com/vercel/hyper/issues/619
import React, {PureComponent} from 'react';
import React, {ComponentType, PureComponent} from 'react';
import ReactDOM from 'react-dom';
import Notification from '../components/notification';
import notify from './notify';
@ -24,9 +24,10 @@ import {
TabsProps,
TermGroupOwnProps,
TermProps,
Assignable
Assignable,
HyperActions
} from '../hyper';
import {Middleware} from 'redux';
import {Dispatch, Middleware} from 'redux';
import {ObjectTypedKeys} from './object';
import IPCChildProcess from './ipc-child-process';
import ChildProcess from 'child_process';
@ -456,10 +457,10 @@ export function getTabProps<T extends Assignable<TabProps, T>>(tab: any, parentP
export function connect<stateProps extends {}, dispatchProps>(
stateFn: (state: HyperState) => stateProps,
dispatchFn: (dispatch: HyperDispatch) => dispatchProps,
c: any,
c: null | undefined,
d: Options = {}
) {
return (Class: any, name: keyof typeof connectors) => {
return (Class: ComponentType<any>, name: keyof typeof connectors) => {
return reduxConnect<stateProps, dispatchProps, any, HyperState>(
(state) => {
let ret = stateFn(state);
@ -570,7 +571,7 @@ export function decorateSessionsReducer(fn: ISessionReducer) {
}
// redux middleware generator
export const middleware: Middleware = (store) => (next) => (action) => {
export const middleware: Middleware<{}, HyperState, Dispatch<HyperActions>> = (store) => (next) => (action) => {
const nextMiddleware = (remaining: Middleware[]) => (action_: any) =>
remaining.length ? remaining[0](store)(nextMiddleware(remaining.slice(1)))(action_) : next(action_);
nextMiddleware(middlewares)(action);

View file

@ -2,7 +2,7 @@ if (typeof snapshotResult !== 'undefined') {
const Module = __non_webpack_require__('module');
const originalLoad: (module: string, ...args: any[]) => any = Module._load;
Module._load = function _load(module: string, ...args: any[]): NodeModule {
Module._load = function _load(module: string, ...args: unknown[]): NodeModule {
let cachedModule = snapshotResult.customRequire.cache[module];
if (cachedModule) return cachedModule.exports;