예제 #1
0
    def run(self) -> None:
        # setup gui
        set_env(title="Alas", output_animation=False)
        add_css(filepath_css('alas'))
        if self.is_mobile:
            add_css(filepath_css('alas-mobile'))
        else:
            add_css(filepath_css('alas-pc'))

        if self.theme == 'dark':
            add_css(filepath_css('dark-alas'))
        else:
            add_css(filepath_css('light-alas'))

        # Auto refresh when lost connection
        # [For develop] Disable by run `reload=0` in console
        run_js('''
        reload = 1;
        WebIO._state.CurrentSession.on_session_close(
            ()=>{
                setTimeout(
                    ()=>{
                        if (reload == 1){
                            location.reload();
                        }
                    }, 4000
                )
            }
        );
        ''')

        aside = get_localstorage('aside')
        self.show()

        # detect config change
        _thread_wait_config_change = Thread(
            target=self._alas_thread_wait_config_change)
        register_thread(_thread_wait_config_change)
        _thread_wait_config_change.start()

        # save config
        _thread_save_config = Thread(target=self._alas_thread_update_config)
        register_thread(_thread_save_config)
        _thread_save_config.start()

        visibility_state_switch = Switch(status={
            True: [
                lambda: self.__setattr__('visible', True),
                lambda: self.alas_update_overiew_task()
                if self.page == 'Overview' else 0,
                lambda: self.task_handler._task.__setattr__('delay', 15)
            ],
            False: [
                lambda: self.__setattr__('visible', False),
                lambda: self.task_handler._task.__setattr__('delay', 1)
            ]
        },
                                         get_state=get_window_visibility_state,
                                         name='visibility_state')

        self.state_switch = Switch(
            status=self.set_status,
            get_state=lambda: getattr(getattr(self, 'alas', -1), 'state', 0),
            name='state')

        def goto_update():
            self.ui_develop()
            self.dev_update()

        update_switch = Switch(status={
            1:
            lambda: toast(t("Gui.Toast.ClickToUpdate"),
                          duration=0,
                          position='right',
                          color='success',
                          onclick=goto_update)
        },
                               get_state=lambda: updater.state,
                               name='update_state')

        self.task_handler.add(self.state_switch.g(), 2)
        self.task_handler.add(visibility_state_switch.g(), 15)
        self.task_handler.add(update_switch.g(), 1)
        self.task_handler.start()

        # Return to previous page
        if aside not in ["Develop", "Home", None]:
            self.ui_alas(aside)
예제 #2
0
    def dev_update(self) -> None:
        self.init_menu(name="Update")
        self.set_title(t("Gui.MenuDevelop.Update"))

        if not Setting.reload:
            put_warning(t("Gui.Update.DisabledWarn"))

        put_row(
            content=[
                put_scope("updater_loading"), None,
                put_scope("updater_state")
            ],
            size="auto .25rem 1fr",
        )

        put_scope("updater_btn")
        put_scope("updater_info")

        def update_table():
            with use_scope("updater_info", clear=True):
                local_commit = updater.get_commit(short_sha1=True)
                upstream_commit = updater.get_commit(
                    f"origin/{updater.branch}", short_sha1=True)
                put_table(
                    [
                        [t("Gui.Update.Local"), *local_commit],
                        [t("Gui.Update.Upstream"), *upstream_commit],
                    ],
                    header=[
                        "",
                        "SHA1",
                        t("Gui.Update.Author"),
                        t("Gui.Update.Time"),
                        t("Gui.Update.Message"),
                    ],
                )

        def u(state):
            if state == -1:
                return
            clear("updater_loading")
            clear("updater_state")
            clear("updater_btn")
            if state == 0:
                put_loading("border", "secondary",
                            "updater_loading").style("--loading-border-fill--")
                put_text(t("Gui.Update.UpToDate"), scope="updater_state")
                put_button(
                    t("Gui.Button.CheckUpdate"),
                    onclick=updater.check_update,
                    color="info",
                    scope="updater_btn",
                )
                update_table()
            elif state == 1:
                put_loading("grow", "success",
                            "updater_loading").style("--loading-grow--")
                put_text(t("Gui.Update.HaveUpdate"), scope="updater_state")
                put_button(
                    t("Gui.Button.ClickToUpdate"),
                    onclick=updater.run_update,
                    color="success",
                    scope="updater_btn",
                )
                update_table()
            elif state == "checking":
                put_loading("border", "primary",
                            "updater_loading").style("--loading-border--")
                put_text(t("Gui.Update.UpdateChecking"), scope="updater_state")
            elif state == "failed":
                put_loading("grow", "danger",
                            "updater_loading").style("--loading-grow--")
                put_text(t("Gui.Update.UpdateFailed"), scope="updater_state")
                put_button(
                    t("Gui.Button.RetryUpdate"),
                    onclick=updater.run_update,
                    color="primary",
                    scope="updater_btn",
                )
            elif state == "start":
                put_loading("border", "primary",
                            "updater_loading").style("--loading-border--")
                put_text(t("Gui.Update.UpdateStart"), scope="updater_state")
                put_button(
                    t("Gui.Button.CancelUpdate"),
                    onclick=updater.cancel,
                    color="danger",
                    scope="updater_btn",
                )
            elif state == "wait":
                put_loading("border", "primary",
                            "updater_loading").style("--loading-border--")
                put_text(t("Gui.Update.UpdateWait"), scope="updater_state")
                put_button(
                    t("Gui.Button.CancelUpdate"),
                    onclick=updater.cancel,
                    color="danger",
                    scope="updater_btn",
                )
            elif state == "run update":
                put_loading("border", "primary",
                            "updater_loading").style("--loading-border--")
                put_text(t("Gui.Update.UpdateRun"), scope="updater_state")
                put_button(
                    t("Gui.Button.CancelUpdate"),
                    onclick=updater.cancel,
                    color="danger",
                    scope="updater_btn",
                    disabled=True,
                )
            elif state == "reload":
                put_loading("grow", "success",
                            "updater_loading").style("--loading-grow--")
                put_text(t("Gui.Update.UpdateSuccess"), scope="updater_state")
                update_table()
            elif state == "finish":
                put_loading("grow", "success",
                            "updater_loading").style("--loading-grow--")
                put_text(t("Gui.Update.UpdateFinish"), scope="updater_state")
                update_table()
            elif state == "cancel":
                put_loading("border", "danger",
                            "updater_loading").style("--loading-border--")
                put_text(t("Gui.Update.UpdateCancel"), scope="updater_state")
                put_button(
                    t("Gui.Button.CancelUpdate"),
                    onclick=updater.cancel,
                    color="danger",
                    scope="updater_btn",
                    disabled=True,
                )
            else:
                put_text(
                    "Something went wrong, please contact develops",
                    scope="updater_state",
                )
                put_text(f"state: {state}", scope="updater_state")

        updater_switch = Switch(status=u,
                                get_state=lambda: updater.state,
                                name="updater")

        update_table()
        self.task_handler.add(updater_switch.g(),
                              delay=0.5,
                              pending_delete=True)

        updater.check_update()
예제 #3
0
    def dev_update(self) -> None:
        self.init_menu(name='Update')
        self.set_title(t("Gui.MenuDevelop.Update"))

        if not Setting.reload:
            put_warning(t("Gui.Update.DisabledWarn"))

        put_row(content=[
            put_scope('updater_loading'), None,
            put_scope('updater_state')
        ],
                size='auto .25rem 1fr')

        put_scope('updater_btn')
        put_scope('updater_info')

        def update_table():
            with use_scope('updater_info', clear=True):
                local_commit = updater.get_commit(short_sha1=True)
                upstream_commit = updater.get_commit(
                    f'origin/{updater.branch}', short_sha1=True)
                put_table([[t('Gui.Update.Local'), *local_commit],
                           [t('Gui.Update.Upstream'), *upstream_commit]],
                          header=[
                              '', 'SHA1',
                              t('Gui.Update.Author'),
                              t('Gui.Update.Time'),
                              t('Gui.Update.Message')
                          ])

        def u(state):
            if state == -1:
                return
            clear('updater_loading')
            clear('updater_state')
            clear('updater_btn')
            if state == 0:
                put_loading('border', 'secondary',
                            'updater_loading').style("--loading-border-fill--")
                put_text(t('Gui.Update.UpToDate'), scope='updater_state')
                put_button(t('Gui.Button.CheckUpdate'),
                           onclick=updater.check_update,
                           color='info',
                           scope='updater_btn')
                update_table()
            elif state == 1:
                put_loading('grow', 'success',
                            'updater_loading').style("--loading-grow--")
                put_text(t('Gui.Update.HaveUpdate'), scope='updater_state')
                put_button(t('Gui.Button.ClickToUpdate'),
                           onclick=updater.run_update,
                           color='success',
                           scope='updater_btn')
                update_table()
            elif state == 'checking':
                put_loading('border', 'primary',
                            'updater_loading').style("--loading-border--")
                put_text(t('Gui.Update.UpdateChecking'), scope='updater_state')
            elif state == 'failed':
                put_loading('grow', 'danger',
                            'updater_loading').style("--loading-grow--")
                put_text(t('Gui.Update.UpdateFailed'), scope='updater_state')
                put_button(t('Gui.Button.RetryUpdate'),
                           onclick=updater.run_update,
                           color='primary',
                           scope='updater_btn')
            elif state == 'start':
                put_loading('border', 'primary',
                            'updater_loading').style("--loading-border--")
                put_text(t('Gui.Update.UpdateStart'), scope='updater_state')
                put_button(t('Gui.Button.CancelUpdate'),
                           onclick=updater.cancel,
                           color='danger',
                           scope='updater_btn')
            elif state == 'wait':
                put_loading('border', 'primary',
                            'updater_loading').style("--loading-border--")
                put_text(t('Gui.Update.UpdateWait'), scope='updater_state')
                put_button(t('Gui.Button.CancelUpdate'),
                           onclick=updater.cancel,
                           color='danger',
                           scope='updater_btn')
            elif state == 'run update':
                put_loading('border', 'primary',
                            'updater_loading').style("--loading-border--")
                put_text(t('Gui.Update.UpdateRun'), scope='updater_state')
                put_button(t('Gui.Button.CancelUpdate'),
                           onclick=updater.cancel,
                           color='danger',
                           scope='updater_btn',
                           disabled=True)
            elif state == 'reload':
                put_loading('grow', 'success',
                            'updater_loading').style("--loading-grow--")
                put_text(t('Gui.Update.UpdateSuccess'), scope='updater_state')
                update_table()
            elif state == 'finish':
                put_loading('grow', 'success',
                            'updater_loading').style("--loading-grow--")
                put_text(t('Gui.Update.UpdateFinish'), scope='updater_state')
                update_table()
            elif state == 'cancel':
                put_loading('border', 'danger',
                            'updater_loading').style("--loading-border--")
                put_text(t('Gui.Update.UpdateCancel'), scope='updater_state')
                put_button(t('Gui.Button.CancelUpdate'),
                           onclick=updater.cancel,
                           color='danger',
                           scope='updater_btn',
                           disabled=True)
            else:
                put_text("Something went wrong, please contact develops",
                         scope='updater_state')
                put_text(f"state: {state}", scope='updater_state')

        updater_switch = Switch(status=u,
                                get_state=lambda: updater.state,
                                name='updater')

        update_table()
        self.task_handler.add(updater_switch.g(),
                              delay=0.5,
                              pending_delete=True)

        updater.check_update()
예제 #4
0
    def dev_remote(self) -> None:
        self.init_menu(name="Remote")
        self.set_title(t("Gui.MenuDevelop.Remote"))
        put_row(
            content=[put_scope("remote_loading"), None, put_scope("remote_state")],
            size="auto .25rem 1fr",
        )
        put_scope("remote_info")

        def u(state):
            if state == -1:
                return
            clear("remote_loading")
            clear("remote_state")
            clear("remote_info")
            if state in (1, 2):
                put_loading("grow", "success", "remote_loading").style(
                    "--loading-grow--"
                )
                put_text(t("Gui.Remote.Running"), scope="remote_state")
                put_text(t("Gui.Remote.EntryPoint"), scope="remote_info")
                entrypoint = RemoteAccess.get_entry_point()
                if entrypoint:
                    if State.electron:  # Prevent click into url in electron client
                        put_text(entrypoint, scope="remote_info").style(
                            "text-decoration-line: underline"
                        )
                    else:
                        put_link(name=entrypoint, url=entrypoint, scope="remote_info")
                else:
                    put_text("Loading...", scope="remote_info")
            elif state in (0, 3):
                put_loading("border", "secondary", "remote_loading").style(
                    "--loading-border-fill--"
                )
                if (
                    State.deploy_config.EnableRemoteAccess
                    and State.deploy_config.Password
                ):
                    put_text(t("Gui.Remote.NotRunning"), scope="remote_state")
                else:
                    put_text(t("Gui.Remote.NotEnable"), scope="remote_state")
                put_text(t("Gui.Remote.ConfigureHint"), scope="remote_info")
                url = "http://app.azurlane.cloud" + (
                    "" if State.deploy_config.Language.startswith("zh") else "/en.html"
                )
                put_html(
                    f'<a href="{url}" target="_blank">{url}</a>', scope="remote_info"
                )
                if state == 3:
                    put_warning(
                        t("Gui.Remote.SSHNotInstall"),
                        closable=False,
                        scope="remote_info",
                    )

        remote_switch = Switch(
            status=u, get_state=RemoteAccess.get_state, name="remote"
        )

        self.task_handler.add(remote_switch.g(), delay=1, pending_delete=True)