Fix not using the users configured shell for sync (#6589)

* Fix not using the users configured shell for sync

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix issue with use of userShellSetting in ShellSessions

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-11-17 10:15:56 -05:00
1 parent a89eb486d8
commit a91e3a7f8e
10 files changed
+56 -32

No files matched your search

@@ -3,12 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { homedir } from "os";
import userInfoInjectable from "../user-store/user-info.injectable";
const homeDirectoryPathInjectable = getInjectable({
id: "home-directory-path",
instantiate: () => homedir(),
causesSideEffects: true,
instantiate: (di) => di.inject(userInfoInjectable).homedir,
});
export default homeDirectoryPathInjectable;
@@ -1,13 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import userStoreInjectable from "./user-store.injectable";
const resolvedShellInjectable = getInjectable({
id: "resolved-shell",
instantiate: (di) => di.inject(userStoreInjectable).resolvedShell,
});
export default resolvedShellInjectable;
@@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import userInfoInjectable from "./user-info.injectable";
import userStoreInjectable from "./user-store.injectable";
const userShellSettingInjectable = getInjectable({
id: "user-shell-setting",
instantiate: (di) => {
const userStore = di.inject(userStoreInjectable);
const userInfo = di.inject(userInfoInjectable);
return computed(() => userStore.shell || userInfo.shell);
},
});
export default userShellSettingInjectable;
@@ -4,6 +4,12 @@
*/
import { getGlobalOverride } from "../test-utils/get-global-override";
import homeDirectoryPathInjectable from "./home-directory-path.injectable";
import userInfoInjectable from "./user-info.injectable";
export default getGlobalOverride(homeDirectoryPathInjectable, () => "/some-home-directory");
export default getGlobalOverride(userInfoInjectable, () => ({
gid: 1,
homedir: "/some-home-dir",
shell: "bash",
uid: 2,
username: "some-user-name",
}));
@@ -0,0 +1,14 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { userInfo } from "os";
const userInfoInjectable = getInjectable({
id: "user-info",
instantiate: () => userInfo(),
causesSideEffects: true,
});
export default userInfoInjectable;
+1 -5
View File
@@ -4,7 +4,7 @@
*/
import { app } from "electron";
import { action, computed, observable, reaction, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx";
import { action, observable, reaction, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx";
import { BaseStore } from "../base-store";
import migrations from "../../migrations/user-store";
import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils";
@@ -91,10 +91,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
*/
@observable syncKubeconfigEntries!: StoreType<typeof DESCRIPTORS["syncKubeconfigEntries"]>;
@computed get resolvedShell(): string | undefined {
return this.shell || process.env.SHELL || process.env.PTYSHELL;
}
startMainReactions() {
// open at system start-up
reaction(() => this.openAtLogin, openAtLogin => {
@@ -19,7 +19,7 @@ import joinPathsInjectable from "../../../common/path/join-paths.injectable";
import getBasenameOfPathInjectable from "../../../common/path/get-basename.injectable";
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
import spawnPtyInjectable from "../spawn-pty.injectable";
import resolvedShellInjectable from "../../../common/user-store/resolved-shell.injectable";
import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
import appNameInjectable from "../../../common/vars/app-name.injectable";
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
import emitAppEventInjectable from "../../../common/app-event-bus/emit-event.injectable";
@@ -44,7 +44,7 @@ const openLocalShellSessionInjectable = getInjectable({
isWindows: di.inject(isWindowsInjectable),
logger: di.inject(loggerInjectable),
userStore: di.inject(userStoreInjectable),
resolvedShell: di.inject(resolvedShellInjectable),
userShellSetting: di.inject(userShellSettingInjectable),
appName: di.inject(appNameInjectable),
buildVersion: di.inject(buildVersionInjectable),
modifyTerminalShellEnv: di.inject(modifyTerminalShellEnvInjectable),
@@ -14,7 +14,7 @@ import loggerInjectable from "../../../common/logger.injectable";
import createKubeJsonApiForClusterInjectable from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable";
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
import spawnPtyInjectable from "../spawn-pty.injectable";
import resolvedShellInjectable from "../../../common/user-store/resolved-shell.injectable";
import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
import appNameInjectable from "../../../common/vars/app-name.injectable";
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
import emitAppEventInjectable from "../../../common/app-event-bus/emit-event.injectable";
@@ -35,7 +35,7 @@ const openNodeShellSessionInjectable = getInjectable({
isMac: di.inject(isMacInjectable),
isWindows: di.inject(isWindowsInjectable),
logger: di.inject(loggerInjectable),
resolvedShell: di.inject(resolvedShellInjectable),
userShellSetting: di.inject(userShellSettingInjectable),
appName: di.inject(appNameInjectable),
buildVersion: di.inject(buildVersionInjectable),
createKubeJsonApiForCluster: di.inject(createKubeJsonApiForClusterInjectable),
+4 -3
View File
@@ -8,7 +8,7 @@ import type { Kubectl } from "../kubectl/kubectl";
import type WebSocket from "ws";
import { clearKubeconfigEnvVars } from "../utils/clear-kube-env-vars";
import path from "path";
import os, { userInfo } from "os";
import os from "os";
import type * as pty from "node-pty";
import { getOrInsertWith } from "../../common/utils";
import { type TerminalMessage, TerminalChannels } from "../../common/terminal/channels";
@@ -18,6 +18,7 @@ import type { SpawnPty } from "./spawn-pty.injectable";
import type { InitializableState } from "../../common/initializable-state/create";
import type { EmitAppEvent } from "../../common/app-event-bus/emit-event.injectable";
import type { Stat } from "../../common/fs/stat/stat.injectable";
import type { IComputedValue } from "mobx";
export class ShellOpenError extends Error {
constructor(message: string, options?: ErrorOptions) {
@@ -107,7 +108,7 @@ export interface ShellSessionDependencies {
readonly isWindows: boolean;
readonly isMac: boolean;
readonly logger: Logger;
readonly resolvedShell: string | undefined;
readonly userShellSetting: IComputedValue<string>;
readonly appName: string;
readonly buildVersion: InitializableState<string>;
computeShellEnvironment: ComputeShellEnvironment;
@@ -338,7 +339,7 @@ export abstract class ShellSession {
}
protected async getShellEnv() {
const shell = this.dependencies.resolvedShell || userInfo().shell;
const shell = this.dependencies.userShellSetting.get();
const result = await this.dependencies.computeShellEnvironment(shell);
const rawEnv = (() => {
if (result.callWasSuccessful) {
@@ -5,11 +5,11 @@
import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "../../../common/logger.injectable";
import { onLoadOfApplicationInjectionToken } from "../runnable-tokens/on-load-of-application-injection-token";
import os from "os";
import { unionPATHs } from "../../../common/utils/union-env-path";
import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable";
import electronAppInjectable from "../../electron-app/electron-app.injectable";
import computeShellEnvironmentInjectable from "../../utils/shell-env/compute-shell-environment.injectable";
import userShellSettingInjectable from "../../../common/user-store/shell-setting.injectable";
const setupShellInjectable = getInjectable({
id: "setup-shell",
@@ -18,6 +18,7 @@ const setupShellInjectable = getInjectable({
const logger = di.inject(loggerInjectable);
const isSnapPackage = di.inject(isSnapPackageInjectable);
const electronApp = di.inject(electronAppInjectable);
const resolvedUserShellSetting = di.inject(userShellSettingInjectable);
const computeShellEnvironment = di.inject(computeShellEnvironmentInjectable);
return {
@@ -25,7 +26,7 @@ const setupShellInjectable = getInjectable({
run: async (): Promise<void> => {
logger.info("🐚 Syncing shell environment");
const result = await computeShellEnvironment(os.userInfo().shell);
const result = await computeShellEnvironment(resolvedUserShellSetting.get());
if (!result.callWasSuccessful) {
return void logger.error(`[SHELL-SYNC]: ${result.error}`);