From 89cf5cc4304037e7841909a90e35c7b1620c9fa6 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Wed, 4 Dec 2024 23:53:38 +0530 Subject: [PATCH] Use light and dark mode icons (#64) Fixes https://github.com/microsoft/vscode-python-environments/issues/52 --- files/dark_mode_icon.svg | 1 + files/light_mode_icon.svg | 1 + src/features/terminal/terminalManager.ts | 15 ++++++--------- src/managers/sysPython/pipManager.ts | 7 +++++-- src/managers/sysPython/sysPythonManager.ts | 7 +++++-- src/managers/sysPython/utils.ts | 5 ++++- src/managers/sysPython/venvManager.ts | 10 +++++++--- src/managers/sysPython/venvUtils.ts | 5 ++++- 8 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 files/dark_mode_icon.svg create mode 100644 files/light_mode_icon.svg diff --git a/files/dark_mode_icon.svg b/files/dark_mode_icon.svg new file mode 100644 index 0000000..c3ec6ec --- /dev/null +++ b/files/dark_mode_icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/files/light_mode_icon.svg b/files/light_mode_icon.svg new file mode 100644 index 0000000..a24a66b --- /dev/null +++ b/files/light_mode_icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/features/terminal/terminalManager.ts b/src/features/terminal/terminalManager.ts index 21a1a72..8e4b761 100644 --- a/src/features/terminal/terminalManager.ts +++ b/src/features/terminal/terminalManager.ts @@ -21,7 +21,7 @@ import { terminals, withProgress, } from '../../common/window.apis'; -import { IconPath, PythonEnvironment, PythonProject, PythonTerminalOptions } from '../../api'; +import { PythonEnvironment, PythonProject, PythonTerminalOptions } from '../../api'; import { getActivationCommand, getDeactivationCommand, isActivatableEnvironment } from '../common/activation'; import { showErrorMessage } from '../../common/errors/utils'; import { quoteArgs } from '../execution/execUtils'; @@ -29,13 +29,7 @@ import { createDeferred } from '../../common/utils/deferred'; import { traceError, traceVerbose } from '../../common/logging'; import { getConfiguration } from '../../common/workspace.apis'; import { EnvironmentManagers } from '../../internal.api'; - -function getIconPath(i: IconPath | undefined): IconPath | undefined { - if (i instanceof Uri) { - return i.fsPath.endsWith('__icon__.py') ? undefined : i; - } - return i; -} +import { EXTENSION_ROOT_DIR } from '../../common/constants'; const SHELL_INTEGRATION_TIMEOUT = 500; // 0.5 seconds const SHELL_INTEGRATION_POLL_INTERVAL = 100; // 0.1 seconds @@ -297,7 +291,10 @@ export class TerminalManagerImpl implements TerminalManager { env: options.env, strictEnv: options.strictEnv, message: options.message, - iconPath: options.iconPath ?? getIconPath(environment.iconPath), + iconPath: options.iconPath ?? { + light: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'light_mode_icon.svg')), + dark: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'dark_mode_icon.svg')), + }, hideFromUser: options.hideFromUser, color: options.color, location: options.location, diff --git a/src/managers/sysPython/pipManager.ts b/src/managers/sysPython/pipManager.ts index 5123e4c..497f529 100644 --- a/src/managers/sysPython/pipManager.ts +++ b/src/managers/sysPython/pipManager.ts @@ -12,10 +12,10 @@ import { PythonEnvironmentApi, } from '../../api'; import { installPackages, refreshPackages, uninstallPackages } from './utils'; -import { EXTENSION_ROOT_DIR } from '../../common/constants'; import { Disposable } from 'vscode-jsonrpc'; import { getProjectInstallable } from './venvUtils'; import { VenvManager } from './venvManager'; +import { EXTENSION_ROOT_DIR } from '../../common/constants'; function getChanges(before: Package[], after: Package[]): { kind: PackageChangeKind; pkg: Package }[] { const changes: { kind: PackageChangeKind; pkg: Package }[] = []; @@ -43,7 +43,10 @@ export class PipPackageManager implements PackageManager, Disposable { this.displayName = 'Pip'; this.description = 'This package manager for python installs using pip.'; this.tooltip = new MarkdownString('This package manager for python installs using `pip`.'); - this.iconPath = Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', '__icon__.py')); + this.iconPath = { + light: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'light_mode_icon.svg')), + dark: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'dark_mode_icon.svg')), + }; } readonly name: string; readonly displayName?: string; diff --git a/src/managers/sysPython/sysPythonManager.ts b/src/managers/sysPython/sysPythonManager.ts index 33ba168..35cdea8 100644 --- a/src/managers/sysPython/sysPythonManager.ts +++ b/src/managers/sysPython/sysPythonManager.ts @@ -24,10 +24,10 @@ import { setSystemEnvForGlobal, setSystemEnvForWorkspace, } from './utils'; -import { EXTENSION_ROOT_DIR } from '../../common/constants'; import { NativePythonFinder } from '../common/nativePythonFinder'; import { createDeferred, Deferred } from '../../common/utils/deferred'; import { getLatest } from '../common/utils'; +import { EXTENSION_ROOT_DIR } from '../../common/constants'; export class SysPythonManager implements EnvironmentManager { private collection: PythonEnvironment[] = []; @@ -57,7 +57,10 @@ export class SysPythonManager implements EnvironmentManager { this.preferredPackageManagerId = 'ms-python.python:pip'; this.description = 'Manages Global python installs'; this.tooltip = new MarkdownString('$(globe) Python Environment Manager', true); - this.iconPath = Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', '__icon__.py')); + this.iconPath = { + light: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'light_mode_icon.svg')), + dark: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'dark_mode_icon.svg')), + }; } private _initialized: Deferred | undefined; diff --git a/src/managers/sysPython/utils.ts b/src/managers/sysPython/utils.ts index 7a79fb8..cffcd6b 100644 --- a/src/managers/sysPython/utils.ts +++ b/src/managers/sysPython/utils.ts @@ -196,7 +196,10 @@ function getPythonInfo(env: NativeEnvInfo): PythonEnvironmentInfo { version: env.version, description: env.executable, environmentPath: Uri.file(env.executable), - iconPath: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', '__icon__.py')), + iconPath: { + light: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'light_mode_icon.svg')), + dark: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'dark_mode_icon.svg')), + }, sysPrefix: env.prefix, execInfo: { run: { diff --git a/src/managers/sysPython/venvManager.ts b/src/managers/sysPython/venvManager.ts index 438bfa1..f9efaae 100644 --- a/src/managers/sysPython/venvManager.ts +++ b/src/managers/sysPython/venvManager.ts @@ -1,4 +1,4 @@ -import { ProgressLocation, Uri, window, LogOutputChannel, EventEmitter, MarkdownString } from 'vscode'; +import { ProgressLocation, Uri, LogOutputChannel, EventEmitter, MarkdownString } from 'vscode'; import { CreateEnvironmentScope, DidChangeEnvironmentEventArgs, @@ -33,6 +33,7 @@ import { NativePythonFinder } from '../common/nativePythonFinder'; import { ENVS_EXTENSION_ID, EXTENSION_ROOT_DIR } from '../../common/constants'; import { createDeferred, Deferred } from '../../common/utils/deferred'; import { getLatest, sortEnvironments } from '../common/utils'; +import { withProgress } from '../../common/window.apis'; export class VenvManager implements EnvironmentManager { private collection: PythonEnvironment[] = []; @@ -63,7 +64,10 @@ export class VenvManager implements EnvironmentManager { this.description = 'Manages virtual environments created using venv'; this.tooltip = new MarkdownString('Manages virtual environments created using `venv`', true); this.preferredPackageManagerId = 'ms-python.python:pip'; - this.iconPath = Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', '__icon__.py')); + this.iconPath = { + light: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'light_mode_icon.svg')), + dark: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'dark_mode_icon.svg')), + }; } private _initialized: Deferred | undefined; @@ -145,7 +149,7 @@ export class VenvManager implements EnvironmentManager { } private async internalRefresh(scope: RefreshEnvironmentsScope, hardRefresh: boolean, title: string): Promise { - await window.withProgress( + await withProgress( { location: ProgressLocation.Window, title, diff --git a/src/managers/sysPython/venvUtils.ts b/src/managers/sysPython/venvUtils.ts index f591153..63cd3cb 100644 --- a/src/managers/sysPython/venvUtils.ts +++ b/src/managers/sysPython/venvUtils.ts @@ -129,7 +129,10 @@ function getPythonInfo(env: NativeEnvInfo): PythonEnvironmentInfo { version: env.version, description: env.executable, environmentPath: Uri.file(env.executable), - iconPath: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', '__icon__.py')), + iconPath: { + light: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'light_mode_icon.svg')), + dark: Uri.file(path.join(EXTENSION_ROOT_DIR, 'files', 'dark_mode_icon.svg')), + }, sysPrefix: env.prefix, execInfo: { run: {