Merge pull request '修复了部分功能的判断逻辑,修复了一些bug' (#6) from dev into main
Reviewed-on: #6
This commit is contained in:
commit
d3c0b005f9
@ -74,7 +74,7 @@ class App(tk.Tk):
|
|||||||
def __init__(self, start_path): # 初始化
|
def __init__(self, start_path): # 初始化
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.withdraw()
|
self.withdraw()
|
||||||
self.title("目录扫描器 V1.4")
|
self.title("目录扫描器 V1.4.1")
|
||||||
self.start_path = start_path
|
self.start_path = start_path
|
||||||
self.queue = Queue()
|
self.queue = Queue()
|
||||||
self.progress_queue = Queue()
|
self.progress_queue = Queue()
|
||||||
@ -158,26 +158,34 @@ class App(tk.Tk):
|
|||||||
def show_help(self):
|
def show_help(self):
|
||||||
messagebox.showinfo(
|
messagebox.showinfo(
|
||||||
"帮助",
|
"帮助",
|
||||||
"1. 双击文件夹可以展开/折叠\n",
|
"1. 双击文件夹可以展开/折叠\n2. 双击文件可以直接打开\n3. 右键单击文件/文件夹可以打开、删除文件/文件夹、进入所在目录\n4. 点击左上角文件菜单可以重新选择目录进行扫描\n5. 点击左上角视图菜单可以根据目录/文件大小、目录/文件名排序、刷新列表\n",
|
||||||
"2. 双击文件可以直接打开\n",
|
|
||||||
"3. 右键单击文件/文件夹可以打开、删除文件/文件夹、进入所在目录\n",
|
|
||||||
"4. 点击左上角文件菜单可以重新选择目录进行扫描\n",
|
|
||||||
"5. 点击左上角视图菜单可以根据目录/文件大小、目录/文件名排序、刷新列表\n",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def show_update_log(self):
|
def show_update_log(self):
|
||||||
messagebox.showinfo(
|
repo_owner = "ahdoawhfo"
|
||||||
"更新日志",
|
repo_name = "SpaceSniffer"
|
||||||
"V1.0 实现了基本的目录扫描、文件/目录大小统计功能\n",
|
base_url = "https://git.a6.wiki/api/v1/repos"
|
||||||
"\n",
|
|
||||||
"V1.1 新增了重新选择目录扫描功能,新增了进度条显示\n",
|
try:
|
||||||
"\n",
|
# 发送 GET 请求获取最新的 Release
|
||||||
"V1.2 新增了双击打开目录、文件的功能,实现了右键菜单\n",
|
response = requests.get(
|
||||||
"\n",
|
f"{base_url}/{repo_owner}/{repo_name}/releases/latest"
|
||||||
"V1.3 优化了界面UI\n",
|
)
|
||||||
"\n",
|
|
||||||
"V1.4 新增了扫描日志、检查更新功能\n",
|
if response.status_code == 200:
|
||||||
)
|
release_info = response.json()
|
||||||
|
latest_version = release_info["tag_name"]
|
||||||
|
release_notes = release_info["body"]
|
||||||
|
messagebox.showinfo(
|
||||||
|
"更新日志", f"版本: {latest_version}\n\n{release_notes}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
messagebox.showinfo(
|
||||||
|
"更新日志",
|
||||||
|
f"获取更新日志失败:{response.status_code}",
|
||||||
|
)
|
||||||
|
except requests.RequestException as e:
|
||||||
|
messagebox.showinfo("更新日志", f"获取更新日志时发生错误:{e}")
|
||||||
|
|
||||||
def show_log(self):
|
def show_log(self):
|
||||||
log_content = self.read_log_file() # 从日志文件中读取日志内容
|
log_content = self.read_log_file() # 从日志文件中读取日志内容
|
||||||
@ -209,16 +217,13 @@ class App(tk.Tk):
|
|||||||
|
|
||||||
def check_updates(self):
|
def check_updates(self):
|
||||||
# 创建一个新的 UpdateManager 实例,不销毁程序
|
# 创建一个新的 UpdateManager 实例,不销毁程序
|
||||||
update_manager = UpdateManager(self)
|
update_manager = UpdateManager(self, is_startup=False)
|
||||||
update_manager.check_latest_release()
|
update_manager.check_latest_release()
|
||||||
|
|
||||||
def show_about(self):
|
def show_about(self):
|
||||||
messagebox.showinfo(
|
messagebox.showinfo(
|
||||||
"关于",
|
"关于",
|
||||||
"一款开源的文件/目录扫描工具\n",
|
"一款开源的文件/目录扫描工具\n可以直观地展示目录的文件结构以及文件大小\n\n软件版本 V1.4.1\n作者 ahdoawhfo\n",
|
||||||
"可以直观地展示目录的文件结构以及文件大小\n",
|
|
||||||
"软件版本 V1.4\n",
|
|
||||||
"作者 ahdoawhfo\n",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_double_click(self, event): # V1.2 Update:当双击的是文件时,打开文件
|
def on_double_click(self, event): # V1.2 Update:当双击的是文件时,打开文件
|
||||||
@ -457,8 +462,8 @@ class App(tk.Tk):
|
|||||||
def on_close(self): # 关闭程序
|
def on_close(self): # 关闭程序
|
||||||
if self.scanner.is_alive():
|
if self.scanner.is_alive():
|
||||||
self.scanner.join()
|
self.scanner.join()
|
||||||
self.destroy()
|
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
exit()
|
||||||
|
|
||||||
def set_window_size(self): # 设置窗口大小
|
def set_window_size(self): # 设置窗口大小
|
||||||
screen_width = self.winfo_screenwidth()
|
screen_width = self.winfo_screenwidth()
|
||||||
@ -512,15 +517,16 @@ class ProgressWindow(tk.Toplevel): # 进度窗口
|
|||||||
|
|
||||||
|
|
||||||
class UpdateManager:
|
class UpdateManager:
|
||||||
def __init__(self, root):
|
def __init__(self, root=None, is_startup=True):
|
||||||
self.root = root
|
self.root = root
|
||||||
|
self.is_startup = is_startup
|
||||||
|
|
||||||
def check_latest_release(self):
|
def check_latest_release(self):
|
||||||
# Gitea 仓库信息和当前软件版本
|
# Gitea 仓库信息和当前软件版本
|
||||||
repo_owner = "ahdoawhfo"
|
repo_owner = "ahdoawhfo"
|
||||||
repo_name = "SpaceSniffer"
|
repo_name = "SpaceSniffer"
|
||||||
base_url = "https://git.a6.wiki/api/v1/repos"
|
base_url = "https://git.a6.wiki/api/v1/repos"
|
||||||
current_version = "1.4" # 替换成你的当前软件版本
|
current_version = "1.4.1" # 替换成你的当前软件版本
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 发送 GET 请求获取最新的 Release
|
# 发送 GET 请求获取最新的 Release
|
||||||
@ -541,18 +547,25 @@ class UpdateManager:
|
|||||||
# 打开浏览器到 release 页面
|
# 打开浏览器到 release 页面
|
||||||
release_url = release_info["html_url"]
|
release_url = release_info["html_url"]
|
||||||
webbrowser.open_new(release_url)
|
webbrowser.open_new(release_url)
|
||||||
if self.root:
|
if self.is_startup:
|
||||||
self.destroy()
|
return False
|
||||||
root.destroy()
|
else:
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
self.show_message("检查更新", "当前版本已经是最新版本")
|
if not self.is_startup: # 仅在用户点击检查更新时显示
|
||||||
|
self.show_message("检查更新", "当前版本已经是最新版本")
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
self.show_message(
|
if not self.is_startup: # 仅在用户点击检查更新时显示
|
||||||
"检查更新",
|
self.show_message(
|
||||||
f"获取最新 Release 失败:{response.status_code}",
|
"获取 Release 失败",
|
||||||
)
|
f"获取最新 Release 失败:{response.status_code}",
|
||||||
|
)
|
||||||
|
return True
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
self.show_message("检查更新", f"请求最新 Release 时发生错误:{e}")
|
if not self.is_startup: # 仅在用户点击检查更新时显示
|
||||||
|
self.show_message("请求错误", f"请求最新 Release 时发生错误:{e}")
|
||||||
|
return True
|
||||||
|
|
||||||
def prompt_update(self, latest_version, release_notes):
|
def prompt_update(self, latest_version, release_notes):
|
||||||
prompt_message = f"检查更新: {latest_version}\n\n更新说明:\n{release_notes}\n\n是否立即更新?"
|
prompt_message = f"检查更新: {latest_version}\n\n更新说明:\n{release_notes}\n\n是否立即更新?"
|
||||||
@ -560,7 +573,10 @@ class UpdateManager:
|
|||||||
return choice
|
return choice
|
||||||
|
|
||||||
def show_message(self, title, message):
|
def show_message(self, title, message):
|
||||||
messagebox.showinfo(title, message)
|
if self.root:
|
||||||
|
messagebox.showinfo(title, message)
|
||||||
|
else:
|
||||||
|
print(f"{title}: {message}")
|
||||||
|
|
||||||
|
|
||||||
def clear_log_file():
|
def clear_log_file():
|
||||||
@ -577,8 +593,11 @@ if __name__ == "__main__":
|
|||||||
clear_log_file()
|
clear_log_file()
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
app = UpdateManager(root)
|
update_manager = UpdateManager(root, is_startup=True)
|
||||||
app.check_latest_release()
|
proceed = update_manager.check_latest_release()
|
||||||
|
if not proceed:
|
||||||
|
root.destroy()
|
||||||
|
exit()
|
||||||
start_path = filedialog.askdirectory()
|
start_path = filedialog.askdirectory()
|
||||||
if start_path:
|
if start_path:
|
||||||
app = App(start_path)
|
app = App(start_path)
|
||||||
@ -586,3 +605,4 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
messagebox.showinfo("提示", "没有选中任何目录,程序即将退出")
|
messagebox.showinfo("提示", "没有选中任何目录,程序即将退出")
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
exit()
|
||||||
|
Loading…
Reference in New Issue
Block a user