示例#1
0
def update_fallback(config: CommonConfig):
    if not is_windows():
        return

    try:
        # 到这里一般是无法访问github,这时候试试gitee的方案
        latest_version = get_version_from_gitee()
        ui = UpdateInfo()
        ui.latest_version = latest_version
        ui.netdisk_link = config.netdisk_link
        ui.netdisk_passcode = "fzls"
        ui.update_message = "当前无法访问github,暂时无法获取更新内容,若欲知更新内容,请浏览gitee主页进行查看哦~\n\nhttps://gitee.com/fzls/djc_helper/blob/master/CHANGELOG.MD"

        try_manaual_update(ui)
    except Exception as err:
        logger.error(
            f"手动检查版本更新失败(这个跟自动更新没有任何关系),大概率是访问不了github和gitee导致的,可自行前往网盘查看是否有更新, 错误为{err}"
            + color("bold_green") + f"\n(无法理解上面这段话的话,就当没看见这段话,对正常功能没有任何影响)")

        # 如果一直连不上github,则尝试判断距离上次更新的时间是否已经很长
        time_since_last_update = datetime.now() - datetime.strptime(
            ver_time, "%Y.%m.%d")
        if time_since_last_update.days >= 7:
            msg = f"无法访问github确认是否有新版本,而当前版本更新于{ver_time},距今已有{time_since_last_update},很可能已经有新的版本,建议打开目录中的[网盘链接]看看是否有新版本,或者购买自动更新DLC省去手动更新的操作\n\n(如果已购买自动更新DLC,就无视这句话)"
            logger.info(color("bold_green") + msg)
            if is_first_run(
                    f"notify_manual_update_if_can_not_connect_github_v{now_version}"
            ):
                win32api.MessageBox(0, msg, "更新提示",
                                    win32con.MB_ICONINFORMATION)
                webbrowser.open(config.netdisk_link)
示例#2
0
def message_box(msg,
                title,
                print_log=True,
                icon=MB_ICONINFORMATION,
                open_url="",
                show_once=False,
                follow_flag_file=True,
                color_name="bold_cyan",
                open_image="",
                show_once_daily=False):
    get_log_func(logger.warning, print_log)(color(color_name) + msg)

    if is_run_in_github_action():
        return

    from first_run import is_daily_first_run, is_first_run

    show_message_box = True
    if show_once and not is_first_run(f"message_box_{title}"):
        show_message_box = False
    if show_once_daily and not is_daily_first_run(
            f"daily_message_box_{title}"):
        show_message_box = False
    if follow_flag_file and exists_flag_file('.no_message_box'):
        show_message_box = False

    if show_message_box and is_windows():
        win32api.MessageBox(0, msg, title, icon)

    if open_url != "":
        webbrowser.open(open_url)

    if open_image != "":
        os.popen(os.path.realpath(open_image))
示例#3
0
def show_tip_on_first_run(first_run_tip_name,
                          title,
                          tips,
                          loginfo,
                          show_count=1):
    if not is_first_run(f"show_tip_{first_run_tip_name}"):
        logger.debug(f"{first_run_tip_name} 已经提示过,不再展示")
        return

    # 仅在window系统下检查
    if platform.system() != "Windows":
        return

    # 如果在github action环境下,则不弹窗
    if is_run_in_github_action():
        return

    # 若是首次运行,提示相关信息
    logger.info(loginfo)

    for i in range(show_count):
        _title = title
        if show_count != 1:
            _title = f"第{i + 1}/{show_count}次提示 {title}"
        message_box(tips, _title)
示例#4
0
    def need_show(self) -> bool:
        key = self.get_first_run_key()

        # 判断是否过期
        if get_now() > parse_time(self.expire_at):
            return False

        # 判断是否满足版本需求
        if self.show_only_before_version != "" and not version_less(
                now_version, self.show_only_before_version):
            return False

        # 根据显示类型判断
        if self.show_type == NoticeShowType.ONCE:
            return is_first_run(key)
        elif self.show_type == NoticeShowType.DAILY:
            return is_daily_first_run(key)
        elif self.show_type == NoticeShowType.WEEKLY:
            return is_weekly_first_run(key)
        elif self.show_type == NoticeShowType.MONTHLY:
            return is_monthly_first_run(key)
        elif self.show_type == NoticeShowType.ALWAYS:
            return True
        elif self.show_type == NoticeShowType.DEPRECATED:
            return False
        else:
            return False
示例#5
0
文件: util.py 项目: Fine112358/dnf-
def message_box(msg,
                title,
                print_log=True,
                icon=win32con.MB_ICONWARNING,
                open_url="",
                show_once=False,
                follow_flag_file=True):
    if print_log:
        logger.warning(color("bold_cyan") + msg)

    if is_run_in_github_action():
        return

    from first_run import is_first_run

    show_message_box = True
    if show_once and not is_first_run(f"message_box_{title}"):
        show_message_box = False
    if follow_flag_file and exists_flag_file('.no_message_box'):
        show_message_box = False

    if show_message_box:
        win32api.MessageBox(0, msg, title, icon)

    if open_url != "":
        webbrowser.open(open_url)
示例#6
0
def show_update_info_on_first_run(ui: UpdateInfo):
    if now_version == ui.latest_version and is_first_run(
            f"update_version_v{ui.latest_version}"):
        message = (
            f"新版本v{ui.latest_version}已更新完毕,并成功完成首次运行。本次具体更新内容展示如下,以供参考:\n"
            f"{ui.update_message}")

        async_message_box(message, "更新")
示例#7
0
def show_update_info_on_first_run(ui: UpdateInfo):
    if now_version == ui.latest_version and is_first_run(
            f"update_version_v{ui.latest_version}") and not use_by_myself():
        message = (
            f"新版本v{ui.latest_version}已更新完毕,并成功完成首次运行。本次具体更新内容展示如下,以供参考:\n"
            f"{ui.update_message}")

        def cb():
            win32api.MessageBox(0, message, "更新", win32con.MB_OK)

        async_call(cb)