MCPcopy Index your code
hub / github.com/ZToolsCenter/ZTools / selectAvatar

Method selectAvatar

src/main/api/renderer/system.ts:213–240  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

211 }
212
213 public async selectAvatar(): Promise<any> {
214 try {
215 const result = await openDialog(
216 this.mainWindow!,
217 {
218 title: '选择头像图片',
219 filters: [{ name: '图片文件', extensions: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg'] }],
220 properties: ['openFile']
221 },
222 '未选择文件'
223 )
224 if (!result.success) {
225 return result
226 }
227 const originalPath = result.data!.filePaths[0]
228 const ext = path.extname(originalPath)
229 const fileName = `avatar${ext}`
230
231 await fs.mkdir(AVATAR_DIR, { recursive: true })
232 const avatarPath = path.join(AVATAR_DIR, fileName)
233 await fs.copyFile(originalPath, avatarPath)
234
235 return { success: true, path: pathToFileURL(avatarPath).href }
236 } catch (error: unknown) {
237 console.error('[System] 选择头像失败:', error)
238 return { success: false, error: error instanceof Error ? error.message : '未知错误' }
239 }
240 }
241
242 private async checkFilePaths(
243 paths: string[]

Callers 2

setupIPCMethod · 0.95
setupIPCMethod · 0.80

Calls 1

openDialogFunction · 0.90

Tested by

no test coverage detected