#!/usr/bin/env python3
# Copyright (C) 2023 Stewart Adam
# This file is part of fwbackups.

# fwbackups is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# fwbackups is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with fwbackups; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
import os
import sys

launched_from = os.path.dirname(os.path.realpath(__file__))
if os.path.exists(os.path.join(launched_from, '../fwbackups/__init__.py')):  # check if we are running from source
    sys.path.append('../fwbackups')

from fwbackups.ui import main
from fwbackups import const as constants

if __name__ == "__main__":
    if constants.IS_FLATPAK and 'XDG_RUNTIME_DIR' in os.environ and 'FLATPAK_ID' in os.environ:
        XDG_RUNTIME_DIR = os.environ.get('XDG_RUNTIME_DIR')
        FLATPAK_ID = os.environ.get('FLATPAK_ID')
        os.environ['TMPDIR'] = f"{XDG_RUNTIME_DIR}/app/{FLATPAK_ID}"

    sys.exit(main(sys.argv))
