Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

FIXED: handle different Windows Terminal profile settings #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { stat } from 'fs';
import { promisify } from 'util';
import { dirname } from 'path';
import { detectInstallation } from './installation';
import { IWTProfile, IWTInstallation } from './interfaces';
import { IWTProfile, IWTInstallation, IWTSettings } from './interfaces';

let installation: IWTInstallation;

Expand Down Expand Up @@ -97,9 +97,17 @@ async function openActiveFilesFolderWithProfile() {
}
}

function getProfiles(settings: IWTSettings): IWTProfile[] {
// Windows Terminal versions have a different json schema for profiles:
// - some versions have the profile list set as settings.profiles.list
// - some versions have the profile list set as settings.profiles
return settings.profiles.list || settings.profiles;
}

async function getDefaultProfile(installation: IWTInstallation): Promise<IWTProfile> {
const settings = await getSettingsContents(installation.settingsPath);
const defaultProfile = settings.profiles.list.find(p => p.guid === settings.defaultProfile);
const profiles = getProfiles(settings);
const defaultProfile = profiles.find(p => p.guid === settings.defaultProfile);
if (!defaultProfile) {
throw new Error('Could not detect default profile');
}
Expand All @@ -108,8 +116,10 @@ async function getDefaultProfile(installation: IWTInstallation): Promise<IWTProf

async function chooseProfile(installation: IWTInstallation): Promise<IWTProfile | undefined> {
const settings = await getSettingsContents(installation.settingsPath);
const profiles = getProfiles(settings);
let defaultIndex = -1;
const quickPickItems: (vscode.QuickPickItem & { profile: IWTProfile })[] = settings.profiles.list.map((profile, i) => {

const quickPickItems: (vscode.QuickPickItem & { profile: IWTProfile })[] = profiles.map((profile, i) => {
const isDefault = profile.guid === settings.defaultProfile;
if (isDefault) {
defaultIndex = i;
Expand Down