better installer and portable mode

This commit is contained in:
olcxja 2026-09-25 21:15:17 +02:00
commit 53a02cc7da
6 changed files with 97 additions and 79 deletions

View file

@ -24,14 +24,19 @@ npm start
## Building & installing
`./build.sh` produces `build/PLWL-<version>.tar.gz`: the Electron runtime with the whole app (code, renderer and bundled `files/`) packed into `electron/resources/app.asar`, plus a `plwl` launcher, a `plwl.desktop` template and `install.sh`:
`./build.sh` produces `build/PLWL-<version>.tar.gz`: the Electron runtime renamed to `olcxja.plwl/` (binary `olcxja.plwl/olcxja.plwl`) with the whole app (code, renderer and bundled `files/`) packed into `olcxja.plwl/resources/app.asar`, plus the `olcxja.plwl.png` icon, `install.sh` and `createshortcut.sh`:
```bash
tar -xzf PLWL-<version>.tar.gz
cd PLWL
./install.sh # copies to ~/.local/lib/PLWL, adds ~/.local/bin/plwl + a desktop shortcut, launches the app
# or run without installing:
./plwl
./install.sh # copies everything to ~/.local/bin/olcxja.plwl/,
# installs the icon (olcxja.plwl.png) + shortcut
# removes the extraction folder, launches
./createshortcut.sh # portable mode: only installs the icon + shortcut
# or run without any shortcuts:
./olcxja.plwl/olcxja.plwl
```
## Wine & Proton support

View file

@ -15,37 +15,21 @@ fi
rm -rf build/dist
mkdir -p build/dist/PLWL
cp -r node_modules/electron/dist build/dist/PLWL/electron
cp -r node_modules/electron/dist build/dist/PLWL/olcxja.plwl
mv build/dist/PLWL/olcxja.plwl/electron build/dist/PLWL/olcxja.plwl/olcxja.plwl
chmod +x build/dist/PLWL/olcxja.plwl/olcxja.plwl
# 2. Pack the app payload (code + renderer + bundled files) into app.asar.
STAGE=build/dist/.app-stage
mkdir -p "$STAGE"
cp -r src renderer files package.json "$STAGE/"
npx asar pack "$STAGE" build/dist/PLWL/electron/resources/app.asar
npx asar pack "$STAGE" build/dist/PLWL/olcxja.plwl/resources/app.asar
rm -rf "$STAGE"
# 3. Launcher, desktop entry and installer.
cat > build/dist/PLWL/plwl << 'EOF'
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")"
exec ./electron/electron . "$@"
EOF
chmod +x build/dist/PLWL/plwl
cat > build/dist/PLWL/plwl.desktop << 'EOF'
[Desktop Entry]
Type=Application
Name=PLWL
Comment=Portable Linux Wine Launcher
Exec=plwl
Icon=plwl
Terminal=false
Categories=Game;
EOF
cp tools/install.sh build/dist/PLWL/install.sh
chmod +x build/dist/PLWL/install.sh
# 3. Icon, installer and portable-shortcut helper.
cp renderer/plwl.png build/dist/PLWL/olcxja.plwl.png
cp tools/install.sh tools/createshortcut.sh build/dist/PLWL/
chmod +x build/dist/PLWL/install.sh build/dist/PLWL/createshortcut.sh
# 4. Tarball.
mkdir -p build

View file

@ -3,8 +3,6 @@
const path = require('path')
const fs = require('fs')
const APP_NAME = 'PLWL'
function findPng() {
const p = path.resolve(__dirname, '..', 'renderer', 'plwl.png')
try {
@ -15,44 +13,12 @@ function findPng() {
}
}
function writeIconThemeDirs(png) {
try {
const sizes = { '16x16': 16, '32x32': 32, '48x48': 48, '256x256': 256 }
const home = process.env.HOME
if (!home) return
const exe = path.join(require('./paths').APP_ROOT, 'plwl')
const execPath = fs.existsSync(exe)
? exe
: (process.env.PLWL_EXEC || 'plwl')
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, 'plwl.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=${execPath}`,
`Icon=plwl`,
'Terminal=false',
'Categories=Game;'
].join('\n')
fs.writeFileSync(path.join(desktopDir, 'plwl.desktop'), desktop)
} catch {}
}
function setAppIcon(app) {
const png = findPng()
if (!png) return
try {
app.setIcon(png)
} catch {}
writeIconThemeDirs(png)
}
module.exports = { setAppIcon }

View file

@ -3,7 +3,7 @@
const path = require('path')
const fs = require('fs')
// Packaged builds run from <portable root>/electron/resources/app.asar:
// Packaged builds run from <portable root>/olcxja.plwl/resources/app.asar:
// the portable layout (<root>/files) is two levels above the resources dir
// and files bundled with the release are unpacked next to the asar.
function computeRoots() {

41
tools/createshortcut.sh Normal file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env bash
# PLWL portable shortcut creator — bundled inside the release tarball.
# Installs the icon into the user icon theme and creates a .desktop entry
# pointing at ./olcxja.plwl/olcxja.plwl in the folder this script lives in
# (portable mode — no files are copied anywhere).
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_DIR="$HOME/.local/share/applications"
ICON_BASE="$HOME/.local/share/icons/hicolor"
ICON_SRC="$SCRIPT_DIR/olcxja.plwl.png"
EXE="$SCRIPT_DIR/olcxja.plwl/olcxja.plwl"
[ -f "$EXE" ] || { echo "createshortcut.sh: olcxja.plwl runtime not found in $SCRIPT_DIR" >&2; exit 1; }
chmod +x "$EXE" 2>/dev/null || true
echo "1. Installing icon..."
if [ -f "$ICON_SRC" ]; then
for dir in 16x16 32x32 48x48 256x256; do
mkdir -p "$ICON_BASE/$dir/apps"
cp "$ICON_SRC" "$ICON_BASE/$dir/apps/olcxja.plwl.png"
done
fi
echo "2. Creating shortcut..."
mkdir -p "$APP_DIR"
cat > "$APP_DIR/olcxja.plwl.desktop" << EOF
[Desktop Entry]
Type=Application
Name=PLWL
Comment=Portable Linux Wine Launcher
Exec="$EXE"
Icon=olcxja.plwl
Terminal=false
Categories=Game;
EOF
chmod +x "$APP_DIR/olcxja.plwl.desktop"
command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$APP_DIR" 2>/dev/null || true
echo "Shortcut created: $APP_DIR/olcxja.plwl.desktop -> $EXE"

View file

@ -1,7 +1,5 @@
#!/usr/bin/env bash
# PLWL installer — bundled inside the release tarball (build/PLWL-<version>.tar.gz).
# Modeled after LarpixClient's install.sh: copies the app into ~/.local,
# registers a desktop shortcut and removes the extraction folder.
set -e
echo "WARNING: Make sure you don't run this script in a folder that contains anything more than PLWL"
@ -11,35 +9,59 @@ read -r -p "Press Enter to continue (or Ctrl+C, to cancel)..."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_DIR="$HOME/.local/lib/PLWL"
BIN_DIR="$HOME/.local/bin"
INSTALL_DIR="$HOME/.local/bin/olcxja.plwl"
APP_DIR="$HOME/.local/share/applications"
ICON_BASE="$HOME/.local/share/icons/hicolor"
ICON_SRC="$SCRIPT_DIR/olcxja.plwl.png"
EXE="$INSTALL_DIR/olcxja.plwl/olcxja.plwl"
if [ "$SCRIPT_DIR" = "$INSTALL_DIR" ] || [ "$SCRIPT_DIR" = "$HOME" ] || [ "$SCRIPT_DIR" = "/" ]; then
echo "install.sh: refusing to run from '$SCRIPT_DIR'" >&2
exit 1
fi
case "$INSTALL_DIR/" in
"$SCRIPT_DIR"/*)
echo "install.sh: refusing to install into the extraction folder ('$SCRIPT_DIR')" >&2
exit 1
;;
esac
[ -f "$SCRIPT_DIR/olcxja.plwl/olcxja.plwl" ] || { echo "install.sh: olcxja.plwl runtime not found in $SCRIPT_DIR" >&2; exit 1; }
echo "1. Copying files..."
mkdir -p "$INSTALL_DIR" "$BIN_DIR" "$APP_DIR"
mkdir -p "$INSTALL_DIR" "$APP_DIR"
cp -r "$SCRIPT_DIR/." "$INSTALL_DIR/"
echo "2. Creating shortcut..."
sed -i "s|^Exec=.*|Exec=$BIN_DIR/plwl|" "$INSTALL_DIR/plwl.desktop"
mv "$INSTALL_DIR/plwl.desktop" "$APP_DIR/plwl.desktop"
chmod +x "$APP_DIR/plwl.desktop"
echo "2. Installing icon..."
if [ -f "$ICON_SRC" ]; then
for dir in 16x16 32x32 48x48 256x256; do
mkdir -p "$ICON_BASE/$dir/apps"
cp "$ICON_SRC" "$ICON_BASE/$dir/apps/olcxja.plwl.png"
done
fi
echo "3. Adding executable permissions..."
chmod +x "$INSTALL_DIR/plwl"
ln -sfn "$INSTALL_DIR/plwl" "$BIN_DIR/plwl"
echo "3. Creating shortcut..."
cat > "$APP_DIR/olcxja.plwl.desktop" << EOF
[Desktop Entry]
Type=Application
Name=PLWL
Comment=Portable Linux Wine Launcher
Exec="$EXE"
Icon=olcxja.plwl
Terminal=false
Categories=Game;
EOF
chmod +x "$APP_DIR/olcxja.plwl.desktop"
echo "4. Cleaning installation..."
rm -f "$INSTALL_DIR/install.sh"
echo "4. Adding executable permissions..."
chmod +x "$EXE"
echo "5. Cleaning installation..."
rm -f "$INSTALL_DIR/install.sh" "$INSTALL_DIR/createshortcut.sh"
command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$APP_DIR" 2>/dev/null || true
echo "5. Installation completed. Cleaning up and launching..."
echo "6. Installation completed. Cleaning up and launching..."
rm -rf "${SCRIPT_DIR:?}"/*
nohup "$BIN_DIR/plwl" >/dev/null 2>&1 &
nohup "$EXE" >/dev/null 2>&1 &
disown 2>/dev/null || true
exit 0