add dev rules

This commit is contained in:
olcxja 2026-09-30 19:16:52 +02:00
commit 944d8f86c2
9 changed files with 112 additions and 27 deletions

View file

@ -1,20 +1,9 @@
'use strict'
const path = require('path')
const fs = require('fs')
function findPng() {
const p = path.resolve(__dirname, '..', 'renderer', 'plwl.png')
try {
fs.accessSync(p)
return p
} catch {
return null
}
}
const { launcherIconPath } = require('./paths')
function setAppIcon(app) {
const png = findPng()
const png = launcherIconPath()
if (!png) return
try {
app.setIcon(png)

View file

@ -40,10 +40,7 @@ function createGamesService({ getWindow, onGamesChanged }) {
}
function resolveWine(game) {
const system = { id: 'system', type: 'system', label: 'System Wine' }
const wanted = game.wine === 'default' ? (library.loadSettings().defaultWine || 'system') : (game.wine || 'system')
if (!wanted || wanted === 'system') return system
return require('../wines').getWine(wanted) || system
return require('../wines').resolveWine(game.wine || 'system')
}
function handleExit(id) {

View file

@ -87,8 +87,7 @@ autoQuitWhenDone = headless // booting just to run one game -> exit when it ends
// Lives as long as the app does: shows "active in background" even when the
// window is closed, and offers running games + Quit.
function trayIconPath() {
const png = path.resolve(__dirname, '..', 'renderer', 'plwl.png')
return fs.existsSync(png) ? png : undefined
return require('./paths').launcherIconPath() || undefined
}
function createTray() {

View file

@ -49,10 +49,7 @@ function textsFor(code) {
}
function resolveWine(id) {
const system = { id: 'system', type: 'system', label: 'System Wine' }
const wanted = id === 'default' ? require('./library').loadSettings().defaultWine || 'system' : id
if (!wanted || wanted === 'system') return system
return require('./wines').getWine(wanted) || system
return require('./wines').resolveWine(id)
}
function resolvePrefix(name) {

View file

@ -114,6 +114,22 @@ function resolvePortablePath(p) {
return path.join(FILES, p)
}
// The launcher's own icon (renderer/plwl.png), used by the tray, the app
// icon and as the .desktop shortcut fallback. Cached: it never moves at
// runtime.
let launcherIcon = null
function launcherIconPath() {
if (launcherIcon === null) {
const p = path.join(APP_ROOT, 'renderer', 'plwl.png')
try {
launcherIcon = fs.existsSync(p) ? p : ''
} catch {
launcherIcon = ''
}
}
return launcherIcon || null
}
function readJson(file, fallback) {
try {
return JSON.parse(fs.readFileSync(file, 'utf8'))
@ -129,4 +145,4 @@ function writeJson(file, data) {
fs.renameSync(tmp, file)
}
module.exports = { RESOURCES, APP_ROOT, BUILD, FILES, DATA, DIRS, ensureDirs, syncBundledTranslations, readJson, writeJson, toPortablePath, resolvePortablePath }
module.exports = { RESOURCES, APP_ROOT, BUILD, FILES, DATA, DIRS, ensureDirs, syncBundledTranslations, launcherIconPath, readJson, writeJson, toPortablePath, resolvePortablePath }

View file

@ -63,8 +63,7 @@ function buildDesktopEntry(game) {
} catch {}
if (!icon) {
// fall back to the launcher icon so the shortcut is never naked
const png = path.resolve(__dirname, '..', 'renderer', 'plwl.png')
if (fs.existsSync(png)) icon = png
icon = require('./paths').launcherIconPath() || ''
}
const lines = [
'[Desktop Entry]',

View file

@ -156,6 +156,16 @@ function getDefaultWine() {
return require('./library').loadSettings().defaultWine || 'system'
}
// Resolve the wine build a run should use: 'default'/'system'/unknown all
// fall back to System Wine. Shared by the games service and the ad-hoc
// "open with" runner.
function resolveWine(id) {
const system = { id: 'system', type: 'system', label: 'System Wine' }
const wanted = id === 'default' ? getDefaultWine() : id
if (!wanted || wanted === 'system') return system
return getWine(wanted) || system
}
function setDefaultWine(id) {
const wines = getWines()
if (id !== 'system' && !wines.some(w => w.id === id)) return { ok: false, error: 'notFound' }
@ -276,4 +286,4 @@ async function importWineFolder(srcDir) {
return { ok: true, path: toPortablePath(dst), symlinksFixed }
}
module.exports = { refreshWines, getWines, getWine, setWineDisabled, getDefaultWine, setDefaultWine, deleteWine, importWineFolder, findWineBinary, detectType, fixBuildSymlinks }
module.exports = { refreshWines, getWines, getWine, resolveWine, setWineDisabled, getDefaultWine, setDefaultWine, deleteWine, importWineFolder, findWineBinary, detectType, fixBuildSymlinks }