Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/core/app_info/device_info_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

/// Returns device model string for use in x-device-model header.
/// Returns empty string on unsupported platforms or on error.
final deviceModelProvider = FutureProvider<String>((ref) async {
if (kIsWeb) return '';
final info = DeviceInfoPlugin();
try {
if (Platform.isAndroid) {
final d = await info.androidInfo;
return d.model;
} else if (Platform.isIOS) {
final d = await info.iosInfo;
return d.utsname.machine;
} else if (Platform.isWindows) {
final d = await info.windowsInfo;
return d.productName;
} else if (Platform.isMacOS) {
final d = await info.macOsInfo;
return d.model;
}
} catch (_) {}
return '';
});
6 changes: 4 additions & 2 deletions lib/core/http_client/dio_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class DioHttpClient with InfraLogger {
String? userAgent,
({String username, String password})? credentials,
bool proxyOnly = false,
Map<String, String>? extraHeaders,
}) async {
final mode = proxyOnly
? "proxy"
Expand All @@ -122,11 +123,11 @@ class DioHttpClient with InfraLogger {
url,
path,
cancelToken: cancelToken,
options: _options(url, userAgent: userAgent, credentials: credentials),
options: _options(url, userAgent: userAgent, credentials: credentials, extraHeaders: extraHeaders),
);
}

Options _options(String url, {String? userAgent, ({String username, String password})? credentials}) {
Options _options(String url, {String? userAgent, ({String username, String password})? credentials, Map<String, String>? extraHeaders}) {
final uri = Uri.parse(url);

String? userInfo;
Expand All @@ -145,6 +146,7 @@ class DioHttpClient with InfraLogger {
headers: {
if (userAgent != null) "User-Agent": userAgent,
if (basicAuth != null) "authorization": basicAuth,
if (extraHeaders != null) ...extraHeaders,
// "Accept": "application/json",
// "Content-Type": "application/json",
},
Expand Down
10 changes: 10 additions & 0 deletions lib/core/model/app_info_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class AppInfoEntity with _$AppInfoEntity {

String get userAgent => "HiddifyNext/$version ($operatingSystem) like ClashMeta v2ray sing-box";

/// Normalized OS name for HTTP headers (e.g. x-device-os).
String get displayOs => switch (operatingSystem) {
'android' => 'Android',
'ios' => 'iOS',
'macos' => 'macOS',
'windows' => 'Windows',
'linux' => 'Linux',
_ => operatingSystem,
};

String get presentVersion => environment == Environment.prod ? version : "$version ${environment.name}";

/// formats app info for sharing
Expand Down
14 changes: 14 additions & 0 deletions lib/core/preferences/general_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import 'package:hiddify/core/utils/preferences_utils.dart';
import 'package:hiddify/features/per_app_proxy/model/per_app_proxy_mode.dart';
import 'package:hiddify/features/window/notifier/window_notifier.dart';
import 'package:hiddify/utils/platform_utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:uuid/uuid.dart';

part 'general_preferences.g.dart';

Expand Down Expand Up @@ -128,3 +130,15 @@ class DebugModeNotifier extends _$DebugModeNotifier {
return _pref.write(value);
}
}

/// Persistent hardware ID — генерируется один раз при первом запуске.
/// Используется для идентификации устройства на стороне панели (Remnawave HWID).
final hwidProvider = Provider<String>((ref) {
final prefs = ref.read(sharedPreferencesProvider).requireValue;
const key = 'device_hwid';
final stored = prefs.getString(key);
if (stored != null && stored.isNotEmpty) return stored;
final hwid = const Uuid().v4();
prefs.setString(key, hwid);
return hwid;
});
14 changes: 14 additions & 0 deletions lib/features/profile/data/profile_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import 'dart:io';
import 'package:dartx/dartx.dart';
import 'package:dio/dio.dart';
import 'package:fpdart/fpdart.dart';
import 'package:hiddify/core/app_info/app_info_provider.dart';
import 'package:hiddify/core/app_info/device_info_provider.dart';
import 'package:hiddify/core/db/db.dart';
import 'package:hiddify/core/http_client/dio_http_client.dart';
import 'package:hiddify/core/preferences/general_preferences.dart';
import 'package:hiddify/features/profile/data/profile_data_mapper.dart';
import 'package:hiddify/features/profile/model/profile_entity.dart';
import 'package:hiddify/features/profile/model/profile_failure.dart';
Expand Down Expand Up @@ -149,6 +152,16 @@ class ProfileParser {
// if (url.startsWith("http://"))
// throw const ProfileFailure.invalidUrl('HTTP is not supported. Please use HTTPS for secure connection.');

final appInfo = _ref.read(appInfoProvider).requireValue;
final hwid = _ref.read(hwidProvider);
final deviceModel = await _ref.read(deviceModelProvider.future);
final hwidHeaders = <String, String>{
'x-hwid': hwid,
'x-device-os': appInfo.displayOs,
'x-ver-os': appInfo.operatingSystemVersion,
if (deviceModel.isNotEmpty) 'x-device-model': deviceModel,
};

final rs = await _httpClient
.download(
url.trim(),
Expand All @@ -157,6 +170,7 @@ class ProfileParser {
userAgent: _ref.read(ConfigOptions.useXrayCoreWhenPossible)
? _httpClient.userAgent.replaceAll("HiddifyNext", "HiddifyNextX")
: null,
extraHeaders: hwidHeaders,
)
.catchError((err) {
if (CancelToken.isCancel(err as DioException)) {
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
screen_retriever: ^0.2.0

package_info_plus: ^8.1.0
device_info_plus: ^10.1.0

url_launcher: ^6.2.5
vclibs: ^0.1.2
Expand Down