core: make it easier to change declared OS

This commit is contained in:
David Sheets 2023-12-06 10:51:39 +00:00
parent 29f3345030
commit 0fbd19b521
2 changed files with 14 additions and 7 deletions

View file

@ -16,17 +16,17 @@ pub struct SessionConfig {
pub autoplay: Option<bool>,
}
impl Default for SessionConfig {
fn default() -> SessionConfig {
impl SessionConfig {
pub(crate) fn default_for_os(os: &str) -> Self {
let device_id = uuid::Uuid::new_v4().as_hyphenated().to_string();
let client_id = match std::env::consts::OS {
let client_id = match os {
"android" => ANDROID_CLIENT_ID,
"ios" => IOS_CLIENT_ID,
_ => KEYMASTER_CLIENT_ID,
}
.to_owned();
SessionConfig {
Self {
client_id,
device_id,
proxy: None,
@ -37,6 +37,12 @@ impl Default for SessionConfig {
}
}
impl Default for SessionConfig {
fn default() -> Self {
Self::default_for_os(std::env::consts::OS)
}
}
#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub enum DeviceType {
Unknown = 0,

View file

@ -190,9 +190,10 @@ impl SpClient {
// on macOS and Windows. On Android and iOS we can send a platform-specific client ID and are
// then presented with a hash cash challenge. On Linux, we have to pass the old keymaster ID.
// We delegate most of this logic to `SessionConfig`.
let client_id = match OS {
let os = OS;
let client_id = match os {
"macos" | "windows" => self.session().client_id(),
_ => SessionConfig::default().client_id,
os => SessionConfig::default_for_os(os).client_id,
};
client_data.client_id = client_id;
@ -207,7 +208,7 @@ impl SpClient {
let os_version = sys.os_version().unwrap_or_else(|| String::from("0"));
let kernel_version = sys.kernel_version().unwrap_or_else(|| String::from("0"));
match OS {
match os {
"windows" => {
let os_version = os_version.parse::<f32>().unwrap_or(10.) as i32;
let kernel_version = kernel_version.parse::<i32>().unwrap_or(21370);