feat: 支持4种OpenBridge主题切换,统一项目命名和端口配置

- 添加 OpenBridge 四种主题切换 (day/bright/dusk/night)
- 实现 DJB2 hash 算法生成项目专用端口 (14323)
- 统一项目名称为 openbridge-token-usage-viewer
- 更新 Tauri 应用名称、sidecar 命名和窗口标题
- 开发服务器端口从 3000 改为基于项目名称的稳定端口
This commit is contained in:
2026-01-22 13:02:43 +08:00
parent d077dfdd90
commit b520cdaf35
10 changed files with 189 additions and 36 deletions

View File

@@ -7,7 +7,7 @@
* - Bun 运行时优化 (nitro preset: 'bun')
* - 静态资源内联 (serveStatic: 'inline')
* - React Compiler 自动优化 (无需手动 memo)
* - 开发时热更新 (端口 3000)
* - 基于项目名称的稳定端口 (使用 DJB2 hash)
*/
import tailwindcss from '@tailwindcss/vite'
import { devtools as tanstackDevtools } from '@tanstack/devtools-vite'
@@ -17,8 +17,27 @@ import { nitro } from 'nitro/vite'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
/** 开发服务器端口 */
const DEV_PORT = 3000
// ============================================================================
// 项目配置 (集中管理)
// ============================================================================
/** 项目名称 - 用于生成稳定端口和 sidecar 命名 */
export const PROJECT_NAME = 'openbridge-token-usage-viewer'
/**
* DJB2 Hash 算法 - 将项目名称转换为稳定端口
* 端口范围: 10000-60000
*/
const djb2Hash = (str: string): number => {
let hash = 5381
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash + str.charCodeAt(i)) >>> 0
}
return hash
}
/** 开发服务器端口 (基于项目名称的稳定值) */
export const DEV_PORT = 10000 + (djb2Hash(PROJECT_NAME) % 50000)
export default defineConfig({
// 禁止清屏,方便与 Tauri 开发工具共用终端
@@ -60,7 +79,7 @@ export default defineConfig({
server: {
port: DEV_PORT,
// 如果端口被占用则报错,而不是自动切换端口
strictPort: true,
strictPort: false,
watch: {
// 忽略 Tauri 源码目录,避免不必要的重编译
ignored: ['**/src-tauri/**'],