feat: enhance device UUID generation and management, update .gitignore and configuration files

This commit is contained in:
sudomarcma
2025-09-03 13:29:49 +08:00
parent 7345a4e1c8
commit 80c9f6ad01
7 changed files with 23 additions and 64 deletions
+2
View File
@@ -1,2 +1,4 @@
node_modules
dist
android/.idea/deploymentTargetSelector.xml
android/.idea/deploymentTargetSelector.xml
+4 -1
View File
@@ -1,3 +1,6 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
"java.configuration.updateBuildConfiguration": "automatic",
"i18n-ally.localesPaths": [
"src/locales"
]
}
+2 -2
View File
@@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-07-16T06:10:41.109630400Z">
<DropdownSelection timestamp="2025-09-03T03:14:53.565616900Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\masongyan\.android\avd\API_30.avd" />
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\masongyan\.android\avd\api25.avd" />
</handle>
</Target>
</DropdownSelection>
-3
View File
@@ -5,9 +5,6 @@ android {
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
}
lintOptions{
checkReleaseBuilds false
}
}
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
+1 -1
View File
@@ -8,7 +8,7 @@
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
/>
<title>Vite App</title>
<script type="module" crossorigin src="/assets/index-DHS6QlZu.js"></script>
<script type="module" crossorigin src="/assets/index-CNLmg7Jt.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-PWd6qU--.css">
</head>
<body>
+12 -51
View File
@@ -1,6 +1,7 @@
import { Device } from '@capacitor/device'
import { Preferences } from '@capacitor/preferences'
import { Capacitor } from '@capacitor/core'
import { v4 as uuidv4 } from 'uuid'
import { apiFetch } from '@/api.js'
import { authService } from '@/services/authService.js'
@@ -19,7 +20,7 @@ class DeviceUuidService {
// Get or create device UUID
this.cachedDeviceUuid = await this.getOrCreateDeviceUuid()
// Get device information
this.cachedDeviceInfo = await this.getDeviceInfo()
this.cachedDeviceInfo = await this.getBasicDeviceInfo()
return true
} catch (error) {
console.error('Failed to initialize device UUID service:', error)
@@ -49,35 +50,19 @@ class DeviceUuidService {
async generateDeviceUuid() {
try {
let baseString = ''
const uuid = uuidv4()
// 可选:记录设备信息用于调试(不影响UUID生成)
if (this.isNative) {
// Get device-specific information for UUID generation
const deviceInfo = await Device.getInfo()
const deviceId = await Device.getId()
// Create a base string from device characteristics
baseString = [
deviceInfo.platform || 'unknown',
deviceInfo.model || 'unknown',
deviceInfo.manufacturer || 'unknown',
deviceId.identifier || 'unknown',
deviceInfo.osVersion || 'unknown'
].join('-')
} else {
// Web fallback - use browser characteristics
baseString = [
navigator.userAgent,
navigator.language,
screen.width,
screen.height,
new Date().getTimezoneOffset()
].join('-')
console.log('Generated UUID for device:', {
uuid,
platform: deviceInfo.platform,
model: deviceInfo.model,
manufacturer: deviceInfo.manufacturer
})
}
// Generate UUID based on device characteristics
const uuid = await this.hashStringToUuid(baseString)
return uuid
} catch (error) {
console.error('Failed to generate device UUID:', error)
@@ -85,33 +70,9 @@ class DeviceUuidService {
}
}
async hashStringToUuid(str) {
try {
// Simple hash function to create consistent UUID from string
let hash = 0
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = ((hash << 5) - hash) + char
hash = hash & hash // Convert to 32-bit integer
}
// Convert hash to UUID format
const hashStr = Math.abs(hash).toString(16).padStart(8, '0')
const timestamp = Date.now().toString(16).slice(-8)
const random = Math.random().toString(16).slice(2, 10)
return `${hashStr.slice(0, 8)}-${hashStr.slice(0, 4)}-4${hashStr.slice(1, 4)}-${timestamp.slice(0, 4)}-${random}`
} catch (error) {
console.error('Failed to hash string to UUID:', error)
return this.generateFallbackUuid()
}
}
generateFallbackUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0
const v = c == 'x' ? r : (r & 0x3 | 0x8)
return v.toString(16)
})
// 使用标准UUID库作为fallback
return uuidv4()
}
getBasicDeviceInfo() {
+2 -6
View File
@@ -262,7 +262,7 @@ class NativeServicesManager {
},
deviceUuid: {
initialized: true,
uuid: 'simplified' // Removed complex UUID tracking
uuid: this.services.deviceUuid.cachedDeviceUuid || 'pending'
}
}
}
@@ -296,13 +296,9 @@ class NativeServicesManager {
return this.isNative
}
/**
* Get device UUID (simplified)
*/
async getDeviceUuid() {
return 'simplified-device-uuid' // Simplified implementation
return await this.services.deviceUuid.getDeviceUuid()
}
/**
* Reset all services (for testing/troubleshooting)
*/