Skip to content

Commit 7340ebf

Browse files
committed
Move web configuration format converters to the utils directory and update dependent import paths
- move `apps/editor/src/views/utils/web-configuration-format-converters.ts` to `apps/editor/src/utils`
1 parent 27db1e5 commit 7340ebf

8 files changed

Lines changed: 148 additions & 107 deletions

File tree

‎apps/editor/src/services/websocket-manager.ts‎

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { DEFAULT_PORT, SECURITY_TOKENS } from '@shared/constants/websocket'
1414
import { dictionary } from '@shared/constants/dictionary'
1515
import { Logger } from '@shared/utils/logger'
1616
import { WebConfiguration } from '@shared/types/web-configuration'
17-
import { ConfigWebConfigurationFormat } from '@/views/utils/web-configuration-format-converters'
17+
import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
1818
import { LAST_SELECTED_BROWSER_ID_STATE_KEY } from '@/constants/state-keys'
1919
import { ApplyChatResponseCommandArgs } from '@/commands/apply-chat-response-command/response-processor'
2020
import { WebPromptType } from '@shared/types/prompt-types'
@@ -81,11 +81,15 @@ export class WebSocketManager {
8181
)
8282

8383
try {
84-
const spawned = child_process.spawn(process.execPath, [server_script_path], {
85-
detached: true,
86-
stdio: 'ignore',
87-
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' }
88-
})
84+
const spawned = child_process.spawn(
85+
process.execPath,
86+
[server_script_path],
87+
{
88+
detached: true,
89+
stdio: 'ignore',
90+
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' }
91+
}
92+
)
8993

9094
if (spawned.pid) {
9195
spawned.unref()
@@ -115,24 +119,25 @@ export class WebSocketManager {
115119
let attempts = 0
116120

117121
const check = () => {
118-
const req = http.get(
119-
`http://localhost:${this.port}/health`,
120-
(res) => {
121-
if (res.statusCode === 200) {
122-
resolve()
123-
} else {
124-
retry()
125-
}
122+
const req = http.get(`http://localhost:${this.port}/health`, (res) => {
123+
if (res.statusCode === 200) {
124+
resolve()
125+
} else {
126+
retry()
126127
}
127-
)
128+
})
128129
req.on('error', retry)
129130
req.end()
130131
}
131132

132133
const retry = () => {
133134
attempts++
134135
if (attempts >= retries) {
135-
reject(new Error(`WebSocket server did not become ready after ${retries} attempts`))
136+
reject(
137+
new Error(
138+
`WebSocket server did not become ready after ${retries} attempts`
139+
)
140+
)
136141
} else {
137142
setTimeout(check, interval_ms)
138143
}
@@ -369,7 +374,9 @@ export class WebSocketManager {
369374
return false
370375
}
371376

372-
const web_configuration = web_configurations.find((p) => p.name == params.web_configuration_name)
377+
const web_configuration = web_configurations.find(
378+
(p) => p.name == params.web_configuration_name
379+
)
373380
if (!web_configuration) {
374381
return false
375382
}
@@ -475,7 +482,8 @@ export class WebSocketManager {
475482
const ai_studio_user_id = config.get<number | null>('aiStudioUserId')
476483
const reuse_last_tab = config.get<boolean>('reuseLastTab', false)
477484

478-
const chatbot = CHATBOTS[params.web_configuration.chatbot as keyof typeof CHATBOTS]
485+
const chatbot =
486+
CHATBOTS[params.web_configuration.chatbot as keyof typeof CHATBOTS]
479487
let url: string
480488
if (params.web_configuration.chatbot == 'AI Studio') {
481489
let base_url = chatbot.url
@@ -508,7 +516,10 @@ export class WebSocketManager {
508516
gemini_user_number !== null
509517
) {
510518
url = `https://gemini.google.com/u/${gemini_user_number}`
511-
} else if (chatbot.supports_url_override && params.web_configuration.new_url) {
519+
} else if (
520+
chatbot.supports_url_override &&
521+
params.web_configuration.new_url
522+
) {
512523
try {
513524
const original_domain = new URL(chatbot.url).hostname
514525
const new_domain = new URL(params.web_configuration.new_url).hostname

apps/editor/src/views/utils/web-configuration-format-converters.ts renamed to apps/editor/src/utils/web-configuration-format-converters.ts

File renamed without changes.

‎apps/editor/src/views/actions/create-web-configuration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode'
22
import { dictionary } from '@shared/constants/dictionary'
33
import { CHATBOTS } from '@shared/constants/chatbots'
4-
import { ConfigWebConfigurationFormat } from '../utils/web-configuration-format-converters'
4+
import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
55
import { generate_unique_name } from '../utils/generate-unique-name'
66

77
export const create_web_configuration = async (params: {

‎apps/editor/src/views/actions/delete-web-configuration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22
import { dictionary } from '@shared/constants/dictionary'
3-
import { ConfigWebConfigurationFormat } from '@/views/utils/web-configuration-format-converters'
3+
import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
44

55
export const delete_web_configuration = async (params: {
66
name: string

‎apps/editor/src/views/actions/duplicate-web-configuration.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as vscode from 'vscode'
22
import { dictionary } from '@shared/constants/dictionary'
3-
import { ConfigWebConfigurationFormat } from '@/views/utils/web-configuration-format-converters'
3+
import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
44
import { generate_unique_name } from '../utils/generate-unique-name'
55

6-
76
export const duplicate_web_configuration = async (params: {
87
name: string
98
}): Promise<void> => {
@@ -12,7 +11,9 @@ export const duplicate_web_configuration = async (params: {
1211
const current_web_configurations =
1312
config.get<ConfigWebConfigurationFormat[]>('webConfigurations', []) || []
1413

15-
const original_index = current_web_configurations.findIndex((c, i) => (c.name ?? `unnamed-${i}`) === original_name)
14+
const original_index = current_web_configurations.findIndex(
15+
(c, i) => (c.name ?? `unnamed-${i}`) === original_name
16+
)
1617

1718
if (original_index == -1) {
1819
vscode.window.showErrorMessage(
@@ -21,7 +22,8 @@ export const duplicate_web_configuration = async (params: {
2122
return
2223
}
2324

24-
const web_configuration_to_duplicate = current_web_configurations[original_index]
25+
const web_configuration_to_duplicate =
26+
current_web_configurations[original_index]
2527

2628
const new_name = generate_unique_name(
2729
web_configuration_to_duplicate.name || 'unnamed',
@@ -34,7 +36,11 @@ export const duplicate_web_configuration = async (params: {
3436
}
3537

3638
const updated_web_configurations = [...current_web_configurations]
37-
updated_web_configurations.splice(original_index + 1, 0, duplicated_web_configuration)
39+
updated_web_configurations.splice(
40+
original_index + 1,
41+
0,
42+
duplicated_web_configuration
43+
)
3844

3945
try {
4046
await config.update('webConfigurations', updated_web_configurations, true)

‎apps/editor/src/views/actions/update-web-configuration.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { WebConfiguration } from '@shared/types/web-configuration'
44
import {
55
ConfigWebConfigurationFormat,
66
ui_web_configuration_to_config_format
7-
} from '../utils/web-configuration-format-converters'
7+
} from '@/utils/web-configuration-format-converters'
88
import { generate_unique_name } from '../utils/generate-unique-name'
99
import { are_web_configurations_equal } from '../utils/are-web-configurations-equal'
1010

@@ -34,7 +34,9 @@ export const update_web_configuration = async (params: {
3434
return { success: false, has_changes: false }
3535
}
3636

37-
const final_updated_web_configuration = { ...params.updated_web_configuration }
37+
const final_updated_web_configuration = {
38+
...params.updated_web_configuration
39+
}
3840

3941
const has_changes = !are_web_configurations_equal(
4042
params.updating_web_configuration,
@@ -48,12 +50,15 @@ export const update_web_configuration = async (params: {
4850
if (params.origin == 'cancel') {
4951
const save_changes_button = 'Save'
5052
const result = await vscode.window.showWarningMessage(
51-
dictionary.information_message.CONFIRM_SAVE_CHANGES_TO_ITEM('web configuration'),
53+
dictionary.information_message.CONFIRM_SAVE_CHANGES_TO_ITEM(
54+
'web configuration'
55+
),
5256
{
5357
modal: true,
54-
detail: dictionary.information_message.UNSAVED_CHANGES_TO_ITEM_WILL_BE_LOST(
55-
'web configuration'
56-
)
58+
detail:
59+
dictionary.information_message.UNSAVED_CHANGES_TO_ITEM_WILL_BE_LOST(
60+
'web configuration'
61+
)
5762
},
5863
save_changes_button
5964
)
@@ -75,9 +80,8 @@ export const update_web_configuration = async (params: {
7580
)
7681

7782
const updated_web_configurations = [...current_web_configurations]
78-
updated_web_configurations[web_configuration_index] = ui_web_configuration_to_config_format(
79-
updated_ui_web_configuration
80-
)
83+
updated_web_configurations[web_configuration_index] =
84+
ui_web_configuration_to_config_format(updated_ui_web_configuration)
8185

8286
await config.update(
8387
'webConfigurations',

0 commit comments

Comments
 (0)