Skip to content

Commit b08877b

Browse files
committed
feat: refactor configuration management and enhance log viewer text selection
1 parent a9b3731 commit b08877b

File tree

8 files changed

+186
-246
lines changed

8 files changed

+186
-246
lines changed

README.md

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -85,74 +85,22 @@ sed -i "/# fetch-github-hosts begin/Q" /etc/hosts && curl https://hosts.gitcdn.t
8585

8686
> 💡 可配合 crontab 定时任务实现自动更新
8787
88-
## 🏗️ 技术栈
88+
## 📸 截图
8989

90-
| 组件 | 技术 |
91-
|------|------|
92-
| 桌面框架 | [Tauri 2.0](https://v2.tauri.app/) (Rust) |
93-
| 前端框架 | [Nuxt 3](https://nuxt.com/) + [Vue 3](https://vuejs.org/) |
94-
| UI 组件 | [Nuxt UI](https://ui.nuxt.com/) |
95-
| 样式 | [Tailwind CSS 4](https://tailwindcss.com/) |
96-
| 状态管理 | [Pinia](https://pinia.vuejs.org/) |
97-
| 国际化 | [@nuxtjs/i18n](https://i18n.nuxtjs.org/) |
98-
99-
## 🛠️ 开发
100-
101-
### 环境要求
102-
103-
- Node.js ≥ 20
104-
- Rust ≥ 1.70
105-
- macOS / Windows / Linux
106-
107-
### 本地开发
108-
109-
```bash
110-
# 安装依赖
111-
npm install
112-
113-
# 构建前端静态文件
114-
NUXT_CLI_WRAPPER=false npx nuxt generate
115-
116-
# 启动 Tauri 开发模式
117-
npx tauri dev
118-
```
119-
120-
### 构建发布包
90+
#### 客户端模式
91+
![client](assets/public/docs/client.png)
12192

122-
```bash
123-
# 构建前端
124-
NUXT_CLI_WRAPPER=false npx nuxt generate
93+
#### 客户端启动
94+
![client-start](assets/public/docs/client-start.png)
12595

126-
# 构建 Tauri 应用
127-
npx tauri build
128-
```
96+
#### 客户端 Hosts 源选择
97+
![client-select](assets/public/docs/client-select.png)
12998

130-
## 📁 项目结构
99+
#### 客户端 Hosts 源自定义
100+
![client-custom](assets/public/docs/client-custom.png)
131101

132-
```
133-
fetch-github-hosts/
134-
├── components/ # Vue 组件
135-
│ ├── ClientMode.vue # 客户端模式面板
136-
│ ├── ServerMode.vue # 服务端模式面板
137-
│ ├── AboutPanel.vue # 关于面板
138-
│ └── LogViewer.vue # 日志查看器
139-
├── composables/ # Vue 组合函数
140-
│ └── useTauri.ts # Tauri API 封装
141-
├── i18n/locales/ # 国际化翻译文件
142-
├── pages/index.vue # 主页面
143-
├── public/ # 静态资源
144-
├── src-tauri/ # Tauri (Rust) 后端
145-
│ ├── src/
146-
│ │ ├── lib.rs # 入口 + 系统托盘
147-
│ │ ├── commands.rs # Tauri 命令
148-
│ │ ├── services.rs # 客户端/服务端逻辑
149-
│ │ ├── dns.rs # DNS 解析
150-
│ │ ├── hosts.rs # Hosts 文件操作
151-
│ │ ├── config.rs # 配置读写
152-
│ │ └── models.rs # 数据模型
153-
│ └── icons/ # 应用图标
154-
└── .github/workflows/ # CI/CD
155-
```
102+
#### 服务端模式
103+
![server](assets/public/docs/server.png)
156104

157105
## 🌟 Star 趋势
158106

README_EN.md

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -85,74 +85,22 @@ sed -i "/# fetch-github-hosts begin/Q" /etc/hosts && curl https://hosts.gitcdn.t
8585

8686
> 💡 Set up a crontab task for automatic updates
8787
88-
## 🏗️ Tech Stack
88+
## 📸 Screenshots
8989

90-
| Component | Technology |
91-
|-----------|-----------|
92-
| Desktop Framework | [Tauri 2.0](https://v2.tauri.app/) (Rust) |
93-
| Frontend | [Nuxt 3](https://nuxt.com/) + [Vue 3](https://vuejs.org/) |
94-
| UI Components | [Nuxt UI](https://ui.nuxt.com/) |
95-
| Styling | [Tailwind CSS 4](https://tailwindcss.com/) |
96-
| State Management | [Pinia](https://pinia.vuejs.org/) |
97-
| i18n | [@nuxtjs/i18n](https://i18n.nuxtjs.org/) |
98-
99-
## 🛠️ Development
100-
101-
### Requirements
102-
103-
- Node.js ≥ 20
104-
- Rust ≥ 1.70
105-
- macOS / Windows / Linux
106-
107-
### Local Development
108-
109-
```bash
110-
# Install dependencies
111-
npm install
112-
113-
# Build static frontend
114-
NUXT_CLI_WRAPPER=false npx nuxt generate
115-
116-
# Start Tauri dev mode
117-
npx tauri dev
118-
```
119-
120-
### Build for Production
90+
#### Client Mode
91+
![client](assets/public/docs/client.png)
12192

122-
```bash
123-
# Build frontend
124-
NUXT_CLI_WRAPPER=false npx nuxt generate
93+
#### Client Started
94+
![client-start](assets/public/docs/client-start.png)
12595

126-
# Build Tauri app
127-
npx tauri build
128-
```
96+
#### Hosts Source Selection
97+
![client-select](assets/public/docs/client-select.png)
12998

130-
## 📁 Project Structure
99+
#### Custom Hosts Source
100+
![client-custom](assets/public/docs/client-custom.png)
131101

132-
```
133-
fetch-github-hosts/
134-
├── components/ # Vue components
135-
│ ├── ClientMode.vue # Client mode panel
136-
│ ├── ServerMode.vue # Server mode panel
137-
│ ├── AboutPanel.vue # About panel
138-
│ └── LogViewer.vue # Log viewer
139-
├── composables/ # Vue composables
140-
│ └── useTauri.ts # Tauri API wrappers
141-
├── i18n/locales/ # i18n translation files
142-
├── pages/index.vue # Main page
143-
├── public/ # Static assets
144-
├── src-tauri/ # Tauri (Rust) backend
145-
│ ├── src/
146-
│ │ ├── lib.rs # Entry + System tray
147-
│ │ ├── commands.rs # Tauri commands
148-
│ │ ├── services.rs # Client/Server logic
149-
│ │ ├── dns.rs # DNS resolution
150-
│ │ ├── hosts.rs # Hosts file operations
151-
│ │ ├── config.rs # Config read/write
152-
│ │ └── models.rs # Data models
153-
│ └── icons/ # App icons
154-
└── .github/workflows/ # CI/CD
155-
```
102+
#### Server Mode
103+
![server](assets/public/docs/server.png)
156104

157105
## 🌟 Star History
158106

README_JA.md

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -85,74 +85,22 @@ sed -i "/# fetch-github-hosts begin/Q" /etc/hosts && curl https://hosts.gitcdn.t
8585

8686
> 💡 crontab で定期実行すれば自動更新できます
8787
88-
## 🏗️ 技術スタック
88+
## 📸 スクリーンショット
8989

90-
| コンポーネント | 技術 |
91-
|-------------|------|
92-
| デスクトップフレームワーク | [Tauri 2.0](https://v2.tauri.app/) (Rust) |
93-
| フロントエンド | [Nuxt 3](https://nuxt.com/) + [Vue 3](https://vuejs.org/) |
94-
| UI コンポーネント | [Nuxt UI](https://ui.nuxt.com/) |
95-
| スタイリング | [Tailwind CSS 4](https://tailwindcss.com/) |
96-
| 状態管理 | [Pinia](https://pinia.vuejs.org/) |
97-
| 国際化 | [@nuxtjs/i18n](https://i18n.nuxtjs.org/) |
98-
99-
## 🛠️ 開発
100-
101-
### 必要環境
102-
103-
- Node.js ≥ 20
104-
- Rust ≥ 1.70
105-
- macOS / Windows / Linux
106-
107-
### ローカル開発
108-
109-
```bash
110-
# 依存関係のインストール
111-
npm install
112-
113-
# フロントエンドの静的ビルド
114-
NUXT_CLI_WRAPPER=false npx nuxt generate
115-
116-
# Tauri 開発モードの起動
117-
npx tauri dev
118-
```
119-
120-
### プロダクションビルド
90+
#### クライアントモード
91+
![client](assets/public/docs/client.png)
12192

122-
```bash
123-
# フロントエンドのビルド
124-
NUXT_CLI_WRAPPER=false npx nuxt generate
93+
#### クライアント起動中
94+
![client-start](assets/public/docs/client-start.png)
12595

126-
# Tauri アプリのビルド
127-
npx tauri build
128-
```
96+
#### Hosts ソース選択
97+
![client-select](assets/public/docs/client-select.png)
12998

130-
## 📁 プロジェクト構造
99+
#### カスタム Hosts ソース
100+
![client-custom](assets/public/docs/client-custom.png)
131101

132-
```
133-
fetch-github-hosts/
134-
├── components/ # Vue コンポーネント
135-
│ ├── ClientMode.vue # クライアントモードパネル
136-
│ ├── ServerMode.vue # サーバーモードパネル
137-
│ ├── AboutPanel.vue # 概要パネル
138-
│ └── LogViewer.vue # ログビューア
139-
├── composables/ # Vue コンポーザブル
140-
│ └── useTauri.ts # Tauri API ラッパー
141-
├── i18n/locales/ # 翻訳ファイル
142-
├── pages/index.vue # メインページ
143-
├── public/ # 静的アセット
144-
├── src-tauri/ # Tauri (Rust) バックエンド
145-
│ ├── src/
146-
│ │ ├── lib.rs # エントリ + システムトレイ
147-
│ │ ├── commands.rs # Tauri コマンド
148-
│ │ ├── services.rs # クライアント/サーバーロジック
149-
│ │ ├── dns.rs # DNS 解決
150-
│ │ ├── hosts.rs # Hosts ファイル操作
151-
│ │ ├── config.rs # 設定の読み書き
152-
│ │ └── models.rs # データモデル
153-
│ └── icons/ # アプリアイコン
154-
└── .github/workflows/ # CI/CD
155-
```
102+
#### サーバーモード
103+
![server](assets/public/docs/server.png)
156104

157105
## 🌟 スター推移
158106

assets/css/main.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,17 @@ body, #__nuxt {
9595
color: #fff;
9696
}
9797

98+
/* Disable text selection globally, except log viewer */
99+
body {
100+
-webkit-user-select: none;
101+
user-select: none;
102+
}
103+
104+
/* Allow text selection only in log viewer */
105+
.log-selectable,
106+
.log-selectable * {
107+
-webkit-user-select: text;
108+
user-select: text;
109+
}
110+
98111

components/ClientMode.vue

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
const { safeInvoke, safeListen } = useTauri()
102102
const { t } = useI18n()
103103
const toast = useToast()
104+
const { config: appConfig, loadConfig, updateClient } = useConfig()
104105
105106
const isRunning = ref(false)
106107
const logs = ref<string[]>([])
@@ -153,7 +154,7 @@ async function startFetch() {
153154
await safeInvoke('start_client', { url, interval })
154155
isRunning.value = true
155156
addLog(t('client.remoteUrlLog', { url }))
156-
await saveConfig()
157+
await syncToSharedConfig()
157158
} catch (e: any) {
158159
addLog(t('client.fetchFail', { error: e.toString() }))
159160
}
@@ -196,39 +197,33 @@ async function flushDns() {
196197
197198
function onAutoFetchChange(val: boolean) {
198199
config.autoFetch = val
199-
saveConfig()
200+
updateClient({
201+
interval: Number(config.interval),
202+
method: config.originMethod,
203+
select_origin: config.selectOrigin,
204+
custom_url: config.customUrl,
205+
auto_fetch: config.autoFetch,
206+
})
200207
toast.add({ title: t('client.autoFetchChanged'), color: 'info' })
201208
}
202209
203-
async function saveConfig() {
204-
try {
205-
await safeInvoke('save_config', {
206-
config: {
207-
lang: 'zh-CN',
208-
client: {
209-
interval: Number(config.interval),
210-
method: config.originMethod,
211-
select_origin: config.selectOrigin,
212-
custom_url: config.customUrl,
213-
auto_fetch: config.autoFetch,
214-
},
215-
server: { interval: 60, port: 9898 },
216-
},
217-
})
218-
} catch (_) { }
210+
async function syncToSharedConfig() {
211+
await updateClient({
212+
interval: Number(config.interval),
213+
method: config.originMethod,
214+
select_origin: config.selectOrigin,
215+
custom_url: config.customUrl,
216+
auto_fetch: config.autoFetch,
217+
})
219218
}
220219
221-
async function loadConfig() {
222-
try {
223-
const cfg: any = await safeInvoke('load_config')
224-
if (cfg) {
225-
config.interval = cfg.client?.interval ?? 60
226-
config.originMethod = cfg.client?.method ?? 'official'
227-
config.selectOrigin = cfg.client?.select_origin ?? 'FetchGithubHosts'
228-
config.customUrl = cfg.client?.custom_url ?? ''
229-
config.autoFetch = cfg.client?.auto_fetch ?? false
230-
}
231-
} catch (_) { }
220+
function syncFromSharedConfig() {
221+
const c = appConfig.value.client
222+
config.interval = c.interval ?? 60
223+
config.originMethod = c.method ?? 'official'
224+
config.selectOrigin = c.select_origin ?? 'FetchGithubHosts'
225+
config.customUrl = c.custom_url ?? ''
226+
config.autoFetch = c.auto_fetch ?? false
232227
}
233228
234229
onMounted(async () => {
@@ -237,6 +232,7 @@ onMounted(async () => {
237232
addLog(event.payload.message)
238233
})
239234
await loadConfig()
235+
syncFromSharedConfig()
240236
// Auto fetch on startup if enabled
241237
if (config.autoFetch) {
242238
startFetch()

components/LogViewer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
v-if="logs.length > 0"
1212
/>
1313
</div>
14-
<div ref="logContainer" class="flex-1 overflow-y-auto p-3 font-mono text-xs leading-relaxed">
14+
<div ref="logContainer" class="log-selectable flex-1 overflow-y-auto p-3 font-mono text-xs leading-relaxed">
1515
<div v-if="logs.length === 0" class="opacity-20 text-center py-8">
1616
{{ $t('log.empty') }}
1717
</div>

0 commit comments

Comments
 (0)