Skip to content

Commit f0286cc

Browse files
committed
DRY things up even more
1 parent 6bde947 commit f0286cc

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -779,22 +779,15 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
779779
// Update listApiConfigMeta first to ensure UI has latest data
780780
await this.updateGlobalState("listApiConfigMeta", listApiConfig)
781781

782-
// If this mode has a saved config, use it
782+
// If this mode has a saved config, use it.
783783
if (savedConfigId) {
784-
const config = listApiConfig?.find((c) => c.id === savedConfigId)
784+
const hasConfig = !!listApiConfig.find(({ id }) => id === savedConfigId)
785785

786-
if (config?.name) {
787-
const { name: _, ...apiConfig } = await this.providerSettingsManager.activateProfile({
788-
name: config.name,
789-
})
790-
791-
await Promise.all([
792-
this.updateGlobalState("currentApiConfigName", config.name),
793-
this.updateApiConfiguration(apiConfig),
794-
])
786+
if (hasConfig) {
787+
await this.activateProviderProfile({ id: savedConfigId })
795788
}
796789
} else {
797-
// If no saved config for this mode, save current config as default
790+
// If no saved config for this mode, save current config as default.
798791
const currentApiConfigName = this.getGlobalState("currentApiConfigName")
799792

800793
if (currentApiConfigName) {

src/core/webview/webviewMessageHandler.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,13 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
8888
const currentConfigName = getGlobalState("currentApiConfigName")
8989

9090
if (currentConfigName) {
91-
const manager = provider.providerSettingsManager
92-
const hasConfig = await manager.hasConfig(currentConfigName)
93-
94-
if (!hasConfig) {
91+
if (!(await provider.providerSettingsManager.hasConfig(currentConfigName))) {
9592
// Current config name not valid, get first config in list.
96-
await updateGlobalState("currentApiConfigName", listApiConfig?.[0]?.name)
97-
98-
if (listApiConfig?.[0]?.name) {
99-
const { name: _, ...providerSettings } = await manager.activateProfile({
100-
name: listApiConfig?.[0]?.name,
101-
})
102-
103-
await Promise.all([
104-
updateGlobalState("listApiConfigMeta", listApiConfig),
105-
provider.postMessageToWebview({ type: "listApiConfig", listApiConfig }),
106-
provider.updateApiConfiguration(providerSettings),
107-
])
93+
const name = listApiConfig[0]?.name
94+
await updateGlobalState("currentApiConfigName", name)
10895

109-
await provider.postStateToWebview()
96+
if (name) {
97+
await provider.activateProviderProfile({ name })
11098
return
11199
}
112100
}

0 commit comments

Comments
 (0)