-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stop docker containers on application exit
This commit introduces a fix that ensures docker containers are gracefully stopped when the user exits the application. fix: correct comment after mod in previous commit fix: ipcRenderer import fix(test): modify electron's mock to include ipcRenderer's .on and .removeAllListeners functions feat: add shutting down indicator, add test, and make app quit on all OS by removing "if" test: add test for stopAll function fix: call stopAll without passing any param. Immediately close app when no network is started refactor: add test for stopAll dunction, moved 'shutting down...' label to en-US.json refactor: move component to common folder. Move style to Styled mappings refactor: removed an inline styling. Change key to reflect component's folder
- Loading branch information
Showing
8 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { renderWithProviders } from 'utils/tests'; | ||
import DockerContainerShutdown from './DockerContainerShutdown'; | ||
import { ipcRenderer } from '__mocks__/electron'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
describe('DockerContainerShutdown component', () => { | ||
let unmount: () => void; | ||
const renderComponent = async () => { | ||
const cmp = <DockerContainerShutdown />; | ||
const result = renderWithProviders(cmp); | ||
unmount = result.unmount; | ||
return result; | ||
}; | ||
afterEach(() => unmount()); | ||
it('should not display overlay when shutting down', async () => { | ||
const { queryByText } = await renderComponent(); | ||
expect(queryByText('Shutting down...')).toBeNull(); | ||
}); | ||
|
||
it('should set isShuttingDown to true when app is closing', async () => { | ||
const { getByText } = await renderComponent(); | ||
|
||
ipcRenderer.on.mock.calls[0][1](); | ||
await waitFor(() => expect(getByText('Shutting down...')).toBeInTheDocument()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { ipcRenderer } from 'electron'; | ||
import { useStoreActions } from 'store'; | ||
import { useAsyncCallback } from 'react-async-hook'; | ||
import { Modal, Spin } from 'antd'; | ||
import { LoadingOutlined } from '@ant-design/icons'; | ||
import { usePrefixedTranslation } from 'hooks'; | ||
import styled from '@emotion/styled'; | ||
|
||
const Styled = { | ||
LoadingCard: styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
`, | ||
LoadingLabel: styled.div` | ||
margin-left: 10px; | ||
`, | ||
Loading: styled(LoadingOutlined)` | ||
font-size: 24px; | ||
`, | ||
}; | ||
|
||
const DockerContainerShutdown: React.FC = () => { | ||
const [isShuttingDown, setIsShuttingDown] = useState(false); | ||
const { stopAll } = useStoreActions(s => s.network); | ||
const stopDockerContainersAsync = useAsyncCallback(stopAll); | ||
const { l } = usePrefixedTranslation('cmps.common.DockerContainerShutdown'); | ||
useEffect(() => { | ||
ipcRenderer.on('app-closing', async () => { | ||
setIsShuttingDown(true); | ||
await stopDockerContainersAsync.execute(); | ||
}); | ||
return () => { | ||
ipcRenderer.removeAllListeners('app-closing'); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<Modal open={isShuttingDown} closable={false} maskClosable={false} footer={null}> | ||
<Styled.LoadingCard> | ||
<Spin size="large" indicator={<Styled.Loading spin />} /> | ||
<Styled.LoadingLabel>{l('shutdownMsg')}</Styled.LoadingLabel> | ||
</Styled.LoadingCard> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default DockerContainerShutdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters