#!/usr/bin/python3
# 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 = '26.07'
pkgdatadir = os.environ.get('MESHY_PKGDATADIR', '/usr/share/meshy')
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 = '/usr/share/locale'
QR_SCANNER_ENABLED = 'true' == 'true'
SHORTCUTS_DIALOG_ENABLED = 'true' == '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.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))
