From 4b19114f62e16375753eed25a06e6d5192a1b7d9 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 16 Nov 2022 09:59:24 -0500 Subject: [PATCH] Fix not using the users configured shell for sync Signed-off-by: Sebastian Malton --- src/common/os/home-directory-path.injectable.ts | 5 ++--- .../user-store/resolved-shell.injectable.ts | 15 +++++++++++---- .../user-info.global-override-for-injectable.ts} | 10 ++++++++-- src/common/user-store/user-info.injectable.ts | 14 ++++++++++++++ src/common/user-store/user-store.ts | 6 +----- .../local-shell-session/open.injectable.ts | 4 ++-- .../node-shell-session/open.injectable.ts | 4 ++-- .../runnables/setup-shell.injectable.ts | 5 +++-- 8 files changed, 43 insertions(+), 20 deletions(-) rename src/common/{os/home-directory-path.global-override-for-injectable.ts => user-store/user-info.global-override-for-injectable.ts} (50%) create mode 100644 src/common/user-store/user-info.injectable.ts diff --git a/src/common/os/home-directory-path.injectable.ts b/src/common/os/home-directory-path.injectable.ts index b6ba1dfee0..83b4b0cdff 100644 --- a/src/common/os/home-directory-path.injectable.ts +++ b/src/common/os/home-directory-path.injectable.ts @@ -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; diff --git a/src/common/user-store/resolved-shell.injectable.ts b/src/common/user-store/resolved-shell.injectable.ts index 98c219feff..30d34f9c5c 100644 --- a/src/common/user-store/resolved-shell.injectable.ts +++ b/src/common/user-store/resolved-shell.injectable.ts @@ -3,11 +3,18 @@ * 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 resolvedShellInjectable = getInjectable({ - id: "resolved-shell", - instantiate: (di) => di.inject(userStoreInjectable).resolvedShell, +const resolvedUserShellSettingInjectable = getInjectable({ + id: "resolved-user-shell-setting", + instantiate: (di) => { + const userStore = di.inject(userStoreInjectable); + const userInfo = di.inject(userInfoInjectable); + + return computed(() => userStore.shell || userInfo.shell); + }, }); -export default resolvedShellInjectable; +export default resolvedUserShellSettingInjectable; diff --git a/src/common/os/home-directory-path.global-override-for-injectable.ts b/src/common/user-store/user-info.global-override-for-injectable.ts similarity index 50% rename from src/common/os/home-directory-path.global-override-for-injectable.ts rename to src/common/user-store/user-info.global-override-for-injectable.ts index f5869831a6..21fb26f8a9 100644 --- a/src/common/os/home-directory-path.global-override-for-injectable.ts +++ b/src/common/user-store/user-info.global-override-for-injectable.ts @@ -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", +})); diff --git a/src/common/user-store/user-info.injectable.ts b/src/common/user-store/user-info.injectable.ts new file mode 100644 index 0000000000..b096da03c5 --- /dev/null +++ b/src/common/user-store/user-info.injectable.ts @@ -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; diff --git a/src/common/user-store/user-store.ts b/src/common/user-store/user-store.ts index 9b80c4dd72..7db6127ed8 100644 --- a/src/common/user-store/user-store.ts +++ b/src/common/user-store/user-store.ts @@ -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 /* implements UserStore */ @observable syncKubeconfigEntries!: StoreType; - @computed get resolvedShell(): string | undefined { - return this.shell || process.env.SHELL || process.env.PTYSHELL; - } - startMainReactions() { // open at system start-up reaction(() => this.openAtLogin, openAtLogin => { diff --git a/src/main/shell-session/local-shell-session/open.injectable.ts b/src/main/shell-session/local-shell-session/open.injectable.ts index 3e9a09405d..e727eba962 100644 --- a/src/main/shell-session/local-shell-session/open.injectable.ts +++ b/src/main/shell-session/local-shell-session/open.injectable.ts @@ -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 resolvedUserShellSettingInjectable from "../../../common/user-store/resolved-shell.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), + resolvedShell: di.inject(resolvedUserShellSettingInjectable), appName: di.inject(appNameInjectable), buildVersion: di.inject(buildVersionInjectable), modifyTerminalShellEnv: di.inject(modifyTerminalShellEnvInjectable), diff --git a/src/main/shell-session/node-shell-session/open.injectable.ts b/src/main/shell-session/node-shell-session/open.injectable.ts index c3095522e1..101d61d223 100644 --- a/src/main/shell-session/node-shell-session/open.injectable.ts +++ b/src/main/shell-session/node-shell-session/open.injectable.ts @@ -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 resolvedUserShellSettingInjectable from "../../../common/user-store/resolved-shell.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), + resolvedShell: di.inject(resolvedUserShellSettingInjectable), appName: di.inject(appNameInjectable), buildVersion: di.inject(buildVersionInjectable), createKubeJsonApiForCluster: di.inject(createKubeJsonApiForClusterInjectable), diff --git a/src/main/start-main-application/runnables/setup-shell.injectable.ts b/src/main/start-main-application/runnables/setup-shell.injectable.ts index 6f80b225ac..6246773af1 100644 --- a/src/main/start-main-application/runnables/setup-shell.injectable.ts +++ b/src/main/start-main-application/runnables/setup-shell.injectable.ts @@ -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 resolvedUserShellSettingInjectable from "../../../common/user-store/resolved-shell.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(resolvedUserShellSettingInjectable); const computeShellEnvironment = di.inject(computeShellEnvironmentInjectable); return { @@ -25,7 +26,7 @@ const setupShellInjectable = getInjectable({ run: async (): Promise => { 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}`);