Skip to content

Commit 067c8a0

Browse files
committed
Address PR comments regarding default handling upon startup
Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
1 parent 96e9cc1 commit 067c8a0

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

packages/terminal/src/browser/terminal-frontend-contribution.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import {
3030
isWindows
3131
} from '@theia/core/lib/common';
3232
import {
33-
ApplicationShell, KeybindingContribution, KeyCode, Key, WidgetManager,
33+
ApplicationShell, KeybindingContribution, KeyCode, Key, WidgetManager, PreferenceService,
3434
KeybindingRegistry, Widget, LabelProvider, WidgetOpenerOptions, StorageService,
35-
QuickInputService, codicon, CommonCommands, FrontendApplicationContribution, OnWillStopAction, Dialog, ConfirmDialog, FrontendApplication
35+
QuickInputService, codicon, CommonCommands, FrontendApplicationContribution, OnWillStopAction, Dialog, ConfirmDialog, FrontendApplication, PreferenceScope
3636
} from '@theia/core/lib/browser';
3737
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
3838
import { TERMINAL_WIDGET_FACTORY_ID, TerminalWidgetFactoryOptions, TerminalWidgetImpl } from './terminal-widget-impl';
@@ -198,6 +198,9 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
198198
@inject(StorageService)
199199
protected readonly storageService: StorageService;
200200

201+
@inject(PreferenceService)
202+
protected readonly preferenceService: PreferenceService;
203+
201204
@inject(TerminalPreferences)
202205
protected terminalPreferences: TerminalPreferences;
203206

@@ -245,9 +248,31 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
245248
await this.contributeDefaultProfiles();
246249

247250
this.terminalPreferences.onPreferenceChanged(e => {
248-
this.mergePreferencesPromise = this.mergePreferencesPromise.finally(() => this.mergePreferences());
251+
if (e.preferenceName.startsWith('terminal.integrated.')) {
252+
this.mergePreferencesPromise = this.mergePreferencesPromise.finally(() => this.mergePreferences());
253+
}
249254
});
250255
this.mergePreferencesPromise = this.mergePreferencesPromise.finally(() => this.mergePreferences());
256+
257+
this.profileService.onAdded(id => {
258+
// extension contributions get read after this point: need to set the default profile if necessary
259+
let defaultProfileId;
260+
switch (OS.type()) {
261+
case OS.Type.Windows: {
262+
defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.windows'];
263+
break;
264+
}
265+
case OS.Type.Linux: {
266+
defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.linux'];
267+
break;
268+
}
269+
case OS.Type.OSX: {
270+
defaultProfileId = this.terminalPreferences['terminal.integrated.defaultProfile.osx'];
271+
break;
272+
}
273+
}
274+
this.profileService.setDefaultProfile(defaultProfileId);
275+
});
251276
}
252277

253278
async contributeDefaultProfiles(): Promise<void> {
@@ -259,7 +284,7 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
259284
])!
260285
}));
261286
} else {
262-
this.contributedProfileStore.registerTerminalProfile('cmd', new ShellTerminalProfile(this, {
287+
this.contributedProfileStore.registerTerminalProfile('SHELL', new ShellTerminalProfile(this, {
263288
shellPath: await this.resolveShellPath('${SHELL}')!,
264289
shellArgs: ['-l']
265290
}));
@@ -916,7 +941,7 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
916941
return;
917942
}
918943

919-
this.profileService.setDefaultProfile(result[0]);
944+
this.preferenceService.set(`terminal.integrated.defaultProfile.${OS.type().toLowerCase()}`, result[0], PreferenceScope.User);
920945
}
921946

922947
protected async openActiveWorkspaceTerminal(options?: ApplicationShell.WidgetOptions): Promise<void> {

packages/terminal/src/browser/terminal-profile-service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const NULL_PROFILE: TerminalProfile = {
3232
};
3333

3434
export interface TerminalProfileService {
35+
onAdded: Event<string>;
36+
onRemoved: Event<string>;
3537
getProfile(id: string): TerminalProfile | undefined
3638
readonly all: [string, TerminalProfile][];
3739
setDefaultProfile(id: string): void;
@@ -84,6 +86,12 @@ export class DefaultTerminalProfileService implements TerminalProfileService {
8486
protected order: string[] = [];
8587
protected readonly stores: TerminalProfileStore[];
8688

89+
protected readonly onAddedEmitter: Emitter<string> = new Emitter();
90+
protected readonly onRemovedEmitter: Emitter<string> = new Emitter();
91+
92+
onAdded: Event<string> = this.onAddedEmitter.event;
93+
onRemoved: Event<string> = this.onRemovedEmitter.event;
94+
8795
constructor(...stores: TerminalProfileStore[]) {
8896
this.stores = stores;
8997
for (const store of this.stores) {
@@ -111,13 +119,15 @@ export class DefaultTerminalProfileService implements TerminalProfileService {
111119
// the profile was removed, but it's still in the `order` array
112120
this.order.splice(index, 1);
113121
this.defaultProfileIndex = Math.max(0, Math.min(this.order.length - 1, index));
122+
this.onRemovedEmitter.fire(id);
114123
}
115124
}
116125

117126
handleAdded(id: string): void {
118127
const index = this.order.indexOf(id);
119128
if (index < 0) {
120129
this.order.push(id);
130+
this.onAddedEmitter.fire(id);
121131
}
122132
}
123133

0 commit comments

Comments
 (0)