diff --git a/Composer/packages/client/src/App.tsx b/Composer/packages/client/src/App.tsx index 10dca85a7e..ecc68da714 100644 --- a/Composer/packages/client/src/App.tsx +++ b/Composer/packages/client/src/App.tsx @@ -19,10 +19,13 @@ const Logger = () => { return null; }; +const { ipcRenderer } = window; export const App: React.FC = () => { const { appLocale } = useRecoilValue(userSettingsState); - const { fetchExtensions, fetchFeatureFlags, checkNodeVersion } = useRecoilValue(dispatcherState); + const { fetchExtensions, fetchFeatureFlags, checkNodeVersion, performAppCleanupOnQuit } = useRecoilValue( + dispatcherState + ); useEffect(() => { loadLocale(appLocale); @@ -32,6 +35,9 @@ export const App: React.FC = () => { checkNodeVersion(); fetchExtensions(); fetchFeatureFlags(); + ipcRenderer?.on('cleanup', (_event) => { + performAppCleanupOnQuit(); + }); }, []); return ( diff --git a/Composer/packages/client/src/recoilModel/dispatchers/application.ts b/Composer/packages/client/src/recoilModel/dispatchers/application.ts index 259d31253e..7decb8f7b8 100644 --- a/Composer/packages/client/src/recoilModel/dispatchers/application.ts +++ b/Composer/packages/client/src/recoilModel/dispatchers/application.ts @@ -26,6 +26,7 @@ import { DebugDrawerKeys } from '../../pages/design/DebugPanel/TabExtensions/typ import httpClient from '../../utils/httpUtil'; import { setError } from './shared'; +import { flushExistingTasks } from './utils/project'; export const applicationDispatcher = () => { const setAppUpdateStatus = useRecoilCallback( @@ -147,6 +148,11 @@ export const applicationDispatcher = () => { } }); + const performAppCleanupOnQuit = useRecoilCallback((callbackHelpers: CallbackInterface) => async () => { + // shutdown any running bots to avoid orphaned processes + await flushExistingTasks(callbackHelpers); + }); + return { checkNodeVersion, setAppUpdateStatus, @@ -156,6 +162,7 @@ export const applicationDispatcher = () => { setMessage: debounce(setMessage, 500), onboardingSetComplete, onboardingAddCoachMarkRef, + performAppCleanupOnQuit, setCreationFlowStatus, setApplicationLevelError, setCreationFlowType, diff --git a/Composer/packages/client/src/utils/electronUtil.ts b/Composer/packages/client/src/utils/electronUtil.ts index 1484254931..8202004574 100644 --- a/Composer/packages/client/src/utils/electronUtil.ts +++ b/Composer/packages/client/src/utils/electronUtil.ts @@ -2,10 +2,8 @@ // Licensed under the MIT License. import { PublishTarget } from '@bfc/shared'; -// import { armScopes } from '../constants'; - import httpClient from './httpUtil'; -// import { AuthClient } from './authClient'; + /** * Returns true if the client is embedded in the Composer Electron environment. */ @@ -23,6 +21,7 @@ type ABSProfile = { armEndpoint?: string; }; export type Profile = ABSProfile; // can include PVAProfile or other type of profile by | + /** * * @param profile payload from bf's create protocol diff --git a/Composer/packages/electron-server/src/main.ts b/Composer/packages/electron-server/src/main.ts index 0699300fb7..dc39551c3d 100644 --- a/Composer/packages/electron-server/src/main.ts +++ b/Composer/packages/electron-server/src/main.ts @@ -311,6 +311,7 @@ async function run() { app.on('before-quit', () => { const mainWindow = ElectronWindow.getInstance().browserWindow; mainWindow?.webContents.send('session-update', 'session-ended'); + mainWindow?.webContents.send('cleanup'); }); app.on('activate', () => {