From 9ecf1c675731e493c8ec840282983fa4f8503c09 Mon Sep 17 00:00:00 2001 From: Egor Date: Wed, 3 Dec 2025 18:17:45 -0800 Subject: [PATCH] allow port to be clearable, store cloudflared bin in gerbil installation directory --- .vscode/settings.json | 2 +- src/components/screens/Launch/NetworkTab.tsx | 13 ++----------- src/main/modules/koboldcpp/tunnel.ts | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3584bb6..ba7d7d7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,5 +13,5 @@ "editor.defaultFormatter": "prettier.prettier-vscode", "[typescriptreact]": { "editor.defaultFormatter": "prettier.prettier-vscode" - }, + } } diff --git a/src/components/screens/Launch/NetworkTab.tsx b/src/components/screens/Launch/NetworkTab.tsx index 5e09d66..cc287b4 100644 --- a/src/components/screens/Launch/NetworkTab.tsx +++ b/src/components/screens/Launch/NetworkTab.tsx @@ -1,5 +1,4 @@ import { Stack, Text, TextInput, Group } from '@mantine/core'; -import { useState } from 'react'; import { InfoTooltip } from '@/components/InfoTooltip'; import { CheckboxWithTooltip } from '@/components/CheckboxWithTooltip'; import { useLaunchConfigStore } from '@/stores/launchConfig'; @@ -21,7 +20,6 @@ export const NetworkTab = () => { setNocertify, setWebsearch, } = useLaunchConfigStore(); - const [portInput, setPortInput] = useState(''); return ( @@ -49,12 +47,12 @@ export const NetworkTab = () => { { const value = event.currentTarget.value; - setPortInput(value); if (value === '') { + setPort(undefined); return; } @@ -63,13 +61,6 @@ export const NetworkTab = () => { setPort(numValue); } }} - onBlur={(event) => { - const value = event.currentTarget.value; - if (value === '') { - setPort(undefined); - setPortInput(''); - } - }} type="number" min={1} max={65535} diff --git a/src/main/modules/koboldcpp/tunnel.ts b/src/main/modules/koboldcpp/tunnel.ts index 7832147..f6fe8bb 100644 --- a/src/main/modules/koboldcpp/tunnel.ts +++ b/src/main/modules/koboldcpp/tunnel.ts @@ -1,15 +1,23 @@ import fs from 'fs'; -import { Tunnel, bin, install } from 'cloudflared'; +import path from 'path'; +import { Tunnel, install } from 'cloudflared'; +import { platform } from 'process'; import { logError } from '@/utils/node/logging'; import { sendKoboldOutput, sendToRenderer } from '../window'; import { PROXY } from '@/constants/proxy'; import { SILLYTAVERN, OPENWEBUI } from '@/constants'; +import { getInstallDir } from '@/main/modules/config'; import type { FrontendPreference } from '@/types'; let activeTunnel: Tunnel | null = null; let tunnelUrl: string | null = null; +const getCloudflaredBin = () => { + const binName = platform === 'win32' ? 'cloudflared.exe' : 'cloudflared'; + return path.join(getInstallDir(), binName); +}; + const getTunnelTarget = (frontendPreference: FrontendPreference) => { switch (frontendPreference) { case 'sillytavern': @@ -31,14 +39,18 @@ export const startTunnel = async ( try { sendKoboldOutput('Starting Cloudflare tunnel...'); + const bin = getCloudflaredBin(); + if (!fs.existsSync(bin)) { sendKoboldOutput('Installing cloudflared binary...'); await install(bin); - sendKoboldOutput('cloudflared binary installed'); } const tunnelTarget = getTunnelTarget(frontendPreference); - const tunnel = Tunnel.quick(tunnelTarget, { '--no-autoupdate': true }); + const tunnel = Tunnel.quick(tunnelTarget, { + '--no-autoupdate': true, + bin, + }); activeTunnel = tunnel; let rateLimited = false;