#!/usr/pkg/bin/python3.13
import os
import sys

import gi

if __name__ == "__main__":
    systempath = "/usr/pkg/share/syncthing-gtk"
    installpath =  os.path.join(os.path.dirname(os.path.realpath(__file__)),
            '..', 'share', 'syncthing-gtk')
    localpath = "/usr/local/share/syncthing-gtk"
    paths = (systempath, localpath, installpath)
    # let gettext to decide
    localedir = None
    for path in paths:
        if os.path.exists(path):
            localedir = os.path.join(path, '..', 'locale')
            break
    else:
        raise IOError("Could not find files in %r", paths)

    gi.require_version('Gtk', '3.0')
    gi.require_version('Gdk', '3.0')
    gi.require_version('Rsvg', '2.0')

    from syncthing_gtk.tools import init_locale, init_logging
    init_locale(localedir)
    init_logging()

    if "APPDIR" in os.environ:
        # Running as AppImage
        from gi.repository import Gtk
        Gtk.IconTheme.get_default().prepend_search_path(os.environ["APPDIR"])
        Gtk.IconTheme.get_default().prepend_search_path(os.environ["APPDIR"] + "/usr/pkg/share/icons/hicolor/32x32/apps")
        Gtk.IconTheme.get_default().prepend_search_path(os.environ["APPDIR"] + "/usr/pkg/share/icons/hicolor/32x32/status")

    from syncthing_gtk.app import App
    App(path, os.path.join(path, "icons")).run(sys.argv)
