Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
8 changes: 7 additions & 1 deletion Composer/packages/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -32,6 +35,9 @@ export const App: React.FC = () => {
checkNodeVersion();
fetchExtensions();
fetchFeatureFlags();
ipcRenderer?.on('cleanup', (_event) => {
performAppCleanupOnQuit();
});
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -156,6 +162,7 @@ export const applicationDispatcher = () => {
setMessage: debounce(setMessage, 500),
onboardingSetComplete,
onboardingAddCoachMarkRef,
performAppCleanupOnQuit,
setCreationFlowStatus,
setApplicationLevelError,
setCreationFlowType,
Expand Down
5 changes: 2 additions & 3 deletions Composer/packages/client/src/utils/electronUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/electron-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down