Skip to content

Commit 0fbd19b

Browse files
committed
core: make it easier to change declared OS
1 parent 29f3345 commit 0fbd19b

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

core/src/config.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ pub struct SessionConfig {
1616
pub autoplay: Option<bool>,
1717
}
1818

19-
impl Default for SessionConfig {
20-
fn default() -> SessionConfig {
19+
impl SessionConfig {
20+
pub(crate) fn default_for_os(os: &str) -> Self {
2121
let device_id = uuid::Uuid::new_v4().as_hyphenated().to_string();
22-
let client_id = match std::env::consts::OS {
22+
let client_id = match os {
2323
"android" => ANDROID_CLIENT_ID,
2424
"ios" => IOS_CLIENT_ID,
2525
_ => KEYMASTER_CLIENT_ID,
2626
}
2727
.to_owned();
2828

29-
SessionConfig {
29+
Self {
3030
client_id,
3131
device_id,
3232
proxy: None,
@@ -37,6 +37,12 @@ impl Default for SessionConfig {
3737
}
3838
}
3939

40+
impl Default for SessionConfig {
41+
fn default() -> Self {
42+
Self::default_for_os(std::env::consts::OS)
43+
}
44+
}
45+
4046
#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
4147
pub enum DeviceType {
4248
Unknown = 0,

core/src/spclient.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ impl SpClient {
190190
// on macOS and Windows. On Android and iOS we can send a platform-specific client ID and are
191191
// then presented with a hash cash challenge. On Linux, we have to pass the old keymaster ID.
192192
// We delegate most of this logic to `SessionConfig`.
193-
let client_id = match OS {
193+
let os = OS;
194+
let client_id = match os {
194195
"macos" | "windows" => self.session().client_id(),
195-
_ => SessionConfig::default().client_id,
196+
os => SessionConfig::default_for_os(os).client_id,
196197
};
197198
client_data.client_id = client_id;
198199

@@ -207,7 +208,7 @@ impl SpClient {
207208
let os_version = sys.os_version().unwrap_or_else(|| String::from("0"));
208209
let kernel_version = sys.kernel_version().unwrap_or_else(|| String::from("0"));
209210

210-
match OS {
211+
match os {
211212
"windows" => {
212213
let os_version = os_version.parse::<f32>().unwrap_or(10.) as i32;
213214
let kernel_version = kernel_version.parse::<i32>().unwrap_or(21370);

0 commit comments

Comments
 (0)