Skip to content

Commit 940275b

Browse files
committed
Refine the type definitions
1 parent 0ef2cd7 commit 940275b

File tree

8 files changed

+87
-44
lines changed

8 files changed

+87
-44
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"@eslint/eslintrc": "^3.3.1",
7575
"@eslint/js": "^9.36.0",
7676
"@playwright/test": "^1.55.1",
77+
"@types/lodash": "^4.17.20",
7778
"@typescript-eslint/eslint-plugin": "^8.44.1",
7879
"@typescript-eslint/parser": "^8.44.1",
7980
"@vitejs/plugin-vue": "^6.0.1",

src/main/IPCs.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { commandSelectionInvoke, mcpServersProcessCallback } from './index'
2828
import { getCachedText } from './aid/utils'
2929
import { McpClientResponse, CommandResponse, McpInitResponse } from './types'
3030

31+
import { IpcFileTransferRequest, IpcFileTransferResponse } from '@/types/ipc'
32+
3133
const handlerRegistry = new Map<string, Function>()
3234

3335
interface ManifestResponse {
@@ -189,28 +191,39 @@ export default class IPCs {
189191
return dialogResult
190192
})
191193

192-
ipcMain.on('msgFileTransferRequest', async (event: IpcMainEvent, { name, data }) => {
193-
try {
194-
const buffer = Buffer.from(data)
195-
const saveOption = Constants.getDxtSource(name)
196-
const filePath = saveOption.mcpbPath
197-
const dirPath = saveOption.outputDir
198-
if (!existsSync(dirPath)) {
199-
mkdirSync(dirPath, { recursive: true })
194+
ipcMain.on(
195+
'msgFileTransferRequest',
196+
async (event: IpcMainEvent, { name, data }: IpcFileTransferRequest) => {
197+
try {
198+
const buffer = Buffer.from(data)
199+
const saveOption = Constants.getDxtSource(name)
200+
const filePath = saveOption.mcpbPath
201+
const dirPath = saveOption.outputDir
202+
if (!existsSync(dirPath)) {
203+
mkdirSync(dirPath, { recursive: true })
204+
}
205+
console.log('MCP bundle to be saved in: ', filePath)
206+
207+
writeFileSync(filePath, buffer, { encoding: null })
208+
209+
console.log(saveOption)
210+
await unpackDxt(saveOption)
211+
// console.log(getManifest(dirPath))
212+
213+
event.reply('msgFileTransferResponse', {
214+
name,
215+
success: true,
216+
path: saveOption.outputDir
217+
} as IpcFileTransferResponse)
218+
} catch (err) {
219+
event.reply('msgFileTransferResponse', {
220+
name,
221+
success: false,
222+
reason: err.message
223+
} as IpcFileTransferResponse)
200224
}
201-
console.log('MCP bundle to be saved in: ', filePath)
202-
203-
writeFileSync(filePath, buffer, { encoding: null })
204-
205-
console.log(saveOption)
206-
await unpackDxt(saveOption)
207-
// console.log(getManifest(dirPath))
208-
209-
event.reply('msgFileTransferResponse', { name, success: true, path: saveOption.outputDir })
210-
} catch (err) {
211-
event.reply('msgFileTransferResponse', { name, success: false, reason: err.message })
212225
}
213-
})
226+
)
214227

215228
ipcMain.on(
216229
'msgCommandSelectionResult',

src/renderer/components/common/ConfigDxtCard.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const props = defineProps({
3232
const { modelValue: metadata } = props
3333
const { config: manifest } = metadata
3434
35-
const showPassword = reactive({})
35+
const showPassword = reactive<Record<string, boolean>>({})
3636
37-
function toggleShowPassword(key) {
37+
function toggleShowPassword(key: string) {
3838
showPassword[key] = !showPassword[key]
3939
}
4040

src/renderer/components/common/ConfigStdioCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const stdioStore = useStdioStore()
88
99
const editDialog = ref(false)
1010
11-
const showPassword = reactive({})
11+
const showPassword = reactive<Record<string, boolean>>({})
1212
1313
const props = defineProps({
1414
modelValue: {

src/renderer/store/snackbar.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
11
import { defineStore } from 'pinia'
22

3+
type SnackbarType = 'error' | 'success' | 'info' | 'warning' | 'unknown'
4+
5+
interface SnackbarState {
6+
isShow: boolean
7+
message: string
8+
type: SnackbarType
9+
}
10+
311
export const useSnackbarStore = defineStore('snackbarStore', {
4-
state: () => ({
5-
isShow: false,
6-
message: '',
7-
type: ''
8-
}),
12+
state: () =>
13+
({
14+
isShow: false,
15+
message: '',
16+
type: 'unknown'
17+
}) as SnackbarState,
918

1019
actions: {
11-
showMessage(message, type = '') {
20+
showMessage(message: string, type: SnackbarType = 'unknown') {
1221
console.log(message)
1322
this.isShow = true
1423
this.message = message
1524
this.type = type
1625
},
1726

18-
showErrorMessage(message) {
27+
showErrorMessage(message: string) {
1928
this.showMessage(message, 'error')
2029
},
21-
showSuccessMessage(message) {
30+
showSuccessMessage(message: string) {
2231
this.showMessage(message, 'success')
2332
},
24-
showInfoMessage(message) {
33+
showInfoMessage(message: string) {
2534
this.showMessage(message, 'info')
2635
},
27-
showWarningMessage(message) {
36+
showWarningMessage(message: string) {
2837
this.showMessage(message, 'warning')
2938
},
3039
getIcon() {
3140
const icon = {
3241
info: 'mdi-information',
3342
success: 'mdi-check-circle',
3443
error: 'mdi-alert-circle',
35-
warning: 'mdi-alert'
44+
warning: 'mdi-alert',
45+
unknown: 'mdi-help-circle-outline'
3646
}
3747

3848
return icon[this.type]

src/renderer/utils/index.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
SamplingResponse,
1010
ElicitResponse,
1111
CommandResponse,
12-
McpInitResponse
12+
McpInitResponse,
13+
IpcFileTransferRequest,
14+
IpcFileTransferResponse
1315
} from '@/types/ipc'
1416

1517
function isValidValue(value: any): boolean {
@@ -119,19 +121,22 @@ export const ElicitationTransfer = {
119121
}
120122

121123
class File {
122-
static async sendFileToMainRequest(file: { name: string; data: ArrayBuffer }): Promise<void> {
124+
static async sendFileToMainRequest(file: IpcFileTransferRequest): Promise<void> {
123125
await window.mainApi.send('msgFileTransferRequest', file)
124126
}
125-
static async sendFileToMainResponse(count: number): Promise<void> {
126-
const results: any = []
127+
static async sendFileToMainResponse(count: number): Promise<IpcFileTransferResponse[]> {
128+
const results: IpcFileTransferResponse[] = []
127129
let completedCount = 0
128-
window.mainApi.on('msgFileTransferResponse', (_event, result) => {
129-
results.push(result)
130-
completedCount++
131-
if (completedCount === count) {
132-
console.log('All done', results)
130+
window.mainApi.on(
131+
'msgFileTransferResponse',
132+
(_event: Event, result: IpcFileTransferResponse) => {
133+
results.push(result)
134+
completedCount++
135+
if (completedCount === count) {
136+
console.log('All done', results)
137+
}
133138
}
134-
})
139+
)
135140
return results
136141
}
137142
}

src/types/ipc.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ export type IpcMcpInitRequest = {
4444
}
4545

4646
export type IpcMcpInitRequestCallback = (_event: Event, _progress: IpcMcpInitRequest) => void
47+
48+
export type IpcFileTransferRequest = { name: string; data: ArrayBuffer }
49+
50+
export type IpcFileTransferResponse =
51+
| { name: string; success: false; reason: string }
52+
| { name; success: true; path: string }

0 commit comments

Comments
 (0)