add app and apps icons

This commit is contained in:
olcxja 2026-09-25 18:42:03 +02:00
commit 7508811374
16 changed files with 554 additions and 7 deletions

54
src/appicon.js Normal file
View file

@ -0,0 +1,54 @@
'use strict'
const path = require('path')
const fs = require('fs')
const APP_NAME = 'PLGL'
function findPng() {
const p = path.resolve(__dirname, '..', 'renderer', 'plgl.png')
try {
fs.accessSync(p)
return p
} catch {
return null
}
}
function writeIconThemeDirs(png) {
try {
const sizes = { '16x16': 16, '32x32': 32, '48x48': 48, '256x256': 256 }
const home = process.env.HOME
if (!home) return
const base = path.join(home, '.local', 'share', 'icons')
for (const [dir, size] of Object.entries(sizes)) {
const themeDir = path.join(base, 'hicolor', dir, 'apps')
fs.mkdirSync(themeDir, { recursive: true })
fs.copyFileSync(png, path.join(themeDir, 'plgl.png'))
}
const desktopDir = path.join(home, '.local', 'share', 'applications')
fs.mkdirSync(desktopDir, { recursive: true })
const desktop = [
'[Desktop Entry]',
'Type=Application',
`Name=${APP_NAME}`,
'Comment=Portable Linux Wine Launcher',
'Exec=plgl',
`Icon=plgl`,
'Terminal=false',
'Categories=Game;'
].join('\n')
fs.writeFileSync(path.join(desktopDir, 'plgl.desktop'), desktop)
} catch {}
}
function setAppIcon(app) {
const png = findPng()
if (!png) return
try {
app.setIcon(png)
} catch {}
writeIconThemeDirs(png)
}
module.exports = { setAppIcon }