Skip to content

Commit

Permalink
feat: close terminal pane on switching project
Browse files Browse the repository at this point in the history
  • Loading branch information
topliceanurazvan committed Oct 21, 2022
1 parent b2b3214 commit db770cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
7 changes: 4 additions & 3 deletions electron/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ export function askActionConfirmation({
if (unsavedResourceCount) {
message +=
unsavedResourceCount === 1
? 'You have an unsaved resource\n'
: `You have ${unsavedResourceCount} unsaved resources\n`;
? 'You have an unsaved resource.\n'
: `You have ${unsavedResourceCount} unsaved resources.\n`;
}

if (terminalsCount) {
message += terminalsCount === 1 ? 'You have a terminal tab open' : `You have ${terminalsCount} terminal tabs open`;
message +=
terminalsCount === 1 ? 'You have a terminal tab open.' : `You have ${terminalsCount} terminal tabs open.`;
}

const choice = dialog.showMessageBoxSync({
Expand Down
14 changes: 2 additions & 12 deletions src/redux/reducers/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import flatten from 'flat';
import {existsSync, mkdirSync} from 'fs';
import _ from 'lodash';
import path, {join} from 'path';
import {v4 as uuidv4} from 'uuid';

import {PREDEFINED_K8S_VERSION} from '@constants/constants';

Expand Down Expand Up @@ -46,7 +45,6 @@ import {promiseFromIpcRenderer} from '@utils/promises';
import {readSavedCrdKindHandlers} from '@src/kindhandlers';

import initialState from '../initialState';
import {addTerminal, setSelectedTerminal} from './terminal';
import {setLeftBottomMenuSelection, setLeftMenuSelection, toggleStartProjectPane} from './ui';

export const setCreateProject = createAsyncThunk('config/setCreateProject', async (project: Project, thunkAPI: any) => {
Expand Down Expand Up @@ -76,6 +74,8 @@ export const setOpenProject = createAsyncThunk(
const terminalsIds: string[] = Object.keys(thunkAPI.getState().terminal.terminalsMap);

if (terminalsIds.length) {
thunkAPI.dispatch(setLeftBottomMenuSelection(null));

terminalsIds.forEach(terminalId => {
ipcRenderer.send('shell.ptyProcessKillAll', {terminalId});
});
Expand Down Expand Up @@ -107,16 +107,6 @@ export const setOpenProject = createAsyncThunk(
projectConfig.k8sVersion = PREDEFINED_K8S_VERSION;
}

if (terminalsIds) {
const newTerminalId = uuidv4();
thunkAPI.dispatch(
addTerminal({id: newTerminalId, isRunning: false, shell: thunkAPI.getState().terminal.settings.defaultShell})
);
thunkAPI.dispatch(setSelectedTerminal(newTerminalId));

thunkAPI.dispatch(setLeftBottomMenuSelection('terminal'));
}

// Then set project config by reading .monokle or populating it
thunkAPI.dispatch(configSlice.actions.updateProjectConfig({config, fromConfigFile: false}));
// Last set rootFolder so function can read the latest projectConfig
Expand Down

0 comments on commit db770cf

Please sign in to comment.