Merge pull request #5308 from dignow/fix/login_device_info
fix, login device info
This commit is contained in:
commit
064d00f136
@ -1,4 +1,5 @@
|
|||||||
import 'dart:io';
|
import 'dart:convert';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_hbb/models/peer_model.dart';
|
import 'package:flutter_hbb/models/peer_model.dart';
|
||||||
|
|
||||||
@ -70,16 +71,6 @@ class PeerPayload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeviceInfo {
|
|
||||||
static Map<String, dynamic> toJson() {
|
|
||||||
final Map<String, dynamic> data = <String, dynamic>{};
|
|
||||||
data['os'] = Platform.operatingSystem;
|
|
||||||
data['type'] = "client";
|
|
||||||
data['name'] = bind.mainGetHostname();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoginRequest {
|
class LoginRequest {
|
||||||
String? username;
|
String? username;
|
||||||
String? password;
|
String? password;
|
||||||
@ -88,7 +79,6 @@ class LoginRequest {
|
|||||||
bool? autoLogin;
|
bool? autoLogin;
|
||||||
String? type;
|
String? type;
|
||||||
String? verificationCode;
|
String? verificationCode;
|
||||||
Map<String, dynamic> deviceInfo = DeviceInfo.toJson();
|
|
||||||
|
|
||||||
LoginRequest(
|
LoginRequest(
|
||||||
{this.username,
|
{this.username,
|
||||||
@ -110,6 +100,13 @@ class LoginRequest {
|
|||||||
if (verificationCode != null) {
|
if (verificationCode != null) {
|
||||||
data['verificationCode'] = verificationCode;
|
data['verificationCode'] = verificationCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> deviceInfo = {};
|
||||||
|
try {
|
||||||
|
deviceInfo = jsonDecode(bind.mainGetLoginDeviceInfo());
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Failed to decode get device info: $e');
|
||||||
|
}
|
||||||
data['deviceInfo'] = deviceInfo;
|
data['deviceInfo'] = deviceInfo;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -637,8 +637,8 @@ pub fn main_get_default_sound_input() -> Option<String> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_get_hostname() -> SyncReturn<String> {
|
pub fn main_get_login_device_info() -> SyncReturn<String> {
|
||||||
SyncReturn(get_hostname())
|
SyncReturn(get_login_device_info_json())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_change_id(new_id: String) {
|
pub fn main_change_id(new_id: String) {
|
||||||
|
@ -148,7 +148,12 @@ impl OidcSession {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.client
|
.client
|
||||||
.post(format!("{}/api/oidc/auth", api_server))
|
.post(format!("{}/api/oidc/auth", api_server))
|
||||||
.json(&HashMap::from([("op", op), ("id", id), ("uuid", uuid)]))
|
.json(&serde_json::json!({
|
||||||
|
"op": op,
|
||||||
|
"id": id,
|
||||||
|
"uuid": uuid,
|
||||||
|
"deviceInfo": crate::ui_interface::get_login_device_info(),
|
||||||
|
}))
|
||||||
.send()?
|
.send()?
|
||||||
.try_into()?)
|
.try_into()?)
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,7 @@ use std::{collections::HashMap, ffi::c_void, os::raw::c_int};
|
|||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::{
|
use crate::{define_method_prefix, flutter::APP_TYPE_MAIN};
|
||||||
define_method_prefix,
|
|
||||||
flutter::{APP_TYPE_MAIN},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::PluginNativeHandler;
|
use super::PluginNativeHandler;
|
||||||
|
|
||||||
@ -26,7 +23,8 @@ pub struct PluginNativeUIHandler;
|
|||||||
/// ```
|
/// ```
|
||||||
/// [Safety]
|
/// [Safety]
|
||||||
/// Please make sure the callback u provided is VALID, or memory or calling issues may occur to cause the program crash!
|
/// Please make sure the callback u provided is VALID, or memory or calling issues may occur to cause the program crash!
|
||||||
pub type OnUIReturnCallback = extern "C" fn(return_code: c_int, data: *const c_void, data_len: u64, user_data: *const c_void);
|
pub type OnUIReturnCallback =
|
||||||
|
extern "C" fn(return_code: c_int, data: *const c_void, data_len: u64, user_data: *const c_void);
|
||||||
|
|
||||||
impl PluginNativeHandler for PluginNativeUIHandler {
|
impl PluginNativeHandler for PluginNativeUIHandler {
|
||||||
define_method_prefix!("ui_");
|
define_method_prefix!("ui_");
|
||||||
@ -41,9 +39,7 @@ impl PluginNativeHandler for PluginNativeUIHandler {
|
|||||||
if let Some(cb) = data.get("cb") {
|
if let Some(cb) = data.get("cb") {
|
||||||
if let Some(cb) = cb.as_u64() {
|
if let Some(cb) = cb.as_u64() {
|
||||||
let user_data = match data.get("user_data") {
|
let user_data = match data.get("user_data") {
|
||||||
Some(user_data) => {
|
Some(user_data) => user_data.as_u64().unwrap_or(0),
|
||||||
user_data.as_u64().unwrap_or(0)
|
|
||||||
},
|
|
||||||
None => 0,
|
None => 0,
|
||||||
};
|
};
|
||||||
self.select_peers_async(cb, user_data);
|
self.select_peers_async(cb, user_data);
|
||||||
@ -68,9 +64,7 @@ impl PluginNativeHandler for PluginNativeUIHandler {
|
|||||||
if let Some(on_tap_cb) = data.get("on_tap_cb") {
|
if let Some(on_tap_cb) = data.get("on_tap_cb") {
|
||||||
if let Some(on_tap_cb) = on_tap_cb.as_u64() {
|
if let Some(on_tap_cb) = on_tap_cb.as_u64() {
|
||||||
let user_data = match data.get("user_data") {
|
let user_data = match data.get("user_data") {
|
||||||
Some(user_data) => {
|
Some(user_data) => user_data.as_u64().unwrap_or(0),
|
||||||
user_data.as_u64().unwrap_or(0)
|
|
||||||
},
|
|
||||||
None => 0,
|
None => 0,
|
||||||
};
|
};
|
||||||
self.register_ui_entry(title, on_tap_cb, user_data);
|
self.register_ui_entry(title, on_tap_cb, user_data);
|
||||||
|
@ -44,6 +44,13 @@ pub struct UiStatus {
|
|||||||
pub id: String,
|
pub id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct LoginDeviceInfo {
|
||||||
|
pub os: String,
|
||||||
|
pub r#type: String,
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref UI_STATUS : Arc<Mutex<UiStatus>> = Arc::new(Mutex::new(UiStatus{
|
static ref UI_STATUS : Arc<Mutex<UiStatus>> = Arc::new(Mutex::new(UiStatus{
|
||||||
status_num: 0,
|
status_num: 0,
|
||||||
@ -959,6 +966,21 @@ pub fn get_hostname() -> String {
|
|||||||
crate::common::hostname()
|
crate::common::hostname()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_login_device_info() -> LoginDeviceInfo {
|
||||||
|
LoginDeviceInfo {
|
||||||
|
// std::env::consts::OS is better than whoami::platform() here.
|
||||||
|
os: std::env::consts::OS.to_owned(),
|
||||||
|
r#type: "client".to_owned(),
|
||||||
|
name: crate::common::hostname(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_login_device_info_json() -> String {
|
||||||
|
serde_json::to_string(&get_login_device_info()).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
// notice: avoiding create ipc connection repeatedly,
|
// notice: avoiding create ipc connection repeatedly,
|
||||||
// because windows named pipe has serious memory leak issue.
|
// because windows named pipe has serious memory leak issue.
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user