#!@PYTHON@
# Copyright 2026, Jiri Eischmann <jiri@eischmann.cz> and the meshy contributors
# SPDX-License-Identifier: GPL-3.0-or-later

import os
import sys
import signal
import locale
import gettext

VERSION = '@VERSION@'
pkgdatadir = os.environ.get('MESHY_PKGDATADIR', '@pkgdatadir@')
appdir = os.environ.get('APPDIR')
if appdir:
    pkgdatadir = os.path.join(appdir, 'usr', 'share', 'meshy')
    localedir = os.path.join(appdir, 'usr', 'share', 'locale')
else:
    localedir = '@localedir@'
QR_SCANNER_ENABLED = '@QR_SCANNER_ENABLED@' == 'true'
SHORTCUTS_DIALOG_ENABLED = '@SHORTCUTS_DIALOG_ENABLED@' == 'true'

signal.signal(signal.SIGINT, signal.SIG_DFL)

# Set up gettext for translations
# locale.bindtextdomain is not available on macOS, so use try/except
try:
    locale.bindtextdomain('meshy', localedir)
    locale.textdomain('meshy')
except AttributeError:
    # macOS doesn't have bindtextdomain in locale module
    # gettext.install will handle the translation setup
    pass
gettext.bindtextdomain('meshy', localedir)
gettext.install('meshy', localedir)

if __name__ == '__main__':
    import gi
    gi.require_version('Gtk', '4.0')
    gi.require_version('Adw', '1')

    import meshy as _meshy_pkg
    _meshy_pkg.pkgdatadir = pkgdatadir
    _meshy_pkg.QR_SCANNER_ENABLED = QR_SCANNER_ENABLED
    _meshy_pkg.SHORTCUTS_DIALOG_ENABLED = SHORTCUTS_DIALOG_ENABLED

    from meshy.main import main
    sys.exit(main(VERSION))
