Ship AppImage with bundled GTK runtime and automated releases
AppImage / build (push) Has been cancelled
AppImage / release (push) Has been cancelled
Tests / unit (de, 3.10) (push) Has been cancelled
Tests / unit (de, 3.14) (push) Has been cancelled
Tests / unit (en, 3.10) (push) Has been cancelled
Tests / unit (en, 3.14) (push) Has been cancelled
AppImage / build (push) Has been cancelled
AppImage / release (push) Has been cancelled
Tests / unit (de, 3.10) (push) Has been cancelled
Tests / unit (de, 3.14) (push) Has been cancelled
Tests / unit (en, 3.10) (push) Has been cancelled
Tests / unit (en, 3.14) (push) Has been cancelled
This commit is contained in:
+24
-3
@@ -1,6 +1,7 @@
|
||||
"""User-scoped desktop integration."""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -8,10 +9,17 @@ APP_ID = 'io.github.btd700linux.Control'
|
||||
|
||||
|
||||
def desktop_entry(*, background=False):
|
||||
appdir = os.environ.get('APPDIR')
|
||||
appimage = os.environ.get('APPIMAGE') if appdir else None
|
||||
checkout = (ROOT / 'run.sh').is_file()
|
||||
path = str(ROOT / 'run.sh') if checkout else sys.executable
|
||||
module_args = '' if checkout else ' -m btd700'
|
||||
icon = str(ROOT / 'packaging/btd700-control.svg') if checkout else 'audio-headphones'
|
||||
path = appimage or (str(Path(appdir) / 'AppRun') if appdir else None) or (str(ROOT / 'run.sh') if checkout else sys.executable)
|
||||
module_args = '' if appdir or checkout else ' -m btd700'
|
||||
# The pinned type2 runtime removes its CLI flag before launching AppRun;
|
||||
# its extraction directory also identifies subsequent launches in this mode.
|
||||
if appimage and ('APPIMAGE_EXTRACT_AND_RUN' in os.environ or Path(appdir).name.startswith('appimage_extracted_')):
|
||||
module_args = ' --appimage-extract-and-run'
|
||||
icon = (str(installed_icon()) if appimage else str(Path(appdir) / 'btd700-control.svg') if appdir
|
||||
else str(ROOT / 'packaging/btd700-control.svg') if checkout else 'audio-headphones')
|
||||
# Desktop Entry Exec quoting is not shell quoting.
|
||||
escaped = path.replace('\\', '\\\\').replace('"', '\\"').replace('`', '\\`').replace('$', '\\$').replace('%', '%%')
|
||||
return ('[Desktop Entry]\nType=Application\nName=BTD 700 Control\n'
|
||||
@@ -29,9 +37,22 @@ def autostart_path():
|
||||
return base / 'autostart' / f'{APP_ID}.desktop'
|
||||
|
||||
|
||||
def installed_icon():
|
||||
base = Path(os.environ.get('XDG_DATA_HOME', Path.home() / '.local/share'))
|
||||
return base / 'icons/hicolor/scalable/apps' / f'{APP_ID}.svg'
|
||||
|
||||
|
||||
def install_appimage_icon():
|
||||
if os.environ.get('APPIMAGE') and os.environ.get('APPDIR'):
|
||||
path = installed_icon()
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(Path(os.environ['APPDIR']) / 'btd700-control.svg', path)
|
||||
|
||||
|
||||
def set_autostart(enabled):
|
||||
path = autostart_path()
|
||||
if enabled:
|
||||
install_appimage_icon()
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(desktop_entry(background=True))
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user