This commit is contained in:
zpc 2025-03-29 00:11:48 +08:00
parent 26862f20a0
commit 9b7bd2318c
5 changed files with 127 additions and 38 deletions

View File

@ -1,38 +1,75 @@
@echo off
chcp 936
setlocal enabledelayedexpansion
:: 配置参数
set LOG_FILE=ShengShengBuXi.log
set MAX_LOG_SIZE=1048576 :: 最大日志大小1MB
set RESTART_DELAY=1 :: 重启延迟(秒)
set APP_NAME=ShengShengBuXi.ConsoleApp.exe
:: Debug mode
set DEBUG=1
:: 初始化日志
if not exist "%LOG_FILE%" (
echo 日志创建时间: %date% %time% > "%LOG_FILE%"
echo ======================================= >> "%LOG_FILE%"
:: Configuration
set APP_NAME=ShengShengBuXi.ConsoleApp.exe
set LOG_FILE=%~dp0ShengShengBuXi.log
set RESTART_DELAY=0
:: Create log file
echo [%date% %time%] Batch file started > "%LOG_FILE%"
echo [%date% %time%] Current directory: %cd% >> "%LOG_FILE%"
echo [%date% %time%] Batch file directory: %~dp0 >> "%LOG_FILE%"
echo [INFO] Checking environment...
echo [INFO] Current directory: %cd%
echo [INFO] Batch file directory: %~dp0
echo [INFO] Checking program file...
:: Check if program exists
if not exist "%~dp0%APP_NAME%" (
echo [ERROR] Cannot find %APP_NAME%
echo [ERROR] Please make sure the batch file and program are in the same directory
echo [INFO] Directory listing:
dir
echo [ERROR] Program file not found >> "%LOG_FILE%"
pause
exit /b 1
)
echo [INFO] Program file check passed
echo [INFO] Program file check passed >> "%LOG_FILE%"
:restart
:: 检查日志大小并轮转
for %%F in ("%LOG_FILE%") do set LOG_SIZE=%%~zF
if !LOG_SIZE! gtr %MAX_LOG_SIZE% (
echo 日志文件过大(!LOG_SIZE!字节),正在轮转... >> "%LOG_FILE%"
move /y "%LOG_FILE%" "ShengShengBuXi_%date:/=-%_%time::=-%.log" >nul
echo 新日志创建时间: %date% %time% > "%LOG_FILE%"
echo ======================================= >> "%LOG_FILE%"
:: Debug info
if defined DEBUG (
echo [DEBUG] Current directory: %cd%
echo [DEBUG] Program path: %~dp0%APP_NAME%
echo [DEBUG] Log path: %LOG_FILE%
echo [INFO] Preparing to start program...
echo [INFO] Preparing to start program... >> "%LOG_FILE%"
)
:: 记录启动信息
echo [%date% %time%] 启动 %APP_NAME% >> "%LOG_FILE%"
:: Log start
echo [%date% %time%] Starting %APP_NAME% >> "%LOG_FILE%"
:: 启动程序并重定向输出
start /b /wait "%APP_NAME%" >> "%LOG_FILE%" 2>&1
:: Start program
echo [INFO] Starting program...
echo [INFO] Starting program... >> "%LOG_FILE%"
:: 记录退出信息
echo [%date% %time%] 程序退出,代码: !errorlevel! >> "%LOG_FILE%"
echo [%date% %time%] 将在 %RESTART_DELAY% 秒后重启... >> "%LOG_FILE%"
:: Run program with full path
"%~dp0%APP_NAME%" >> "%LOG_FILE%" 2>&1
:: 延迟后重启
:: Check exit status
set EXIT_CODE=%errorlevel%
echo [%date% %time%] Program exited with code: !EXIT_CODE! >> "%LOG_FILE%"
if !EXIT_CODE! neq 0 (
echo [WARNING] Program exited abnormally >> "%LOG_FILE%"
echo [WARNING] Program exited with code: !EXIT_CODE!
echo [INFO] Please check log file: %LOG_FILE%
echo Press any key to continue...
pause
)
:: Restart delay
echo [%date% %time%] Restarting in %RESTART_DELAY% seconds... >> "%LOG_FILE%"
echo [INFO] Restarting in %RESTART_DELAY% seconds...
timeout /t %RESTART_DELAY% /nobreak >nul
goto restart
goto restart

View File

@ -19,6 +19,10 @@ public class SignalRService : ISignalRService
private bool _isInitialConnection = true;
private const int MAX_RETRY_COUNT = 10;
private const int RETRY_INTERVAL_MS = 1000;
private const int HEARTBEAT_INTERVAL_MS = 3000; // 3秒发送一次心跳
private Timer? _heartbeatTimer;
private DateTime _lastHeartbeatTime = DateTime.MinValue;
private const int HEARTBEAT_TIMEOUT_MS = 60000; // 60秒没有心跳就认为断开
/// <summary>
/// 连接状态改变事件
@ -74,9 +78,14 @@ public class SignalRService : ISignalRService
_hubConnection = new HubConnectionBuilder()
.WithUrl(hubUrl)
.WithAutomaticReconnect()
.WithAutomaticReconnect([TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(3)])
.Build();
// 启动心跳定时器
_heartbeatTimer?.Dispose();
_heartbeatTimer = new Timer(CheckHeartbeat, null, HEARTBEAT_INTERVAL_MS, HEARTBEAT_INTERVAL_MS);
_lastHeartbeatTime = DateTime.Now;
// 注册连接关闭事件
_hubConnection.Closed += async (error) =>
{
@ -189,6 +198,40 @@ public class SignalRService : ISignalRService
}
}
/// <summary>
/// 检查心跳
/// </summary>
private async void CheckHeartbeat(object? state)
{
try
{
if (_hubConnection == null || _hubConnection.State != HubConnectionState.Connected)
{
return;
}
// 检查上次心跳时间是否超时
if ((DateTime.Now - _lastHeartbeatTime).TotalMilliseconds > HEARTBEAT_TIMEOUT_MS)
{
Console.WriteLine("心跳超时,连接可能已断开");
await _hubConnection.StopAsync();
return;
}
// 发送心跳
await RequestLatestConfigAsync();
_lastHeartbeatTime = DateTime.Now;
}
catch (Exception ex)
{
Console.WriteLine($"心跳检测失败: {ex.Message}");
if (_hubConnection != null)
{
await _hubConnection.StopAsync();
}
}
}
/// <summary>
/// 注册为控制器客户端
/// </summary>
@ -230,6 +273,10 @@ public class SignalRService : ISignalRService
_clientId = null;
ConnectionStateChanged?.Invoke(this, false);
}
// 停止心跳定时器
_heartbeatTimer?.Dispose();
_heartbeatTimer = null;
}
/// <summary>
@ -388,6 +435,11 @@ public class SignalRService : ISignalRService
catch (Exception ex)
{
Console.WriteLine($"获取最新配置失败: {ex.Message}");
// 如果获取配置失败,可能是连接已断开
if (_hubConnection != null)
{
await _hubConnection.StopAsync();
}
}
}

View File

@ -1,5 +1,5 @@
{
"SignalRHubUrl": "http://localhost:82/audiohub",
"SignalRHubUrl": "http://115.159.44.16/audiohub",
"ConfigBackupPath": "config.json",
"AutoConnectToServer": true,
"AllowOfflineStart": false

View File

@ -140,18 +140,18 @@
fontSize: '40px', // 右侧文字大小
fontWeight: '700', // 右侧文字粗细
fontStyle: 'italic', // 右侧文字样式
typewriterSpeed: 330 // 右侧文字打字机速度(毫秒)减慢到1/5
typewriterSpeed: 2000 // 右侧文字打字机速度(毫秒)增加到2000毫秒
},
// 水波纹效果配置
waterEffect: {
enabled: true, // 是否开启水波纹
minInterval: 1600, // 最小触发间隔(毫秒),增加时间
maxInterval: 8000, // 最大触发间隔(毫秒),增加时间
simultaneousDrops: 2, // 同时触发的波纹数量减少到2个
fadeOutSpeed: 2000, // 文字渐隐效果的速度(毫秒)原速度的2倍
centerBias: 0.6, // 涟漪靠近中心区域的偏好值(0-1)0为随机1为只在中心区域
minInterval: 1600, // 最小触发间隔(毫秒)
maxInterval: 8000, // 最大触发间隔(毫秒)
simultaneousDrops: 2, // 同时触发的波纹数量
fadeOutSpeed: 5000, // 文字渐隐效果的速度(毫秒)增加到5000毫秒
centerBias: 0.6, // 涟漪靠近中心区域的偏好值(0-1)
largeDrop: {
probability: 0.2, // 大涟漪出现的概率降低到0.2
probability: 0.2, // 大涟漪出现的概率
size: 80 // 大涟漪的大小
}
},
@ -266,7 +266,7 @@
// 整条文字渐显效果
newP.animate(
{ opacity: 1 },
1500, // 设置动画时长为1.5
2000, // 设置动画时长为2
'swing'
);
return true;

View File

@ -2,20 +2,20 @@
"leftContainer": {
"turnPageHeight": 0.5,
"fontSize": "16px",
"typewriterSpeed": 50
"typewriterSpeed": 300
},
"rightContainer": {
"fontSize": "40px",
"fontWeight": "bolder",
"fontStyle": "italic",
"typewriterSpeed": 330
"typewriterSpeed": 500
},
"waterEffect": {
"enabled": true,
"minInterval": 1600,
"maxInterval": 8000,
"simultaneousDrops": 2,
"fadeOutSpeed": 2000,
"fadeOutSpeed": 1200,
"centerBias": 0.6,
"largeDrop": {
"probability": 0.2,