From 80a2ccd01f70ebe3a2a7f5450af5c1d511711bdc Mon Sep 17 00:00:00 2001 From: Polaris Date: Thu, 29 Aug 2024 11:03:57 +0800 Subject: [PATCH] release-v1.0.0 --- CopyReplace/main.py | 14 ++++++++++++-- CopyReplace/{main2.py => main_v2.py} | 5 ++--- README.md | 9 +++++++++ dist/config.ini | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) rename CopyReplace/{main2.py => main_v2.py} (92%) diff --git a/CopyReplace/main.py b/CopyReplace/main.py index c7d747b..73d955d 100644 --- a/CopyReplace/main.py +++ b/CopyReplace/main.py @@ -1,4 +1,5 @@ import platform +import subprocess import pyperclip import time import configparser @@ -76,16 +77,25 @@ def on_quit(icon, item): def on_restart(icon, item): python = sys.executable - os.execl(python, python, *sys.argv) + icon.stop() # 停止托盘图标,释放资源 + + # 添加延时,等待资源释放 + time.sleep(2) # 等待2秒(你可以根据需要调整时间) + + subprocess.Popen([python] + sys.argv) + sys.exit() # 退出当前进程 # 设置系统托盘图标和菜单 def setup_tray_icon(): # 使用本地图片作为托盘图标 - icon = Icon("Link2Zotero", Image.open(icon_path), "Link2Zotero", Menu( + image = Image.open(icon_path) + icon = Icon("Link2Zotero", image, "Link2Zotero", Menu( MenuItem('Restart', on_restart), MenuItem('Quit', on_quit) )) icon.run() + image.close() # 确保图像文件在使用后被关闭 + if __name__ == "__main__": # 启动剪贴板监控线程 diff --git a/CopyReplace/main2.py b/CopyReplace/main_v2.py similarity index 92% rename from CopyReplace/main2.py rename to CopyReplace/main_v2.py index 2faa3ba..d1ce2af 100644 --- a/CopyReplace/main2.py +++ b/CopyReplace/main_v2.py @@ -8,14 +8,13 @@ import threading from notifypy import Notify - def repl(match: re.Match): return "https://hichennyang.github.io/zotero-link/#{}".format(match.group()) def main(): notification = Notify( default_notification_application_name = "zotero-link", - default_notification_icon = "logo.png" + default_notification_icon = "Link2Zotero_2.png" ) # pattern = r"zotero://\S*\)\)" pattern = r'(? None: if __name__ == "__main__": Icon( "zotero-link", - icon = Image.open("logo.png"), + icon = Image.open("Link2Zotero_2.png"), title = "zotero-link", menu = Menu( MenuItem("退出", quit) diff --git a/README.md b/README.md index 8da502f..dc1880f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ ## 介绍 + + + +## 手动编译方法 +```bash +cd path/to/Link2Zotero +pyinstaller --onefile --icon=Link2Zotero_2.ico --noconsole .\CopyReplace\main.py +``` + diff --git a/dist/config.ini b/dist/config.ini index 34b90a9..4022d34 100644 --- a/dist/config.ini +++ b/dist/config.ini @@ -3,4 +3,4 @@ [Settings] replace_url = "https://flaribbit.github.io/zotero-link/#zotero://" -icon_path = "D:\Github\Tools\Link2Zotero\CopyReplace\Link2Zotero_2.ico" +icon_path = "D:/Github/Tools/Link2Zotero/dist/Link2Zotero_2.ico"