diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..b6cb563 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,27 @@ +const IPC_SELECTOR = 'IPC_SELECTOR' +const IPC_REFRESH_TICKETS = 'IPC_REFRESH_TICKETS' +const IPC_REFRESH_PRS = 'IPC_REFRESH_PRS' +const IPC_REFRESH_GIT = 'IPC_REFRESH_GIT' +const IPC_CHECKOUT_LOCAL_BRANCH = 'IPC_CHECKOUT_LOCAL_BRANCH' +const IPC_CREATE_BRANCH = 'IPC_CREATE_BRANCH' +const IPC_REBASE_BRANCH = 'IPC_REBASE_BRANCH' +const IPC_DELETE_BRANCH = 'IPC_DELETE_BRANCH' +const IPC_PUSH_BRANCH = 'IPC_PUSH_BRANCH' +const IPC_CANCEL_SELECT = 'IPC_CANCEL_SELECT' +const IPC_HIDE_SELECT = 'IPC_HIDE_SELECT' +const IPC_REPO_SELECT = 'IPC_REPO_SELECT' + +export { + IPC_SELECTOR, + IPC_REFRESH_TICKETS, + IPC_REFRESH_PRS, + IPC_REFRESH_GIT, + IPC_CHECKOUT_LOCAL_BRANCH, + IPC_CREATE_BRANCH, + IPC_REBASE_BRANCH, + IPC_DELETE_BRANCH, + IPC_PUSH_BRANCH, + IPC_CANCEL_SELECT, + IPC_REPO_SELECT, + IPC_HIDE_SELECT, +} diff --git a/src/main/index.ts b/src/main/index.ts index 44632f5..2cc7e88 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -30,6 +30,18 @@ import { showNotification } from '../plugins/notifications' // @ts-ignore import electronTimber from 'electron-timber' import { updateChecker } from '../plugins/updateChecker' +import { + IPC_CHECKOUT_LOCAL_BRANCH, + IPC_CREATE_BRANCH, + IPC_REBASE_BRANCH, + IPC_DELETE_BRANCH, + IPC_PUSH_BRANCH, + IPC_CANCEL_SELECT, + IPC_HIDE_SELECT, + IPC_REFRESH_TICKETS, + IPC_REFRESH_GIT, + IPC_REFRESH_PRS, +} from '../constants' const logger = electronTimber.create({ name: 'index' }) @@ -66,6 +78,12 @@ app.on('ready', () => { // getInfo() }) +app.on('browser-window-focus', () => { + mainWindow.webContents.send(IPC_REFRESH_TICKETS) + mainWindow.webContents.send(IPC_REFRESH_GIT) + mainWindow.webContents.send(IPC_REFRESH_PRS) +}) + function registerShortcuts() { okk( globalShortcut.register('Control+z', () => { @@ -74,7 +92,7 @@ function registerShortcuts() { ) } -ipcMain.on('on-create-branch-click', async (e, key) => { +ipcMain.on(IPC_CREATE_BRANCH, async (e, key) => { const result = await createBranchFromTicketId(key) if (result) { @@ -82,47 +100,56 @@ ipcMain.on('on-create-branch-click', async (e, key) => { title: 'branch created', body: key, }) + mainWindow.webContents.send(IPC_REFRESH_GIT) } }) ipcMain.on( - 'on-delete-branch-click', + IPC_DELETE_BRANCH, async (e, repoId: string, branchName: string, isRemote: boolean) => { await deleteBranch(repoId, branchName, isRemote, false) + if (isRemote) { + mainWindow.webContents.send(IPC_REFRESH_PRS) + } else { + mainWindow.webContents.send(IPC_REFRESH_GIT) + } }, ) -ipcMain.on('on-rebase-local-branch-click', async (e, repoId, branchName) => { +ipcMain.on(IPC_REBASE_BRANCH, async (e, repoId, branchName) => { await rebaseLocalBranch(repoId, branchName) showNotification({ title: 'branch rebased', body: `${repoId}:${branchName}`, }) + mainWindow.webContents.send(IPC_REFRESH_GIT) }) ipcMain.on( - 'on-push-local-branch-click', + IPC_PUSH_BRANCH, async ( e, { repoId, skipChecks, branchName }: Parameters[0], ) => { await pushTask({ repoId, skipChecks, branchName }) + mainWindow.webContents.send(IPC_REFRESH_GIT) }, ) -ipcMain.on('on-checkout-local-branch-click', async (e, repoId, branchName) => { +ipcMain.on(IPC_CHECKOUT_LOCAL_BRANCH, async (e, repoId, branchName) => { await checkoutLocalBranch(repoId, branchName) showNotification({ title: 'checked out branch', body: `${repoId}:${branchName}`, }) + mainWindow.webContents.send(IPC_REFRESH_GIT) }) -ipcMain.on('hide-select-window', () => { +ipcMain.on(IPC_HIDE_SELECT, () => { selectWindow.hide() }) -ipcMain.on('cancel-select-window', () => { +ipcMain.on(IPC_CANCEL_SELECT, () => { selectWindow.hide() }) diff --git a/src/plugins/windows.ts b/src/plugins/windows.ts index 1019f5b..2aced1a 100644 --- a/src/plugins/windows.ts +++ b/src/plugins/windows.ts @@ -1,4 +1,5 @@ import { BrowserWindow, screen, ipcMain } from 'electron' +import { IPC_SELECTOR, IPC_CANCEL_SELECT, IPC_REPO_SELECT } from '../constants' var mainWindow: BrowserWindow var selectWindow: BrowserWindow @@ -46,7 +47,7 @@ const createSelectWindow = () => { selectWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY) // selectWindow.webContents.openDevTools() selectWindow.webContents.on('did-finish-load', () => { - selectWindow.webContents.send('navigate_to_selector') + selectWindow.webContents.send(IPC_SELECTOR) }) return selectWindow // mainWindow.on('closed', () => { @@ -58,10 +59,10 @@ const showRepoSelector = () => { selectWindow.show() return new Promise<{ repoId: string } | false>((resolve, reject) => { - ipcMain.once('repo-selected', (e, repoId: string) => { + ipcMain.once(IPC_REPO_SELECT, (e, repoId: string) => { resolve({ repoId }) }) - ipcMain.once('cancel-select-window', e => { + ipcMain.once(IPC_CANCEL_SELECT, e => { resolve(undefined) }) }) diff --git a/src/store/branches/actions.ts b/src/store/branches/actions.ts index c4512cd..d0d3ceb 100644 --- a/src/store/branches/actions.ts +++ b/src/store/branches/actions.ts @@ -7,7 +7,7 @@ import { checkoutLocalBranch, getGitRepoFromId, } from '../../plugins/git' -import { TAppState, getRepoSettingsFromId } from '..' +import { TAppState } from '..' import { LOCAL_BRANCHES_UPDATED, TBranches, LOAD_BRANCHES } from './types' import { showNotification } from '../../plugins/notifications' @@ -16,7 +16,7 @@ import { okk } from '../../helpers/helpers' import electronTimber from 'electron-timber' const logger = electronTimber.create({ name: 'branches/actions' }) -export const fetchBranches = (): ThunkAction< +export const fetchGit = (): ThunkAction< void, TAppState, null, diff --git a/src/store/tickets/actions.ts b/src/store/tickets/actions.ts index f891aaa..bb9e27b 100644 --- a/src/store/tickets/actions.ts +++ b/src/store/tickets/actions.ts @@ -55,6 +55,7 @@ export const fetchTickets = ( } } catch (error) { logger.error('fetchTickets failed', error) + dispatch({ type: LOADING_JIRA_TICKETS_FAIL }) return diff --git a/src/windows/App.tsx b/src/windows/App.tsx index a0cba38..05f4d87 100644 --- a/src/windows/App.tsx +++ b/src/windows/App.tsx @@ -6,7 +6,7 @@ import React, { useEffect } from 'react' import { css, jsx } from '@emotion/core' import { fetchTickets, fetchPRs } from '../store/tickets/actions' -import { fetchBranches } from '../store/branches/actions' +import { fetchGit } from '../store/branches/actions' import { connect, ConnectedProps } from 'react-redux' import { TAppState } from '../store' @@ -25,7 +25,7 @@ const mapState = (state: TAppState) => ({ const mapDispatch = { fetchTicketsAction: fetchTickets, fetchPRsAction: fetchPRs, - fetchBranchesAction: fetchBranches, + fetchGitAction: fetchGit, } const connector = connect(mapState, mapDispatch) @@ -38,14 +38,14 @@ const app: React.FC = ({ settings, fetchTicketsAction, fetchPRsAction, - fetchBranchesAction, + fetchGitAction, history, }) => { const fetchData = (isFirstTime: boolean) => { if (validateSettings(settings)) { fetchTicketsAction(isFirstTime) fetchPRsAction(isFirstTime) - fetchBranchesAction() + fetchGitAction() } else { history.replace('/settings') } @@ -119,12 +119,7 @@ const app: React.FC = ({ text-align: right; `} > -
- Ctrl + z to show this window -
-
- Cmd + shift + up to open push dialogue -
+ Ctrl + z to show this window ) diff --git a/src/windows/components/TicketRow.tsx b/src/windows/components/TicketRow.tsx index a231758..230d690 100644 --- a/src/windows/components/TicketRow.tsx +++ b/src/windows/components/TicketRow.tsx @@ -20,6 +20,13 @@ import { TBranches } from '../../store/branches/types' import { ticketUrlFromKey } from '../../plugins/jira' import { TExtendedPullRequest } from '../../types' import { pushTask } from '../../tasks/push' +import { + IPC_CHECKOUT_LOCAL_BRANCH, + IPC_CREATE_BRANCH, + IPC_REBASE_BRANCH, + IPC_DELETE_BRANCH, + IPC_PUSH_BRANCH, +} from '../../constants' interface ITicketRowProps { relatedPRs: Array @@ -100,7 +107,7 @@ const TicketRow: React.FC = ({ icon={faCheckSquare} onClick={async () => { ipcRenderer.send( - 'on-checkout-local-branch-click', + IPC_CHECKOUT_LOCAL_BRANCH, relatedBranch.repoId, relatedBranch.name, ) @@ -139,7 +146,7 @@ const TicketRow: React.FC = ({ icon={faExchangeAlt} onClick={async () => { ipcRenderer.send( - 'on-rebase-local-branch-click', + IPC_REBASE_BRANCH, relatedBranch.repoId, relatedBranch.name, ) @@ -168,7 +175,7 @@ const TicketRow: React.FC = ({ branchName: relatedBranch.name, } - ipcRenderer.send('on-push-local-branch-click', options) + ipcRenderer.send(IPC_PUSH_BRANCH, options) }} css={css` ${ClickableBadgeStyle} @@ -181,7 +188,7 @@ const TicketRow: React.FC = ({ icon={faTrashAlt} onClick={async () => { ipcRenderer.send( - 'on-delete-branch-click', + IPC_DELETE_BRANCH, relatedBranch.repoId, relatedBranch.name, relatedBranch.isRemote, @@ -197,7 +204,7 @@ const TicketRow: React.FC = ({ { - ipcRenderer.send('on-create-branch-click', ticketData.key) + ipcRenderer.send(IPC_CREATE_BRANCH, ticketData.key) }} css={css` ${BadgeStyle} diff --git a/src/windows/index.tsx b/src/windows/index.tsx index 2559caa..e9040ad 100644 --- a/src/windows/index.tsx +++ b/src/windows/index.tsx @@ -1,3 +1,6 @@ +import sourceMapSupport from 'source-map-support' +sourceMapSupport.install() + import electronUnhandled from 'electron-unhandled' electronUnhandled({ showDialog: true }) @@ -16,13 +19,33 @@ import { Select } from './modals/Select' import { store } from '../store/index' import { ErrorBoundary } from '../ErrorBoundary' import { ipcRenderer } from 'electron' +import { fetchTickets, fetchPRs } from '../store/tickets/actions' +import { fetchGit } from '../store/branches/actions' +import { + IPC_SELECTOR, + IPC_REFRESH_TICKETS, + IPC_REFRESH_PRS, + IPC_REFRESH_GIT, +} from '../constants' const customHistory = createHashHistory() -ipcRenderer.on('navigate_to_selector', event => { +ipcRenderer.on(IPC_SELECTOR, event => { customHistory.replace('/select') }) +ipcRenderer.on(IPC_REFRESH_TICKETS, event => { + fetchTickets(false)(store.dispatch, store.getState, null) +}) + +ipcRenderer.on(IPC_REFRESH_PRS, event => { + fetchPRs(false)(store.dispatch, store.getState, null) +}) + +ipcRenderer.on(IPC_REFRESH_GIT, event => { + fetchGit()(store.dispatch, store.getState, null) +}) + render( diff --git a/src/windows/modals/Select.tsx b/src/windows/modals/Select.tsx index 17acc5d..ae2845c 100644 --- a/src/windows/modals/Select.tsx +++ b/src/windows/modals/Select.tsx @@ -5,6 +5,11 @@ import { ipcRenderer } from 'electron' import { css, jsx } from '@emotion/core' import { connect, ConnectedProps } from 'react-redux' import { TAppState } from '../../store' +import { + IPC_CANCEL_SELECT, + IPC_REPO_SELECT, + IPC_HIDE_SELECT, +} from '../../constants' const connector = connect((state: TAppState) => ({ settings: state.settings, @@ -35,7 +40,7 @@ const select: React.FC = ({ settings }) => { } `} onClick={() => { - ipcRenderer.send('cancel-select-window') + ipcRenderer.send(IPC_CANCEL_SELECT) }} > x @@ -65,8 +70,8 @@ const select: React.FC = ({ settings }) => { `} key={repoId} onClick={() => { - ipcRenderer.send('repo-selected', repoId) - ipcRenderer.send('hide-select-window') + ipcRenderer.send(IPC_REPO_SELECT, repoId) + ipcRenderer.send(IPC_HIDE_SELECT) }} > {repoId} diff --git a/src/windows/modals/Settings.tsx b/src/windows/modals/Settings.tsx index 0f45cc7..e80dcd9 100644 --- a/src/windows/modals/Settings.tsx +++ b/src/windows/modals/Settings.tsx @@ -401,8 +401,6 @@ const settings: React.FC = ({ settings, saveSettingsAction }) => ( {({ input }) => { - console.log(input.value, input.checked) - return (