diff --git a/lib/actions/config.ts b/lib/actions/config.ts index 260b3e4b..a237cce0 100644 --- a/lib/actions/config.ts +++ b/lib/actions/config.ts @@ -1,13 +1,14 @@ import {CONFIG_LOAD, CONFIG_RELOAD} from '../constants/config'; +import {HyperActions} from '../hyper'; -export function loadConfig(config) { +export function loadConfig(config: any): HyperActions { return { type: CONFIG_LOAD, config }; } -export function reloadConfig(config) { +export function reloadConfig(config: any): HyperActions { const now = Date.now(); return { type: CONFIG_RELOAD, diff --git a/lib/actions/header.ts b/lib/actions/header.ts index f72a1360..9cc52cef 100644 --- a/lib/actions/header.ts +++ b/lib/actions/header.ts @@ -8,9 +8,10 @@ import { } from '../constants/ui'; import rpc from '../rpc'; import {userExitTermGroup, setActiveGroup} from './term-groups'; +import {HyperDispatch} from '../hyper'; -export function closeTab(uid) { - return dispatch => { +export function closeTab(uid: string) { + return (dispatch: HyperDispatch) => { dispatch({ type: CLOSE_TAB, uid, @@ -21,8 +22,8 @@ export function closeTab(uid) { }; } -export function changeTab(uid) { - return dispatch => { +export function changeTab(uid: string) { + return (dispatch: HyperDispatch) => { dispatch({ type: CHANGE_TAB, uid, @@ -34,29 +35,29 @@ export function changeTab(uid) { } export function maximize() { - return dispatch => { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_WINDOW_MAXIMIZE, effect() { - rpc.emit('maximize'); + rpc.emit('maximize', null); } }); }; } export function unmaximize() { - return dispatch => { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_WINDOW_UNMAXIMIZE, effect() { - rpc.emit('unmaximize'); + rpc.emit('unmaximize', null); } }); }; } -export function openHamburgerMenu(coordinates) { - return dispatch => { +export function openHamburgerMenu(coordinates: {x: number; y: number}) { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_OPEN_HAMBURGER_MENU, effect() { @@ -67,22 +68,22 @@ export function openHamburgerMenu(coordinates) { } export function minimize() { - return dispatch => { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_WINDOW_MINIMIZE, effect() { - rpc.emit('minimize'); + rpc.emit('minimize', null); } }); }; } export function close() { - return dispatch => { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_WINDOW_CLOSE, effect() { - rpc.emit('close'); + rpc.emit('close', null); } }); }; diff --git a/lib/actions/index.ts b/lib/actions/index.ts index a4094f30..68b89fbf 100644 --- a/lib/actions/index.ts +++ b/lib/actions/index.ts @@ -1,9 +1,9 @@ import rpc from '../rpc'; import {INIT} from '../constants'; -import {Dispatch} from 'redux'; +import {HyperDispatch} from '../hyper'; export default function init() { - return (dispatch: Dispatch) => { + return (dispatch: HyperDispatch) => { dispatch({ type: INIT, effect: () => { diff --git a/lib/actions/notifications.ts b/lib/actions/notifications.ts index 01077550..71a1b9cc 100644 --- a/lib/actions/notifications.ts +++ b/lib/actions/notifications.ts @@ -1,13 +1,14 @@ import {NOTIFICATION_MESSAGE, NOTIFICATION_DISMISS} from '../constants/notifications'; +import {HyperActions} from '../hyper'; -export function dismissNotification(id: string) { +export function dismissNotification(id: string): HyperActions { return { type: NOTIFICATION_DISMISS, id }; } -export function addNotificationMessage(text: string, url: string | null = null, dismissable = true) { +export function addNotificationMessage(text: string, url: string | null = null, dismissable = true): HyperActions { return { type: NOTIFICATION_MESSAGE, text, diff --git a/lib/actions/sessions.ts b/lib/actions/sessions.ts index 9daa5085..fa8ddc0b 100644 --- a/lib/actions/sessions.ts +++ b/lib/actions/sessions.ts @@ -16,11 +16,10 @@ import { SESSION_SEARCH, SESSION_SEARCH_CLOSE } from '../constants/sessions'; -import {HyperState, session} from '../hyper'; -import {Dispatch} from 'redux'; +import {HyperState, session, HyperDispatch, HyperActions} from '../hyper'; export function addSession({uid, shell, pid, cols, rows, splitDirection, activeUid}: session) { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { const {sessions} = getState(); const now = Date.now(); dispatch({ @@ -38,7 +37,7 @@ export function addSession({uid, shell, pid, cols, rows, splitDirection, activeU } export function requestSession() { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: SESSION_REQUEST, effect: () => { @@ -52,7 +51,7 @@ export function requestSession() { } export function addSessionData(uid: string, data: any) { - return (dispatch: Dispatch) => { + return (dispatch: HyperDispatch) => { dispatch({ type: SESSION_ADD_DATA, data, @@ -69,8 +68,8 @@ export function addSessionData(uid: string, data: any) { }; } -function createExitAction(type: string) { - return (uid: string) => (dispatch: Dispatch, getState: () => HyperState) => { +function createExitAction(type: typeof SESSION_USER_EXIT | typeof SESSION_PTY_EXIT) { + return (uid: string) => (dispatch: HyperDispatch, getState: () => HyperState) => { return dispatch({ type, uid, @@ -84,7 +83,7 @@ function createExitAction(type: string) { window.close(); } } - }); + } as HyperActions); }; } @@ -94,7 +93,7 @@ export const userExitSession = createExitAction(SESSION_USER_EXIT); export const ptyExitSession = createExitAction(SESSION_PTY_EXIT); export function setActiveSession(uid: string) { - return (dispatch: Dispatch) => { + return (dispatch: HyperDispatch) => { dispatch({ type: SESSION_SET_ACTIVE, uid @@ -102,13 +101,13 @@ export function setActiveSession(uid: string) { }; } -export function clearActiveSession() { +export function clearActiveSession(): HyperActions { return { type: SESSION_CLEAR_ACTIVE }; } -export function setSessionXtermTitle(uid: string, title: string) { +export function setSessionXtermTitle(uid: string, title: string): HyperActions { return { type: SESSION_SET_XTERM_TITLE, uid, @@ -117,7 +116,7 @@ export function setSessionXtermTitle(uid: string, title: string) { } export function resizeSession(uid: string, cols: number, rows: number) { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { const {termGroups} = getState(); const group = findBySession(termGroups, uid)!; const isStandaloneTerm = !group.parentUid && !group.children.length; @@ -137,8 +136,8 @@ export function resizeSession(uid: string, cols: number, rows: number) { } export function onSearch(uid?: string) { - return (dispatch: Dispatch, getState: () => HyperState) => { - const targetUid = uid || getState().sessions.activeUid; + return (dispatch: HyperDispatch, getState: () => HyperState) => { + const targetUid = uid || getState().sessions.activeUid!; dispatch({ type: SESSION_SEARCH, uid: targetUid @@ -147,8 +146,8 @@ export function onSearch(uid?: string) { } export function closeSearch(uid?: string) { - return (dispatch: Dispatch, getState: () => HyperState) => { - const targetUid = uid || getState().sessions.activeUid; + return (dispatch: HyperDispatch, getState: () => HyperState) => { + const targetUid = uid || getState().sessions.activeUid!; dispatch({ type: SESSION_SEARCH_CLOSE, uid: targetUid @@ -157,7 +156,7 @@ export function closeSearch(uid?: string) { } export function sendSessionData(uid: string | null, data: any, escaped?: any) { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: SESSION_USER_DATA, data, diff --git a/lib/actions/term-groups.ts b/lib/actions/term-groups.ts index 25068558..3070ca0a 100644 --- a/lib/actions/term-groups.ts +++ b/lib/actions/term-groups.ts @@ -10,12 +10,11 @@ import {SESSION_REQUEST} from '../constants/sessions'; import findBySession from '../utils/term-groups'; import {getRootGroups} from '../selectors'; import {setActiveSession, ptyExitSession, userExitSession} from './sessions'; -import {Dispatch} from 'redux'; -import {ITermState, ITermGroup, HyperState} from '../hyper'; +import {ITermState, ITermGroup, HyperState, HyperDispatch} from '../hyper'; import {Immutable} from 'seamless-immutable'; function requestSplit(direction: string) { - return (activeUid: string) => (dispatch: Dispatch, getState: () => HyperState): void => { + return (activeUid: string) => (dispatch: HyperDispatch, getState: () => HyperState): void => { dispatch({ type: SESSION_REQUEST, effect: () => { @@ -42,7 +41,7 @@ export function resizeTermGroup(uid: string, sizes: number[]) { } export function requestTermGroup(activeUid: string) { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: TERM_GROUP_REQUEST, effect: () => { @@ -59,7 +58,7 @@ export function requestTermGroup(activeUid: string) { } export function setActiveGroup(uid: string) { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { const {termGroups} = getState(); dispatch(setActiveSession(termGroups.activeSessions[uid])); }; @@ -106,7 +105,7 @@ const findNextSessionUid = (state: Immutable, group: Immutable, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { const {termGroups} = getState(); const group = findBySession(termGroups, sessionUid); // This might have already been closed: @@ -131,7 +130,7 @@ export function ptyExitTermGroup(sessionUid: string) { } export function userExitTermGroup(uid: string) { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { const {termGroups} = getState(); dispatch({ type: TERM_GROUP_EXIT, @@ -163,7 +162,7 @@ export function userExitTermGroup(uid: string) { } export function exitActiveTermGroup() { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: TERM_GROUP_EXIT_ACTIVE, effect() { diff --git a/lib/actions/ui.ts b/lib/actions/ui.ts index 13e82125..fbbab767 100644 --- a/lib/actions/ui.ts +++ b/lib/actions/ui.ts @@ -4,7 +4,7 @@ import {getRootGroups} from '../selectors'; import findBySession from '../utils/term-groups'; import notify from '../utils/notify'; import rpc from '../rpc'; -import {requestSession, sendSessionData, setActiveSession} from '../actions/sessions'; +import {requestSession, sendSessionData, setActiveSession} from './sessions'; import { UI_FONT_SIZE_SET, UI_FONT_SIZE_INCR, @@ -28,14 +28,13 @@ import { import {setActiveGroup} from './term-groups'; import parseUrl from 'parse-url'; -import {Dispatch} from 'redux'; -import {HyperState} from '../hyper'; +import {HyperState, HyperDispatch, HyperActions} from '../hyper'; import {Stats} from 'fs'; const {stat} = window.require('fs'); export function openContextMenu(uid: string, selection: any) { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: UI_CONTEXTMENU_OPEN, uid, @@ -51,7 +50,7 @@ export function openContextMenu(uid: string, selection: any) { } export function increaseFontSize() { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: UI_FONT_SIZE_INCR, effect() { @@ -68,7 +67,7 @@ export function increaseFontSize() { } export function decreaseFontSize() { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: UI_FONT_SIZE_DECR, effect() { @@ -85,14 +84,14 @@ export function decreaseFontSize() { }; } -export function resetFontSize() { +export function resetFontSize(): HyperActions { return { type: UI_FONT_SIZE_RESET }; } export function setFontSmoothing() { - return (dispatch: Dispatch) => { + return (dispatch: HyperDispatch) => { setTimeout(() => { const devicePixelRatio = window.devicePixelRatio; const fontSmoothing = devicePixelRatio < 2 ? 'subpixel-antialiased' : 'antialiased'; @@ -105,7 +104,7 @@ export function setFontSmoothing() { }; } -export function windowGeometryUpdated() { +export function windowGeometryUpdated(): HyperActions { return { type: UI_WINDOW_GEOMETRY_CHANGED }; @@ -135,8 +134,8 @@ const getNeighborIndex = (groups: string[], uid: string, type: string) => { return (groups.indexOf(uid) + groups.length - 1) % groups.length; }; -function moveToNeighborPane(type: string) { - return () => (dispatch: Dispatch, getState: () => HyperState) => { +function moveToNeighborPane(type: typeof UI_MOVE_NEXT_PANE | typeof UI_MOVE_PREV_PANE) { + return () => (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type, effect() { @@ -152,7 +151,7 @@ function moveToNeighborPane(type: string) { dispatch(setActiveSession(sessionUid!)); } } - }); + } as HyperActions); }; } @@ -165,7 +164,7 @@ const getGroupUids = (state: HyperState) => { }; export function moveLeft() { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: UI_MOVE_LEFT, effect() { @@ -186,7 +185,7 @@ export function moveLeft() { } export function moveRight() { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { dispatch({ type: UI_MOVE_RIGHT, effect() { @@ -207,7 +206,7 @@ export function moveRight() { } export function moveTo(i: number | 'last') { - return (dispatch: Dispatch, getState: () => HyperState) => { + return (dispatch: HyperDispatch, getState: () => HyperState) => { if (i === 'last') { // Finding last tab index const {termGroups} = getState().termGroups; @@ -238,7 +237,7 @@ export function moveTo(i: number | 'last') { } export function windowMove(window: any) { - return (dispatch: Dispatch) => { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_WINDOW_MOVE, window, @@ -250,7 +249,7 @@ export function windowMove(window: any) { } export function windowGeometryChange() { - return (dispatch: Dispatch) => { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_WINDOW_MOVE, effect() { @@ -261,7 +260,7 @@ export function windowGeometryChange() { } export function openFile(path: string) { - return (dispatch: Dispatch) => { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_OPEN_FILE, effect() { @@ -288,20 +287,20 @@ export function openFile(path: string) { }; } -export function enterFullScreen() { +export function enterFullScreen(): HyperActions { return { type: UI_ENTER_FULLSCREEN }; } -export function leaveFullScreen() { +export function leaveFullScreen(): HyperActions { return { type: UI_LEAVE_FULLSCREEN }; } export function openSSH(url: string) { - return (dispatch: Dispatch) => { + return (dispatch: HyperDispatch) => { dispatch({ type: UI_OPEN_SSH_URL, effect() { @@ -325,7 +324,7 @@ export function openSSH(url: string) { } export function execCommand(command: any, fn: any, e: any) { - return (dispatch: Dispatch) => + return (dispatch: HyperDispatch) => dispatch({ type: UI_COMMAND_EXEC, command, diff --git a/lib/actions/updater.ts b/lib/actions/updater.ts index f4d26389..17eef45b 100644 --- a/lib/actions/updater.ts +++ b/lib/actions/updater.ts @@ -1,16 +1,17 @@ import {UPDATE_INSTALL, UPDATE_AVAILABLE} from '../constants/updater'; import rpc from '../rpc'; +import {HyperActions} from '../hyper'; -export function installUpdate() { +export function installUpdate(): HyperActions { return { type: UPDATE_INSTALL, effect: () => { - rpc.emit('quit and install'); + rpc.emit('quit and install', null); } }; } -export function updateAvailable(version, notes, releaseUrl, canInstall) { +export function updateAvailable(version: string, notes: string, releaseUrl: string, canInstall: boolean): HyperActions { return { type: UPDATE_AVAILABLE, version,