Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions crates/app_packager/src/linux/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl AppImageMakeConfig {
/// (including `[Desktop Action]` sections).
fn desktop_file(&self, config: &PackageConfig) -> String {
let app_name = &config.app_name;
let binary_name = &config.app_binary_name;
let mut fields: Vec<(&str, String)> = vec![
(
"Name",
Expand All @@ -73,7 +74,10 @@ impl AppImageMakeConfig {
.clone()
.unwrap_or_else(|| "A Flutter Application".to_string()),
),
("Exec", format!("LD_LIBRARY_PATH=usr/lib {} %u", app_name)),
(
"Exec",
format!("LD_LIBRARY_PATH=usr/lib {} %u", binary_name),
),
("Icon", app_name.clone()),
("Type", "Application".to_string()),
(
Expand Down Expand Up @@ -115,7 +119,7 @@ impl AppImageMakeConfig {
"[Desktop Action {}]\nName={}\nExec=LD_LIBRARY_PATH=usr/lib {} {} %u",
action.label,
action.name,
app_name,
binary_name,
action.arguments.join(" "),
)
})
Expand All @@ -129,7 +133,7 @@ impl AppImageMakeConfig {
fn app_run(&self, config: &PackageConfig) -> String {
format!(
"#!/bin/bash\n\ncd \"$(dirname \"$0\")\"\nexport LD_LIBRARY_PATH=usr/lib\nexec ./{}\n",
config.app_name
config.app_binary_name
)
}
}
Expand Down Expand Up @@ -276,8 +280,7 @@ impl AppPackager for LinuxAppImagePackager {
};
let metainfo_dir = app_dir.join("usr/share/metainfo");
std::fs::create_dir_all(&metainfo_dir)?;
// Dart's AppImage config extends `MakeConfig` (not the Linux
// variant), so its `appBinaryName` is the pubspec name.
// Named after the pubspec to match the `.desktop` file, as in Dart.
std::fs::copy(
metainfo_path,
metainfo_dir.join(format!("{}{}", config.app_name, ext)),
Expand Down Expand Up @@ -423,6 +426,30 @@ actions:
assert!(script.contains("exec ./hola_amigos"));
}

#[test]
fn launches_binary_name_when_it_differs_from_app_name() {
let config = PackageConfig {
app_binary_name: "hola".into(),
..test_config()
};
let mc: AppImageMakeConfig = serde_yaml::from_str(
r#"
actions:
- label: Gallery
name: Open Gallery
arguments:
- --gallery
"#,
)
.unwrap();

assert!(mc.app_run(&config).contains("exec ./hola\n"));
let desktop = mc.desktop_file(&config);
assert!(desktop.contains("Exec=LD_LIBRARY_PATH=usr/lib hola %u"));
assert!(desktop.contains("Exec=LD_LIBRARY_PATH=usr/lib hola --gallery %u"));
assert!(desktop.contains("Icon=hola_amigos"));
}

#[test]
fn ldd_output_parsing() {
let output = "\tlinux-vdso.so.1 (0x00007ffd)\n\tlibkeybinder-3.0.so.0 => /lib64/libkeybinder-3.0.so.0 (0x00007f65)\n\tlibc.so.6 => /lib64/libc.so.6 (0x00007f64)\n\t/lib64/ld-linux-x86-64.so.2 (0x00007f66)\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class AppPackageMakerAppImage extends AppPackageMaker {
await metainfoFile.copy(
path.join(
metainfoDir,
makeConfig.appBinaryName + path.extension(makeConfig.metainfo!, 2),
makeConfig.appName + path.extension(makeConfig.metainfo!, 2),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AppImageAction {
}
}

class MakeAppImageConfig extends MakeConfig {
class MakeAppImageConfig extends MakeLinuxPackageConfig {
MakeAppImageConfig({
required this.displayName,
required this.icon,
Expand Down Expand Up @@ -81,7 +81,7 @@ class MakeAppImageConfig extends MakeConfig {
final fields = {
'Name': displayName,
'GenericName': genericName,
'Exec': 'LD_LIBRARY_PATH=usr/lib $appName %u',
'Exec': 'LD_LIBRARY_PATH=usr/lib $appBinaryName %u',
'Icon': appName,
'Type': 'Application',
'StartupNotify': startupNotify ? 'true' : 'false',
Expand All @@ -97,7 +97,7 @@ class MakeAppImageConfig extends MakeConfig {
final fields = {
'Name': action.name,
'Exec':
'LD_LIBRARY_PATH=usr/lib $appName ${action.arguments.join(' ')} %u',
'LD_LIBRARY_PATH=usr/lib $appBinaryName ${action.arguments.join(' ')} %u',
};
return '[Desktop Action ${action.label}]\n${fields.entries.map((e) => '${e.key}=${e.value}').join('\n')}';
}).join('\n\n');
Expand All @@ -111,7 +111,7 @@ class MakeAppImageConfig extends MakeConfig {

cd "\$(dirname "\$0")"
export LD_LIBRARY_PATH=usr/lib
exec ./$appName
exec ./$appBinaryName
''';
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:flutter_app_packager/src/makers/appimage/make_appimage_config.dart';
import 'package:flutter_app_packager/src/makers/deb/make_deb_config.dart';
import 'package:flutter_app_packager/src/makers/pacman/make_pacman_config.dart';
import 'package:flutter_app_packager/src/makers/rpm/make_rpm_config.dart';
Expand Down Expand Up @@ -123,6 +124,33 @@ void main() {
);
});

test('appimage launches the CMake binary, not the pubspec name', () {
File('${tempDir.path}/linux/CMakeLists.txt')
.writeAsStringSync('set(BINARY_NAME "test_binary")\n');
final config = MakeAppImageConfig.fromJson({
'display_name': 'Test App',
'icon': 'icon.png',
'actions': [
{
'label': 'NewWindow',
'name': 'New Window',
'arguments': ['--new-window'],
},
],
})..pubspec = _pubspec();

expect(config.appRunContent, contains('exec ./test_binary\n'));
expect(
config.desktopFileContent,
contains('Exec=LD_LIBRARY_PATH=usr/lib test_binary %u'),
);
expect(
config.desktopFileContent,
contains('Exec=LD_LIBRARY_PATH=usr/lib test_binary --new-window %u'),
);
expect(config.desktopFileContent, contains('Icon=test_app'));
});

test('pacman keeps package version out of the desktop entry', () {
final config = MakePacmanConfig(
displayName: 'Test App',
Expand Down