Skip to content

Commit

Permalink
perf(icon): ⚡ 修改全平台icon(除了mac)
Browse files Browse the repository at this point in the history
增加代理功能(beta)
  • Loading branch information
nongyehong committed Jan 18, 2025
1 parent 0252956 commit 38960cc
Show file tree
Hide file tree
Showing 58 changed files with 528 additions and 71 deletions.
365 changes: 331 additions & 34 deletions src-tauri/Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ lazy_static = "1.4"
screenshots = "0.5.4"
base64 = "0.22.1"
rodio = "0.17.3"
reqwest = { version = "0.11", features = [
"json",
"socks",
"native-tls-vendored",
] }


[features]
Expand Down
Binary file modified src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/128x128.png
Binary file modified src-tauri/icons/[email protected]
Binary file modified src-tauri/icons/32x32.png
Binary file modified src-tauri/icons/Square107x107Logo.png
Binary file modified src-tauri/icons/Square142x142Logo.png
Binary file modified src-tauri/icons/Square150x150Logo.png
Binary file modified src-tauri/icons/Square284x284Logo.png
Binary file modified src-tauri/icons/Square30x30Logo.png
Binary file modified src-tauri/icons/Square310x310Logo.png
Binary file modified src-tauri/icons/Square44x44Logo.png
Binary file modified src-tauri/icons/Square71x71Logo.png
Binary file modified src-tauri/icons/Square89x89Logo.png
Binary file modified src-tauri/icons/StoreLogo.png
Binary file modified src-tauri/icons/icon.icns
Binary file not shown.
Binary file modified src-tauri/icons/icon.ico
Binary file not shown.
Binary file modified src-tauri/icons/icon.png
11 changes: 8 additions & 3 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ use common_cmd::{
set_height,
};
#[cfg(desktop)]
mod proxy;
#[cfg(desktop)]
use desktops::common_cmd;
#[cfg(desktop)]
use desktops::init;
#[cfg(desktop)]
use desktops::tray;
#[cfg(desktop)]
use init::CustomInit;
#[cfg(desktop)]
use proxy::test_proxy;

// 移动端依赖
#[cfg(mobile)]
mod mobiles;
#[cfg(mobile)]
use mobiles::init;
#[cfg(mobile)]
use init::CustomInit;
#[cfg(mobile)]
use mobiles::init;

pub fn run() {
#[cfg(desktop)]
Expand Down Expand Up @@ -51,7 +55,8 @@ fn setup_desktop() {
screenshot,
audio,
set_height,
set_badge_count
set_badge_count,
test_proxy
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
58 changes: 58 additions & 0 deletions src-tauri/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use reqwest::{Client, Proxy};
use std::time::Duration;

// 定义测试用的URL列表
const TEST_URLS: [&str; 3] = [
"https://www.baidu.com",
"https://www.bing.com",
"https://www.qq.com",
];

#[tauri::command]
pub async fn test_proxy(proxy_type: String, proxy_host: String, proxy_port: u16) -> Result<bool, String> {
if proxy_type.is_empty() {
return Ok(true); // 不使用代理时直接返回成功
}

let proxy_url = match proxy_type.as_str() {
"http" => format!("http://{}:{}", proxy_host, proxy_port),
"socks5" => format!("socks5://{}:{}", proxy_host, proxy_port),
_ => return Err("不支持的代理类型".to_string()),
};

// 构建代理客户端,移除了dns_resolver配置
let client = Client::builder()
.proxy(Proxy::all(&proxy_url).map_err(|e| format!("代理设置错误: {}", e))?)
.timeout(Duration::from_secs(10))
.build()
.map_err(|e| format!("创建客户端失败: {}", e))?;

// 依次测试多个URL,直到有一个成功
for url in TEST_URLS.iter() {
match test_url(&client, url).await {
Ok(_) => return Ok(true),
Err(e) => {
println!("测试 {} 失败: {}", url, e);
// 如果是DNS错误,直接返回特定错误信息
if e.contains("dns error") {
return Err("DNS解析失败,请检查网络连接或代理设置".to_string());
}
}
}
}

Err("所有测试网站均无法连接,请检查代理设置".to_string())
}

async fn test_url(client: &Client, url: &str) -> Result<(), String> {
match client.get(url).send().await {
Ok(response) => {
if response.status().is_success() {
Ok(())
} else {
Err(format!("HTTP状态码错误: {}", response.status()))
}
}
Err(e) => Err(format!("请求失败: {}", e)),
}
}
32 changes: 17 additions & 15 deletions src/services/fingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ export const getEnhancedFingerprint = async (): Promise<string> => {

// 创建新的Promise并保存引用
fingerprintPromise = (async () => {
console.time('🔍 设备指纹获取总耗时')
const totalStart = performance.now()

try {
// 检查缓存是否有效
const cachedData = localStorage.getItem('deviceFingerprint')
if (cachedData) {
const { fingerprint, timestamp } = JSON.parse(cachedData)
if (Date.now() - timestamp < CACHE_DURATION) {
console.timeEnd('🔍 设备指纹获取总耗时')
console.log('✅ 使用缓存的设备指纹')
const totalTime = performance.now() - totalStart
console.log(`🔍 使用缓存的设备指纹,总耗时: ${totalTime.toFixed(2)}ms`)
return fingerprint
}
}

console.time('📊 收集设备信息耗时')
// 收集设备信息
const deviceInfoStart = performance.now()
const deviceInfo = {
platform: await type(),
screenSize: `${window.screen.width}x${window.screen.height}`,
Expand All @@ -48,18 +48,20 @@ export const getEnhancedFingerprint = async (): Promise<string> => {
language: navigator.language,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
}
console.timeEnd('📊 收集设备信息耗时')
const deviceInfoTime = performance.now() - deviceInfoStart
console.log(`📊 收集设备信息耗时: ${deviceInfoTime.toFixed(2)}ms`)

// 在主线程中获取基础浏览器指纹
console.time('Worker: 基础指纹生成')
const fpStart = performance.now()
const fp = await FingerprintJS.load()
const fpResult = await fp.get({
debug: false
})
console.timeEnd('Worker: 基础指纹生成')
const fpTime = performance.now() - fpStart
console.log(`基础指纹生成耗时: ${fpTime.toFixed(2)}ms`)

// 创建 Promise 等待 Worker 返回结果
console.time('🔨 Worker生成指纹耗时')
// Worker处理
const workerStart = performance.now()
const fingerprint = await new Promise<string>((resolve) => {
const handleMessage = (e: MessageEvent) => {
const { type, fingerprint } = e.data
Expand All @@ -76,7 +78,8 @@ export const getEnhancedFingerprint = async (): Promise<string> => {
browserFingerprint: fpResult.visitorId
})
})
console.timeEnd('🔨 Worker生成指纹耗时')
const workerTime = performance.now() - workerStart
console.log(`🔨 Worker生成指纹耗时: ${workerTime.toFixed(2)}ms`)

// 缓存结果
if (fingerprint) {
Expand All @@ -87,17 +90,16 @@ export const getEnhancedFingerprint = async (): Promise<string> => {
timestamp: Date.now()
})
)
console.log('✅ 生成新的设备指纹并缓存')
}

console.timeEnd('🔍 设备指纹获取总耗时')
const totalTime = performance.now() - totalStart
console.log(`🔍 设备指纹获取总耗时: ${totalTime.toFixed(2)}ms`)
return fingerprint
} catch (error) {
console.timeEnd('🔍 设备指纹获取总耗时')
console.error('❌ 获取设备指纹失败:', error)
const totalTime = performance.now() - totalStart
console.error(`❌ 获取设备指纹失败,总耗时: ${totalTime.toFixed(2)}ms`, error)
return ''
} finally {
// 清除正在进行的Promise引用
fingerprintPromise = null
}
})()
Expand Down
23 changes: 21 additions & 2 deletions src/services/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ async function Http<T = any>(
fullResponse: boolean = false,
abort?: AbortController
): Promise<{ data: T; resp: Response } | T> {
// 打印请求信息
console.log(`🚀 发起请求 → ${options.method} ${url}`, {
body: options.body,
query: options.query
})

// 默认重试配置
const defaultRetryOptions: RetryOptions = {
retries: 3,
Expand Down Expand Up @@ -118,8 +124,15 @@ async function Http<T = any>(
signal: abort?.signal
}

// 打印请求头内容
console.log(...httpHeaders)
// 获取代理设置
// const proxySettings = JSON.parse(localStorage.getItem('proxySettings') || '{}')
// 如果设置了代理,添加代理配置 (BETA)
// if (proxySettings.type && proxySettings.ip && proxySettings.port) {
// // 使用 Rust 后端的代理客户端
// fetchOptions.proxy = {
// url: `${proxySettings.type}://${proxySettings.ip}:${proxySettings.port}`
// }
// }

// 判断是否需要添加请求体
if (options.body) {
Expand Down Expand Up @@ -160,6 +173,12 @@ async function Http<T = any>(
// 解析响应数据
const responseData = options.isBlob ? await response.arrayBuffer() : await response.json()

// 打印响应结果
console.log(`✅ 请求成功 → ${options.method} ${url}`, {
status: response.status,
data: responseData
})

// 若有success === false,需要重试
if (responseData && responseData.success === false) {
throw new AppException(responseData.message || url, {
Expand Down
2 changes: 1 addition & 1 deletion src/views/loginWindow/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ const enterKey = (e: KeyboardEvent) => {
onBeforeMount(async () => {
// 如果不是自动登录且当前在登录页面,清除 TOKEN,防止用户直接使用控制台退出导致登录前还没有退出账号就继续登录
if (!login.value.autoLogin && route.path === '/login' && TOKEN.value) {
// await apis.logout()
await apis.logout()
isTrayMenuShow.value = false
computedToken.clear()
// 重新初始化 WebSocket 连接,此时传入 null 作为 token
Expand Down
86 changes: 77 additions & 9 deletions src/views/loginWindow/Proxy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<n-collapse-transition :show="proxyType === 'http'">
<n-flex vertical :size="10" justify="center">
<p class="text-12px pt-14px">IP地址</p>
<n-input class="rounded-6px text-12px" v-model:value="IP" type="text" placeholder="例如:127.0.0.1" />

<p class="text-12px pt-14px">端口号</p>
<n-input
class="rounded-6px text-12px"
v-model:value="IP"
v-model:value="port"
type="text"
placeholder="http://xxx 或者 https://xxx" />

<p class="text-12px pt-14px">端口号</p>
<n-input class="rounded-6px text-12px" v-model:value="port" type="text" placeholder="请输入端口号" />
placeholder="HTTP:7890 或 SOCKS5:7891" />
</n-flex>

<p @click="proxyTest" class="text-(14px #13987f center) cursor-pointer pt-20px">网络代理测试</p>
Expand All @@ -36,6 +36,7 @@
<script setup lang="ts">
import { lightTheme } from 'naive-ui'
import router from '@/router'
import { invoke } from '@tauri-apps/api/core'
const options = [
{
Expand All @@ -45,14 +46,81 @@ const options = [
{
label: 'HTTP代理',
value: 'http'
},
{
label: 'SOCKS5代理',
value: 'socks5'
}
]
const proxyType = ref(options[0].value)
const IP = ref()
const port = ref()
const IP = ref('')
const port = ref('')
// 从本地存储加载代理设置
onMounted(() => {
const savedProxy = localStorage.getItem('proxySettings')
if (savedProxy) {
const settings = JSON.parse(savedProxy)
proxyType.value = settings.type
IP.value = settings.ip
port.value = settings.port
}
})
// 保存代理设置
const handleSave = async () => {
try {
if (proxyType.value && (!IP.value || !port.value)) {
window.$message.warning('请填写完整的代理信息')
return
}
const handleSave = () => {}
const proxyTest = () => {}
// 保存到本地存储
const proxySettings = {
type: proxyType.value,
ip: IP.value,
port: port.value
}
localStorage.setItem('proxySettings', JSON.stringify(proxySettings))
window.$message.success('代理设置保存成功')
router.push('/login')
} catch (error) {
window.$message.error('代理设置失败:' + error)
}
}
// 测试代理连接
const proxyTest = async () => {
if (proxyType.value && (!IP.value || !port.value)) {
window.$message.warning('请填写完整的代理信息')
return
}
try {
window.$message.loading('正在测试代理连接...', {
duration: 0
})
const result = await invoke('test_proxy', {
proxyType: proxyType.value,
proxyHost: IP.value,
proxyPort: Number(port.value)
})
if (result) {
window.$message.success('代理连接测试成功')
} else {
window.$message.error('代理连接测试失败')
}
} catch (error) {
// 显示具体的错误信息
window.$message.error(`代理测试失败: ${error}`)
} finally {
window.$message.destroyAll() // 清除loading消息
}
}
</script>

<style scoped lang="scss">
Expand Down
17 changes: 10 additions & 7 deletions src/workers/fingerprint.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ const detectBrowserFeatures = async (): Promise<Record<string, boolean>> => {
// 生成设备指纹
const generateFingerprint = async (data: { deviceInfo: any; browserFingerprint: string }): Promise<string> => {
try {
console.time('Worker: 指纹生成总耗时')
const totalStart = performance.now()

// 2. 浏览器特征检测
console.time('Worker: 特征检测')
const featureStart = performance.now()
const browserFeatures = await detectBrowserFeatures()
console.timeEnd('Worker: 特征检测')
const featureTime = performance.now() - featureStart
console.log(`Worker: 特征检测耗时: ${featureTime.toFixed(2)}ms`)

// 3. 组合所有特征
console.time('Worker: SHA-256计算')
const hashStart = performance.now()
const combinedFingerprint = JSON.stringify({
browserFingerprint: data.browserFingerprint,
deviceInfo: data.deviceInfo,
Expand All @@ -71,12 +72,14 @@ const generateFingerprint = async (data: { deviceInfo: any; browserFingerprint:
const fingerprint = Array.from(new Uint8Array(fingerprintBuffer))
.map((b) => b.toString(16).padStart(2, '0'))
.join('')
console.timeEnd('Worker: SHA-256计算')
const hashTime = performance.now() - hashStart
console.log(`Worker: SHA-256计算耗时: ${hashTime.toFixed(2)}ms`)

const totalTime = performance.now() - totalStart
console.log(`Worker: 指纹生成总耗时: ${totalTime.toFixed(2)}ms`)

console.timeEnd('Worker: 指纹生成总耗时')
return fingerprint
} catch (error) {
console.timeEnd('Worker: 指纹生成总耗时')
console.error('Worker: ❌ 生成设备指纹失败:', error)
return ''
}
Expand Down

0 comments on commit 38960cc

Please sign in to comment.