MCPcopy
hub / github.com/ZToolsCenter/ZTools / registerIconProtocolForSession

Function registerIconProtocolForSession

src/main/core/iconProtocol.ts:114–143  ·  view source on GitHub ↗
(targetSession: Electron.Session)

Source from the content-addressed store, hash-verified

112 * 供内置插件使用(外部插件不需要访问应用图标)
113 */
114export function registerIconProtocolForSession(targetSession: Electron.Session): void {
115 if (targetSession.protocol.isProtocolHandled('ztools-icon')) {
116 return
117 }
118
119 targetSession.protocol.handle('ztools-icon', async (request) => {
120 try {
121 const urlPath = request.url.replace('ztools-icon://', '')
122 const iconPath = decodeURIComponent(urlPath)
123
124 // 命中内存缓存:刷新 LRU 并返回
125 const cached = iconMemoryCache.get(iconPath)
126 if (cached) {
127 setIconCache(iconPath, cached)
128 return createIconResponse(cached)
129 }
130
131 // 未命中:通过串行队列提取图标
132 const buffer = await extractIconQueued(iconPath)
133
134 // 写入内存缓存
135 setIconCache(iconPath, buffer)
136
137 return createIconResponse(buffer)
138 } catch (error) {
139 console.error('[Main] 图标提取失败:', error)
140 return new Response('Icon Error', { status: 404 })
141 }
142 })
143}

Callers 2

index.tsFile · 0.90
setupPluginSessionMethod · 0.90

Calls 4

setIconCacheFunction · 0.85
createIconResponseFunction · 0.85
extractIconQueuedFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected