refactor(platform): move choosePath out of settings (#3594)

choosePath, a thin wrapper over the platform file/folder dialog, lived in features/settings/languages/api.ts, so vcs/RevisionBrowser imported the settings feature to open a folder picker. It moves to platform/choosePath.ts unchanged (the dialog module still loads lazily). No behaviour change.

Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
This commit is contained in:
Mr0Bread
2026-11-16 04:15:46 +08:00
committed by GitHub
parent feb261d172
commit 41951e2895
10 changed files with 31 additions and 25 deletions
@@ -6,7 +6,8 @@ import { isCancelled } from "@/platform/ipc";
import { useId, useMemo, useState } from "react";
import { Dialog, IconButton, Input, Select, Spinner, type SelectOption, T } from "@/ui";
import { Icon, type IconName } from "@/ui/icons";
import { choosePath, createVenv, pythonInterpreter, rememberSdk, type Sdk, type VenvTool } from "./api";
import { createVenv, pythonInterpreter, rememberSdk, type Sdk, type VenvTool } from "./api";
import { choosePath } from "@/platform/choosePath";
import { tildify, useDetected } from "./components";
import styles from "./Sdk.module.css";
import { tx } from "@/platform/i18n";
@@ -6,7 +6,8 @@ import { useEffect, useId, useMemo, useState } from "react";
import { call, commands, isCancelled, isTauri, nextRequestId, type JdkReleases, type Sdk } from "@/platform/ipc";
import { downloadJdk, TEMURIN, type JdkDownload } from "@/platform/jdk";
import { Dialog, IconButton, Input, ProgressBar, Select, type SelectOption, T } from "@/ui";
import { choosePath, rememberSdk } from "./api";
import { rememberSdk } from "./api";
import { choosePath } from "@/platform/choosePath";
import styles from "./Sdk.module.css";
import { tx } from "@/platform/i18n";
@@ -4,7 +4,7 @@ import { IconButton, Input } from "@/ui";
import { Row, Section, Select, Toggle } from "../components/Form";
import { useSetting } from "../components/context";
import { DEFAULT_LANGUAGES } from "@/platform/languageSettings";
import { choosePath } from "./api";
import { choosePath } from "@/platform/choosePath";
import styles from "./Sdk.module.css";
const names: Record<string, string> = {
@@ -11,7 +11,7 @@ import { call, commands, type Sdk } from "@/platform/ipc";
import { IconButton, Input, type SelectOption, T } from "@/ui";
import { JAVA_LANGUAGE_LEVELS, PHP_LANGUAGE_LEVELS } from "@/platform/languageSettings";
import { GlobListEditor, Row, Section, Select, Toggle } from "../components/Form";
import { choosePath } from "./api";
import { choosePath } from "@/platform/choosePath";
import { usePageContext, useSetting } from "../components/context";
import { SdkField, tildify, useDetected, useJdtlsJdk } from "./components";
import styles from "./Sdk.module.css";
@@ -61,7 +61,8 @@ import {
} from "@/platform/languageSettings";
import { initProjectRoots, useDetectedRoots } from "@/platform/projectRoots";
import { Row, Section } from "../components/Form";
import { choosePath, detectSdks, useSdks, type SdkKind } from "./api";
import { detectSdks, useSdks, type SdkKind } from "./api";
import { choosePath } from "@/platform/choosePath";
import { DownloadJdkDialog } from "./DownloadJdkDialog";
import { SdkField, tildify, useDetected, useJdtlsJdk, useProjectSetting } from "./components";
import styles from "./Sdk.module.css";
-17
View File
@@ -169,20 +169,3 @@ export function refreshContainerPython(): Promise<ContainerPython | null> {
export function phpLanguageLevel(path: string): Promise<PhpLanguageLevels | null> {
return isTauri() ? call(commands.sdkPhpLanguageLevel(path)) : Promise.resolve(null);
}
/** File / folder chooser (Tauri dialog); null when cancelled or outside Tauri. */
export async function choosePath(opts: {
directory: boolean;
title: string;
defaultPath?: string;
}): Promise<string | null> {
if (!isTauri()) return null;
const { open } = await import("@/platform/dialog");
const picked = await open({
directory: opts.directory,
multiple: false,
title: opts.title,
defaultPath: opts.defaultPath || undefined,
});
return (Array.isArray(picked) ? picked[0] : picked) ?? null;
}
@@ -6,7 +6,8 @@ import { useProject } from "@/platform/project";
import { call, commands, isTauri } from "@/platform/ipc";
import { tx } from "@/platform/i18n";
import { useSetting } from "../components/context";
import { choosePath, detectSdks, useSdks, type Sdk, type SdkKind } from "./api";
import { detectSdks, useSdks, type Sdk, type SdkKind } from "./api";
import { choosePath } from "@/platform/choosePath";
import { DownloadJdkDialog } from "./DownloadJdkDialog";
import styles from "./Sdk.module.css";
+1 -1
View File
@@ -48,7 +48,7 @@ import {
toggleGroupServer,
updateMapping,
} from "./deploymentModel";
import { choosePath } from "../languages/api";
import { choosePath } from "@/platform/choosePath";
import { BUILD_GROUP } from "./execution";
import type { PageSpec } from "./spec";
import { parseSshPort, sshTestRemedy } from "./sshConnection";
+1 -1
View File
@@ -26,7 +26,7 @@ import { currentRepoRoot, useVcs } from "./store";
import { repositoryPath } from "./repositoryPaths";
import { languageFor, viewerBase } from "./cm";
import styles from "./GitLog.module.css";
import { choosePath } from "@/features/settings/languages/api";
import { choosePath } from "@/platform/choosePath";
import { openLogTab } from "./logStore";
interface RevisionData {
+19
View File
@@ -0,0 +1,19 @@
import { isTauri } from "@/platform/ipc";
/** File / folder chooser (Tauri dialog); null when cancelled or outside Tauri. */
export async function choosePath(opts: {
directory: boolean;
title: string;
defaultPath?: string;
}): Promise<string | null> {
if (!isTauri()) return null;
// Lazy on purpose: loading platform/dialog starts its GTK capability probe at module load.
const { open } = await import("@/platform/dialog");
const picked = await open({
directory: opts.directory,
multiple: false,
title: opts.title,
defaultPath: opts.defaultPath || undefined,
});
return (Array.isArray(picked) ? picked[0] : picked) ?? null;
}