46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
const fs = require('fs')
|
|
const p = 'E:/SodiumPet/WorkPlace/v0.1.1/src/main/index.ts'
|
|
let c = fs.readFileSync(p, 'utf8')
|
|
|
|
// 1) helper:取表情包作为窗口图标
|
|
const anchor = 'function appIcon(): NativeImage | undefined {'
|
|
if (!c.includes(anchor)) {
|
|
console.log('MISS appIcon')
|
|
process.exit(1)
|
|
}
|
|
const helper = `function stickerIcon(name: string, size = 64): NativeImage | undefined {
|
|
try {
|
|
const p = path.join(bundledDir('stickers'), name)
|
|
if (fs.existsSync(p)) return nativeImage.createFromPath(p).resize({ width: size, height: size })
|
|
} catch {
|
|
/* 忽略 */
|
|
}
|
|
return undefined
|
|
}
|
|
|
|
function appIcon(): NativeImage | undefined {`
|
|
c = c.replace(anchor, helper)
|
|
|
|
// 2) 按出现顺序给每个窗口分配表情包图标
|
|
const mapping = [
|
|
'1.0.png', // 主窗口(桌宠)
|
|
'2.0.png', // 气泡
|
|
'3.0.png', // 右键底栏
|
|
'20.0.png', // 音乐
|
|
'9.0.png', // 歌词浮窗
|
|
'23.1.png', // 编辑器
|
|
'4.0.png', // 详细面板
|
|
'16.0.png', // 资料库
|
|
'8.0.png', // 对话条
|
|
'5.0.png' // 面板
|
|
]
|
|
let idx = 0
|
|
c = c.replace(/= new BrowserWindow\(\{/g, (m) => {
|
|
const file = mapping[idx] ?? '1.0.png'
|
|
idx++
|
|
return `${m} icon: stickerIcon('${file}'),`
|
|
})
|
|
console.log('windows iconified:', idx)
|
|
|
|
fs.writeFileSync(p, c, 'utf8')
|