Skip to content

Commit

Permalink
Adjust AppImage support for appimage.github.io
Browse files Browse the repository at this point in the history
Environment variables are not reliable in that check environment.

Now the executable is under bin and the resources are in directories
under the same parent as bin. Path to the executable is obtained using
proc filesystem.

See AppImage/appimage.github.io#2994
  • Loading branch information
mgrojo committed Sep 17, 2022
1 parent 4ea50ac commit a4e04c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ all:
alr build

install: all
mkdir -p $(DESTDIR)
mkdir -p $(DESTDIR)/bin
cp -rp $(MAIN).desktop $(MAIN) themes $(DESTDIR)
cp -p bin/$(MAIN) $(DESTDIR)/bin
cp -p themes/1/icon.png $(DESTDIR)/$(MAIN).png

AppImage:
rm -rf AppDir
make install DESTDIR=AppDir
make install DESTDIR=AppDir/usr
wget -nv -c https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x linuxdeploy-x86_64.AppImage
./linuxdeploy-x86_64.AppImage \
--executable $(MAIN) \
--desktop-file $(MAIN).desktop --icon-file=AppDir/$(MAIN).png \
--executable bin/$(MAIN) \
--desktop-file $(MAIN).desktop --icon-file=AppDir/usr/$(MAIN).png \
--appdir AppDir --output appimage
4 changes: 2 additions & 2 deletions play_2048.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ project Play_2048 is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Main use ("play_2048.adb");
for Exec_Dir use ".";
for Exec_Dir use "bin";

package Compiler is
for Default_Switches ("Ada") use
("-g",
"-gnatQ",
"-gnatwa", -- All warnings
"-gnatVa", -- All validity checks
"-O1");
"-O2");
end Compiler;

end Play_2048;
26 changes: 12 additions & 14 deletions src/play_2048.adb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
with Ada.Command_Line;
with Ada.Strings.Fixed;
with Ada.Directories;
with Ada.Environment_Variables;
with Ada.Calendar.Formatting;

with Storage;
Expand Down Expand Up @@ -211,10 +210,6 @@ procedure Play_2048 is
(Move (Value, Length => 4, Justify => Ada.Strings.Center));

Board : Game.t_Board renames State.Board;
Elapsed_Time : constant string := Ada.Calendar.Formatting.Image
(Elapsed_Time => Game.Elapsed_Time (State));
Best_Time_Image : constant String := Ada.Calendar.Formatting.Image
(Elapsed_Time => Best_Time);
begin
if Text_UI then
Put_Line (Horizontal_Rule);
Expand Down Expand Up @@ -294,21 +289,24 @@ procedure Play_2048 is
end Set_Text_Style;

function Theme_Path (Theme_Id : t_theme) return String is
-- If running inside our AppImage, use the APPDIR env var. In
-- this way we allow running from an AppImage and still find the

Self_Exe : constant String := "/proc/self/exe";
-- Get the resources path through the directory where the program is
-- located.
-- In this way we allow running from an AppImage and still find the
-- resource files.
--
App_Dir : constant String :=
(if Ada.Environment_Variables.Exists ("APPIMAGE") and then
Ada.Strings.Fixed.Index (Ada.Environment_Variables.Value ("APPIMAGE"),
"Play_2048") > 0 and then
Ada.Environment_Variables.Exists ("APPDIR")
(if Ada.Directories.Exists (Self_Exe)
then
Ada.Environment_Variables.Value ("APPDIR") & "/"
else "");
Ada.Directories.Containing_Directory
(Ada.Directories.Containing_Directory
(Ada.Directories.Full_Name (Self_Exe)))
else
"");
begin
return App_Dir &
"themes/" & Ada.Strings.Fixed.Trim (Theme_Id'Image,
"/themes/" & Ada.Strings.Fixed.Trim (Theme_Id'Image,
Ada.Strings.Left) & "/";
end Theme_Path;

Expand Down

0 comments on commit a4e04c6

Please sign in to comment.