Skip to content

Commit 71b71fb

Browse files
committed
AppImage: build/after-build.js forever (--no-sandbox AGAIN)
1 parent e5dd0e7 commit 71b71fb

File tree

3 files changed

+162
-48
lines changed

3 files changed

+162
-48
lines changed

build/after-build.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
import { execSync } from 'child_process';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
// Get package info
10+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
11+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
12+
const packageName = packageJson.name;
13+
const version = packageJson.version;
14+
15+
async function processAppImage() {
16+
const appImageName = 'emulsion_x86_64.AppImage';
17+
18+
console.log('Processing AppImage package...');
19+
20+
const distDir = path.join(__dirname, '..', 'dist');
21+
const appImagePath = path.join(distDir, appImageName);
22+
23+
if (!fs.existsSync(appImagePath)) {
24+
console.log(`AppImage not found: ${appImagePath}, skipping processing`);
25+
return;
26+
}
27+
28+
console.log(`Found AppImage: ${appImageName}`);
29+
30+
// Change to dist directory
31+
const originalCwd = process.cwd();
32+
process.chdir(distDir);
33+
34+
try {
35+
// Extract AppImage
36+
console.log('Extracting AppImage...');
37+
execSync(`"./${appImageName}" --appimage-extract`, { stdio: 'inherit' });
38+
39+
// Modify atexit function in AppRun
40+
console.log('Modifying AppRun script...');
41+
modifyAppRunAtexit('./squashfs-root/AppRun');
42+
43+
// Remove locale files
44+
console.log('Removing locale files...');
45+
const localesDir = './squashfs-root/usr/share/locale';
46+
if (fs.existsSync(localesDir)) {
47+
const localeDirs = fs.readdirSync(localesDir);
48+
localeDirs.forEach(locale => {
49+
const localePath = path.join(localesDir, locale);
50+
if (fs.statSync(localePath).isDirectory()) {
51+
fs.rmSync(localePath, { recursive: true, force: true });
52+
console.log(`Removed locale: ${locale}`);
53+
}
54+
});
55+
}
56+
57+
// Repackage AppImage
58+
console.log('Repackaging AppImage...');
59+
const appimagetoolPath = path.join(__dirname, '..', 'bin', 'appimagetool-x86_64.AppImage');
60+
61+
if (fs.existsSync(appimagetoolPath)) {
62+
console.log('Using appimagetool from bin directory');
63+
execSync(`"${appimagetoolPath}" squashfs-root "${appImageName}"`, { stdio: 'inherit' });
64+
} else {
65+
console.log('appimagetool not found in bin directory, skipping repackaging');
66+
}
67+
68+
console.log('AppImage processing complete');
69+
70+
} catch (error) {
71+
console.error('Error processing AppImage:', error.message);
72+
throw error;
73+
} finally {
74+
// Restore original working directory
75+
process.chdir(originalCwd);
76+
}
77+
}
78+
79+
function modifyAppRunAtexit(appRunPath) {
80+
if (!fs.existsSync(appRunPath)) {
81+
console.log(`AppRun script not found: ${appRunPath}`);
82+
return;
83+
}
84+
85+
let content = fs.readFileSync(appRunPath, 'utf8');
86+
87+
// Replace the specific exec lines within the atexit function
88+
// Look for: exec "$BIN" followed by optional args
89+
content = content.replace(
90+
/exec "\$BIN"(?:\s+"\$\{args\[@\]\}")?/g,
91+
(match) => {
92+
if (match.includes('${args[@]}')) {
93+
return 'exec "$BIN" "${args[@]}" "--no-sandbox"';
94+
} else {
95+
return 'exec "$BIN" "--no-sandbox"';
96+
}
97+
}
98+
);
99+
100+
fs.writeFileSync(appRunPath, content, 'utf8');
101+
console.log('Successfully modified exec commands to add --no-sandbox');
102+
103+
// Verify the changes
104+
const lines = content.split('\n');
105+
const atexitIndex = lines.findIndex(line => line.includes('atexit()'));
106+
if (atexitIndex !== -1) {
107+
const start = Math.max(0, atexitIndex - 1);
108+
const end = Math.min(lines.length, atexitIndex + 10);
109+
console.log('Modified atexit function:');
110+
console.log(lines.slice(start, end).join('\n'));
111+
}
112+
}
113+
114+
// Run the processing
115+
processAppImage().catch(error => {
116+
console.error('AppImage processing failed:', error);
117+
process.exit(1);
118+
});

build/after-pack.js

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { fileURLToPath } from 'url';
4+
import { execSync } from 'child_process';
45

56
const __filename = fileURLToPath(import.meta.url);
67
const __dirname = path.dirname(__filename);
@@ -14,8 +15,28 @@ export default async (context) => {
1415
console.log(' • Generating AppStream metadata for AppImage...');
1516

1617
const appOutDir = context.appOutDir;
18+
19+
// List all files in appOutDir for debugging
20+
console.log(' • Contents of appOutDir:');
21+
const listFilesRecursively = (dir, prefix = '') => {
22+
const items = fs.readdirSync(dir);
23+
items.forEach(item => {
24+
const fullPath = path.join(dir, item);
25+
const stat = fs.statSync(fullPath);
26+
const relativePath = prefix + item;
27+
if (stat.isDirectory()) {
28+
console.log(` • 📁 ${relativePath}/`);
29+
listFilesRecursively(fullPath, relativePath + '/');
30+
} else {
31+
console.log(` • 📄 ${relativePath} (${stat.size} bytes)`);
32+
}
33+
});
34+
};
35+
36+
// listFilesRecursively(appOutDir);
37+
1738
const metainfoDir = path.join(appOutDir, 'usr', 'share', 'metainfo');
18-
const targetFile = path.join(metainfoDir, 'emulsion.appdata.xml');
39+
const targetFile = path.join(metainfoDir, 'io.gitlab.yphil.emulsion.appdata.xml');
1940

2041
// Read package.json for version
2142
const packageJsonPath = path.join(context.outDir, '..', 'package.json');
@@ -32,30 +53,32 @@ export default async (context) => {
3253
<metadata_license>CC0-1.0</metadata_license>
3354
<project_license>GPL-3.0+</project_license>
3455
<name>Emulsion</name>
35-
<developer_name>yPhil</developer_name>
36-
<summary>Better gaming throught chemistry</summary>
37-
<releases>
38-
<release version="${version}" date="${currentDate}"/>
39-
</releases>
56+
<developer>
57+
<name>yPhil</name>
58+
</developer>
59+
<summary>Better gaming through chemistry</summary>
4060
<description>
4161
<p>Display your games collection into responsive galleries, manage game metadata, cover art and emulator configuration. Launch your games in style.</p>
42-
<h2>Features</h2>
43-
<ul>
44-
<li><strong>Flexible Storage</strong> - Your games / ROMs can be anywhere, across multiple drives / NAS, etc.</li>
45-
<li><strong>Universal Input</strong> - Keyboard, mouse, or any game controller</li>
46-
<li><strong>Responsive UX</strong> - Adapts perfectly to any screen size / orientation</li>
47-
<li><strong>Smart emulator management</strong> - Emulsion uses your installed emulator, or installs it; standard and up to date.</li>
48-
<li><strong>Flexible Metadata Management</strong> - Manual curation, and / or batch automation. Downloads from multiple sources, Wikipedia API default; all manageable from the platform page.</li>
49-
</ul>
62+
<p>Features:</p>
63+
<ul>
64+
<li>Flexible Storage - Your games / ROMs can be anywhere, across multiple drives / NAS, etc.</li>
65+
<li>Universal Input - Keyboard, mouse, or any game controller</li>
66+
<li>Responsive UX - Adapts perfectly to any screen size / orientation</li>
67+
<li>Smart emulator management - Emulsion uses your installed emulator, or installs it; standard and up to date.</li>
68+
<li>Flexible Metadata Management - Manual curation, and / or batch automation. Downloads from multiple sources, Wikipedia API default; all manageable from the platform page.</li>
69+
</ul>
5070
</description>
51-
<launchable type="desktop-id">io.gitlab.yphil.emulsion.desktop</launchable>
71+
<launchable type="desktop-id">emulsion.desktop</launchable>
5272
<url type="homepage">https://yphil.gitlab.io/emulsion/</url>
5373
<url type="help">https://gitlab.com/yphil/emulsion</url>
5474
<url type="bugtracker">https://gitlab.com/yphil/emulsion/-/issues</url>
5575
<categories>
56-
<category>Games</category>
57-
<category>Productivity</category>
76+
<category>Utility</category>
5877
</categories>
78+
<content_rating type="oars-1.1"/>
79+
<releases>
80+
<release version="${version}" date="${currentDate}"/>
81+
</releases>
5982
<screenshots>
6083
<screenshot type="default">
6184
<image>https://yphil.gitlab.io/images/emulsion-screenshot_01-839px.png</image>
@@ -72,31 +95,4 @@ export default async (context) => {
7295
// Write the XML file
7396
fs.writeFileSync(targetFile, xmlContent, 'utf8');
7497
console.log(` • AppStream metadata OK: ${targetFile} (version: ${version}, date: ${currentDate})`);
75-
76-
console.log(' • Generating desktop file for AppImage...');
77-
78-
const applicationsDir = path.join(appOutDir, 'usr', 'share', 'applications');
79-
const desktopFile = path.join(applicationsDir, 'io.gitlab.yphil.emulsion.desktop');
80-
81-
// Generate desktop file content
82-
const desktopContent = `[Desktop Entry]
83-
Name=Emulsion (AppImage)
84-
Comment=Display your games collection into responsive galleries, manage game metadata, cover art and emulator configuration. Launch your games in style.
85-
Exec=emulsion
86-
Icon=emulsion
87-
StartupNotify=true
88-
Terminal=false
89-
Type=Application
90-
Categories=Games;Productivity;
91-
`;
92-
93-
// Create applications directory if it doesn't exist
94-
if (!fs.existsSync(applicationsDir)) {
95-
fs.mkdirSync(applicationsDir, { recursive: true });
96-
console.log(` • Created directory: ${applicationsDir}`);
97-
}
98-
99-
// Write the desktop file
100-
fs.writeFileSync(desktopFile, desktopContent, 'utf8');
101-
console.log(` • Desktop file OK: ${desktopFile}`);
10298
};

build/builder.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ linux:
3232
executableName: emulsion
3333
target:
3434
- AppImage
35-
- deb
36-
- rpm
37-
- freebsd
38-
- pacman
35+
# - deb
36+
# - rpm
37+
# - freebsd
38+
# - pacman
3939
category: Utility
4040

4141
pacman:

0 commit comments

Comments
 (0)