allow port to be clearable, store cloudflared bin in gerbil installation directory

This commit is contained in:
Egor 2025-12-03 18:17:45 -08:00
parent 6561e2dd09
commit 9ecf1c6757
3 changed files with 18 additions and 15 deletions

View file

@ -13,5 +13,5 @@
"editor.defaultFormatter": "prettier.prettier-vscode",
"[typescriptreact]": {
"editor.defaultFormatter": "prettier.prettier-vscode"
},
}
}

View file

@ -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 (
<Stack gap="md">
@ -49,12 +47,12 @@ export const NetworkTab = () => {
</Group>
<TextInput
placeholder="5001"
value={portInput || port?.toString() || ''}
value={port?.toString() ?? ''}
onChange={(event) => {
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}

View file

@ -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;