Skip to content

Commit

Permalink
按需下载cloudflared
Browse files Browse the repository at this point in the history
  • Loading branch information
FishHawk committed Oct 31, 2024
1 parent 4bf0812 commit 1fe973e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

Binary file removed cloudflared-windows-amd64.exe
Binary file not shown.
10 changes: 4 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ def __init__(self):
self.gpu_manager = GPUManager()
self.init_navigation()
self.init_window()
cloudflared_path = get_resource_path(CLOUDFLARED)
if not os.path.exists(cloudflared_path):
MessageBox(
"错误", f"cloudflared 可执行文件不存在: {cloudflared_path}", self
).exec()
self.setMinimumSize(600, 700)
self.load_window_state()

Expand Down Expand Up @@ -86,7 +81,10 @@ def init_window(self):
self.run_llamacpp_batch_bench
)

# 连接设置更改信号
self.cf_share_section.request_download_cloudflared.connect(
self.dowload_section.start_download_cloudflared
)

self.settings_section.sig_need_update.connect(
self.dowload_section.start_download_launcher
)
Expand Down
2 changes: 1 addition & 1 deletion src/llamacpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def __init__(

class LlamacppList(QObject):
DOWNLOAD_SRC = [
"GitHub",
"GHProxy",
"GitHub",
]
CUDART = {
"filename": "cudart-llama-bin-win-cu12.2.0-x64.zip",
Expand Down
32 changes: 27 additions & 5 deletions src/section_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def stop(self):


class DownloadSection(QFrame):
llamacpp_download_src = "GHProxy"
llamacpp_download_src = LLAMACPP_LIST.DOWNLOAD_SRC[0]
sakura_download_src = SAKURA_LIST.DOWNLOAD_SRC[0]
download_tasks: List[DownloadTask] = []
download_threads: List[QThread] = []
Expand Down Expand Up @@ -350,7 +350,7 @@ def on_error(error_message):
self.download_threads.append(thread)

logging.info(f"开始下载: URL={new_task.url}, 文件名={new_task.filename}")
UiInfoBarSuccess(self, f"{new_task.name}开始下载")
UiInfoBarSuccess(self, f"{new_task.name}开始下载,请在下载进度页面查看进度")

def _update_current_llamacpp_version(self):
version = get_llamacpp_version(os.path.join(CURRENT_DIR, "llama"))
Expand Down Expand Up @@ -434,14 +434,36 @@ def on_download_llamacpp_finish():

def start_download_launcher(self, version: str):
filename = f"Sakura_Launcher_GUI_{version}.exe"
url = f"https://github.com/PiDanShouRouZhouXD/Sakura_Launcher_GUI/releases/download/{version}/{filename}"
if self.llamacpp_download_src == "GHProxy":
url = "https://ghp.ci/" + url

task = DownloadTask(
name="Sakura启动器",
url=f"https://github.com/PiDanShouRouZhouXD/Sakura_Launcher_GUI/releases/download/{version}/{filename}",
url=url,
filename=filename,
)

def on_download_llamacpp_finish():
def on_finish():
task.state = DownloadTaskState.SUCCESS
UiInfoBarSuccess(self, f"{task.name}下载成功")

self._start_download_task(task, on_finish=on_download_llamacpp_finish)
self._start_download_task(task, on_finish=on_finish)

def start_download_cloudflared(self):
filename = "cloudflared-windows-amd64.exe"
url = "https://github.com/cloudflare/cloudflared/releases/download/2024.10.1/cloudflared-windows-amd64.exe"
if self.llamacpp_download_src == "GHProxy":
url = "https://ghp.ci/" + url

task = DownloadTask(
name="Cloudflared",
url=url,
filename=filename,
)

def on_finish():
task.state = DownloadTaskState.SUCCESS
UiInfoBarSuccess(self, f"{task.name}下载成功")

self._start_download_task(task, on_finish=on_finish)
10 changes: 9 additions & 1 deletion src/section_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def run(self):


class CFShareSection(QFrame):
request_download_cloudflared = Signal()

def __init__(self, title, main_window, parent=None):
super().__init__(parent)
self.main_window = main_window
Expand Down Expand Up @@ -121,7 +123,7 @@ def init_share_page(self):
layout = QVBoxLayout(self.share_page)
layout.setContentsMargins(0, 0, 0, 0) # 设置内部边距

self.refresh_slots_button = PushButton(FIF.SYNC, "刷新在线数量")
self.refresh_slots_button = PushButton(FIF.SYNC, "刷新")
self.refresh_slots_button.clicked.connect(self.refresh_slots)

self.stop_button = PushButton(FIF.CLOSE, "下线")
Expand Down Expand Up @@ -349,6 +351,12 @@ def on_metrics_refreshed(self, metrics):

@Slot()
def start_cf_share(self):
cloudflared_path = os.path.join(os.path.abspath("."), CLOUDFLARED)
if not os.path.exists(cloudflared_path):
UiInfoBarWarning(self, "未检测到Cloudflared,请等待下载完成后再上线。")
self.request_download_cloudflared.emit()
return

worker_url = self.worker_url_input.text().strip()
if not worker_url:
MessageBox("错误", "请输入WORKER_URL", self).exec_()
Expand Down

0 comments on commit 1fe973e

Please sign in to comment.