#!/bin/python3
import argparse
import os
import sys
import gi

gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
from gi.repository import Gio, Gtk, Gdk


if __name__ == "__main__":
    import stillCenter.constants as constants
    import stillCenter.i18n as i18n
    from stillCenter.logutil import configure_logging
    import logging

    i18n.setup_gettext()
    _ = i18n._

    import stillCenter.StillCenterApp as App

    parser = argparse.ArgumentParser(add_help=True)
    parser.add_argument("--debug", action="store_true", help=_("Enable verbose stillCenter logs"))
    parser.add_argument("--log-level", default="INFO", help=_("Set log level (DEBUG, INFO, WARNING, ERROR)"))
    parser.add_argument("--log-file", help=_("Also write logs to a file"))
    args, remaining_argv = parser.parse_known_args()

    configure_logging(debug=args.debug, level=args.log_level, log_file=args.log_file)
    logger = logging.getLogger("stillCenter")
    logger.info("Starting stillCenter")

    # Load GResource
    resource_path = os.path.join(constants.DATA_DIR, "io.stillhq.stillCenter.gresource")
    if os.path.exists(resource_path):
        resource = Gio.Resource.load(resource_path)
        Gio.Resource._register(resource)

        # Add icons to the icon theme
        icon_theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default())
        icon_theme.add_resource_path("/io/stillhq/stillCenter/icons/")
        logger.debug("Added icons to the icon theme from GResource")
        # icon_theme.add_resource_path("/io/stillhq/stillCenter/icons/16x16/symbolic/")
    else:
        logger.warning("GResource not found at %s", resource_path)

    app = App.StillCenter()
    app.run([sys.argv[0], *remaining_argv])
