diff --git a/README.md b/README.md index 0c379ff..86243a5 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,31 @@ bash ./build-arch-pkg.sh sudo pacman -U linux-assistant-*.pkg.tar.zst ``` +### Build Snap +```bash +# 1. Install snapcraft: +sudo snap install snapcraft --classic +# 2. Install lxd: +sudo snap install lxd +# 3. Add yourself to the group for lxd +sudo usermod -a -G lxd $USER +# 4. Reboot your system +sudo reboot +# 5. Run this command to init lxd +lxd init --minimal +# 6. Clone the Repo: +git clone https://github.com/Jean28518/linux-assistant.git +cd linux-assistant +# 7. Start building snap +snapcraft pack +# 8. Install: +sudo snap install ./linux-assistant_*_amd64.snap --dangerous --classic +# 9. Cleanup: +snapcraft clean +``` + + + ## Run as flatpak Repo: diff --git a/additional/python/get_applications.py b/additional/python/get_applications.py index 0a3b31d..2c9e300 100644 --- a/additional/python/get_applications.py +++ b/additional/python/get_applications.py @@ -76,8 +76,11 @@ def get_applications_of_dir(path, language, desktop): desktop = desktop.replace(".", "") desktop = desktop.replace("-", "") - dataDirs = os.getenv("XDG_DATA_DIRS").split(":") - + # add fallback for XDG_DATA_DIRS to avoid 'NoneType' errors + # use default paths /usr/local/share and /usr/share + xdg_data_dirs_value = os.getenv("XDG_DATA_DIRS", "/usr/local/share/:/usr/share/") + dataDirs = xdg_data_dirs_value.split(":") + if jfolders.does_folder_exist(os.getenv("HOME") + "/.local/share/applications"): dataDirs.append(os.getenv("HOME") + "/.local/share") @@ -91,4 +94,4 @@ def get_applications_of_dir(path, language, desktop): print("%s\t%s\t%s\t%s\t%s" % (app.path, app.name, app.description, app.icon, app.keywords)) - \ No newline at end of file + diff --git a/additional/python/get_icon_path_for_file.py b/additional/python/get_icon_path_for_file.py index 38e1a01..2300cb1 100644 --- a/additional/python/get_icon_path_for_file.py +++ b/additional/python/get_icon_path_for_file.py @@ -7,17 +7,39 @@ import jessentials + file_path = jessentials.get_value_from_arguments("file") file_path = file_path.removeprefix("'").removesuffix("'") -info = Gio.File.new_for_path(file_path).query_info('standard::icon', Gio.FileQueryInfoFlags.NONE, None) -icon = info.get_icon() - -if icon: - theme = Gtk.IconTheme.get_default() - size = 48 - icon_name = info.get_icon().get_names()[0] - icon_path = theme.lookup_icon(icon_name, size, 0).get_filename() - print(icon_path) \ No newline at end of file +# return an empty path if something doesn't work +icon_path = "" + +try: + info = Gio.File.new_for_path(file_path).query_info('standard::icon', Gio.FileQueryInfoFlags.NONE, None) + icon = info.get_icon() + + if icon: + icon_names = icon.get_names() + + # ensure that the list is not empty + if icon_names: + theme = Gtk.IconTheme.get_default() + size = 48 + + icon_name = icon_names[0] + + icon_info = theme.lookup_icon(icon_name, size, 0) + + # ensure that lookup found something + if icon_info: + icon_path = icon_info.get_filename() + +except Exception as e: + # catches all unexpected errors (e.g., file access errors) + # and ensures that the program does not crash. + pass + +# new output +print(icon_path) diff --git a/linux-assistant.sh b/linux-assistant.sh index 38dde28..36dfa4d 100755 --- a/linux-assistant.sh +++ b/linux-assistant.sh @@ -1,24 +1,47 @@ #!/bin/bash -APP_DIR="/usr/lib/linux-assistant" -# if the file "linux-assistant" is present in the same directory as this script, change APP_DIR -if [ -f "linux-assistant" ]; then - APP_DIR="." -fi +APP_DIR="" # leave it empty -# if /app/bin is present change APP_DIR (because then we are in flatpak) -if [ -d "/app/bin" ]; then - APP_DIR="/app/bin" +# if the application is running as a Snap +# snap applications are installed in /snap// and the script is in bin +# so the lib dir is at $SNAP/bin/lib +# unset some variables to prevent conflicts +if [ -n "$SNAP" ]; then + APP_DIR="$SNAP/bin/lib" + # disable some variables + unset LD_LIBRARY_PATH + unset XDG_DATA_DIRS + unset GTK_PATH + unset GSETTINGS_SCHEMA_DIR + unset GI_TYPELIB_PATH + unset GIO_EXTRA_MODULES + unset GTK_USE_PORTAL + unset GDK_DISABLE_MEDIA + echo "[LA] Using snap" + +# running as LA as flatpak +elif [ -d "/app/bin" ]; then + APP_DIR="/app/bin" + echo "[LA] Using flatpak" + +# running LA local +elif [ -f "linux-assistant" ]; then + APP_DIR="." + echo "[LA] Using local" +else + # use /usr/lib as fallback + APP_DIR="/usr/lib/linux-assistant" + echo "[LA] Using standard installation" fi -echo "App_DIR: $APP_DIR" +echo "[LA] App_DIR: $APP_DIR" if [[ "$1" == "-v" || "$1" == "--version" ]]; then VERSION="" if [ -f "$APP_DIR/version" ]; then VERSION=$( cat "$APP_DIR/version" ) fi - + echo "" echo "Linux-Assistant $VERSION" echo "A daily linux helper with powerful integrated search, routines and checks." echo "Homepage: https://www.linux-assistant.org" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..eabd583 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,177 @@ +name: linux-assistant +base: core24 +version: '0.6.1' +summary: A daily Linux helper +description: | + Linux Assistant \E2\80\93 a daily Linux helper with powerful search, + routine checks, and management tools. + System interventions are secured via Polkit. + +# required for metadata +title: Linux Assistant +contact: your-email@example.com # who wants to stand here? +license: GPL-3.0-only + +# required by lint +donation: https://www.linuxguides.de/unterstuetzen/ +issues: https://github.com/Jean28518/linux-assistant/issues +source-code: https://github.com/Jean28518/linux-assistant +website: https://www.linux-assistant.org/ + +grade: stable +confinement: classic + +apps: + linux-assistant: + command: bin/linux-assistant + desktop: gui/linux-assistant.desktop + environment: + PATH: $SNAP/bin:$SNAP/usr/bin:$PATH + LD_LIBRARY_PATH: "$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$SNAP/lib/$SNAPCRAFT_ARCH_TRIPLET" + XDG_DATA_DIRS: $SNAP/usr/share:$SNAP/share:$XDG_DATA_DIRS + GTK_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/gtk-4.0 + GSETTINGS_SCHEMA_DIR: $SNAP/share/glib-2.0/schemas + GI_TYPELIB_PATH: $SNAP/usr/lib/girepository-1.0:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/girepository-1.0 + GIO_EXTRA_MODULES: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/gio/modules + GTK_USE_PORTAL: "1" + GDK_DISABLE_MEDIA: "1" + GSK_RENDERER: "cairo" + GTK_MEDIA_BACKEND: "none" + PYTHONPATH: $SNAP/bin/lib/additional/python + plugs: + - network + - network-bind + - home + - x11 + - wayland + - opengl + - desktop + - desktop-legacy + - pulseaudio + - camera + - removable-media + - system-observe + - mount-observe + - hardware-observe + - network-observe + - process-control + - raw-usb + - gsettings + - cups + - uhid + - unity7 + +plugs: + gtk-3-themes: + interface: content + target: $SNAP/data-dir/themes + default-provider: gtk-common-themes + + gtk-themes: + interface: content + target: $SNAP/data-dir/themes + default-provider: gtk-common-themes + + icon-themes: + interface: content + target: $SNAP/data-dir/icons + default-provider: gtk-common-themes + + dbus: + interface: dbus + bus: session + name: org.freedesktop.portal.Desktop + + opengl: + interface: opengl + +slots: + linux-assistant: + interface: dbus + bus: session + name: io.github.jean28518.linux-assistant + +environment: + LIBGL_DRIVERS_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/dri + LIBGL_DEBUG: verbose + MESA_LOADER_DRIVER_OVERRIDE: swrast + +# split the snap building +parts: + # get the binary, lib, data, additional from the latest release + linux-assistant-release: # I use this methode, because building from source doesn't work with device/snapcraft setup + plugin: dump + source: https://github.com/Jean28518/linux-assistant/releases/download/v0.6.1/linux-assistant-bundle.zip + source-type: zip + organize: + #linux-assistant-bundle/additional: /bin/lib/additional/ + linux-assistant-bundle/data: /bin/lib/data/ + linux-assistant-bundle/lib: /bin/lib/lib/ + linux-assistant-bundle/linux-assistant: bin/lib/linux-assistant + linux-assistant-bundle/version: /bin/lib/ + build-packages: + - libglib2.0-dev-bin + - libglib2.0-bin + stage-packages: + # GTK3 rt + - libglib2.0-0 + - libgtk-3-0 + - libpango-1.0-0 + - libcairo2 + - libatk1.0-0 + - libgdk-pixbuf-2.0-0 + # GTK4 rt + - libgtk-4-1 + - libadwaita-1-0 + # themes & icons + - adwaita-icon-theme + - hicolor-icon-theme + - gnome-themes-extra + - shared-mime-info + - librsvg2-common + # other packages + - libcanberra-gtk3-0 + - libcanberra-gtk-module + - libnotify4 + - gvfs + - dconf-gsettings-backend + - coreutils + - dconf-gsettings-backend + - xdg-desktop-portal + - xdg-desktop-portal-gtk + - xdg-utils + - libproxy1v5 + - libproxy1-plugin-gsettings + - libproxy1-plugin-networkmanager + - curl + - pkexec + - libgl1 + - libegl1 + - libgles2 + - wget + - unzip + override-build: | + craftctl default + glib-compile-schemas $SNAPCRAFT_PART_INSTALL/usr/share/glib-2.0/schemas + gio-querymodules $SNAPCRAFT_PART_INSTALL/usr/lib/x86_64-linux-gnu/gio/modules + + # get the local linux-assistant.sh, .desktop, linux-assistant.png + linux-assistant-local: # use local files, because the .desktop file need other icon dir + plugin: dump + source: . + organize: + additional: /bin/lib/additional/ + linux-assistant.sh: bin/linux-assistant + linux-assistant.png: meta/gui/linux-assistant.png + linux-assistant.desktop: gui/linux-assistant.desktop + override-build: | + set -eux + mkdir -p $SNAPCRAFT_PART_INSTALL/bin + cp linux-assistant.sh $SNAPCRAFT_PART_INSTALL/bin/linux-assistant + mkdir -p $SNAPCRAFT_PART_INSTALL/meta/gui + cp linux-assistant.png $SNAPCRAFT_PART_INSTALL/meta/gui/linux-assistant.png + mkdir -p $SNAPCRAFT_PART_INSTALL/gui + cp linux-assistant.desktop $SNAPCRAFT_PART_INSTALL/gui/linux-assistant.desktop + sed -i 's@^Icon=.*$@Icon=${SNAP}/meta/gui/linux-assistant.png@' $SNAPCRAFT_PART_INSTALL/gui/linux-assistant.desktop + mkdir -p $SNAPCRAFT_PART_INSTALL/bin/lib/additional/ + cp -r additional/* $SNAPCRAFT_PART_INSTALL/bin/lib/additional/