from typing import Optional

import omni.ext
import omni.ui as ui
from omni.kit.welcome.window import register_page

from .open_widget import OpenWidget


class OpenPageExtension(omni.ext.IExt):
    def on_startup(self, ext_id):
        self._widget: Optional[OpenWidget] = None

        self.__ext_name = omni.ext.get_extension_name(ext_id)
        register_page(self.__ext_name, self.build_ui)

    def on_shutdown(self):
        if self._widget:
            self._widget.destroy()
            self._widget = None

    def build_ui(self) -> None:
        self._widget = OpenWidget()
