Skip to content

Commit

Permalink
core: make it easier to change declared OS
Browse files Browse the repository at this point in the history
  • Loading branch information
dsheets committed Dec 6, 2023
1 parent 29f3345 commit 0fbd19b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions core/src/spclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 0fbd19b

Please sign in to comment.