mirror of
https://github.com/servo/servo.git
synced 2025-08-17 11:25:35 +01:00
Auto merge of #27634 - sudarshan-reddy:preferences-actor-returns-real-vals, r=jdm
preferences actor now returns real values. The preferences actor was previously returning mock values. This changes picks up the pref_values from the pref_map which is global preferences state and returns values from there. <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #27510 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because none of the actors have tests. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
ac354572e2
1 changed files with 72 additions and 19 deletions
|
@ -6,6 +6,8 @@ use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||||
use crate::protocol::JsonPacketStream;
|
use crate::protocol::JsonPacketStream;
|
||||||
use crate::StreamId;
|
use crate::StreamId;
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
use servo_config::pref_util::PrefValue;
|
||||||
|
use servo_config::prefs::pref_map;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
|
|
||||||
pub struct PreferenceActor {
|
pub struct PreferenceActor {
|
||||||
|
@ -31,10 +33,56 @@ impl Actor for PreferenceActor {
|
||||||
stream: &mut TcpStream,
|
stream: &mut TcpStream,
|
||||||
_id: StreamId,
|
_id: StreamId,
|
||||||
) -> Result<ActorMessageStatus, ()> {
|
) -> Result<ActorMessageStatus, ()> {
|
||||||
Ok(match msg_type {
|
let pref_value = pref_map().get(msg_type);
|
||||||
"getBoolPref" => {
|
Ok(match pref_value {
|
||||||
|
PrefValue::Float(value) => {
|
||||||
|
let reply = FloatReply {
|
||||||
|
from: self.name(),
|
||||||
|
value: value,
|
||||||
|
};
|
||||||
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
PrefValue::Int(value) => {
|
||||||
|
let reply = IntReply {
|
||||||
|
from: self.name(),
|
||||||
|
value: value,
|
||||||
|
};
|
||||||
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
PrefValue::Str(value) => {
|
||||||
|
let reply = CharReply {
|
||||||
|
from: self.name(),
|
||||||
|
value: value,
|
||||||
|
};
|
||||||
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
PrefValue::Bool(value) => {
|
||||||
let reply = BoolReply {
|
let reply = BoolReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
|
value: value,
|
||||||
|
};
|
||||||
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
PrefValue::Missing => handle_missing_preference(self.name(), msg_type, stream),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the preferences are missing from pref_map then we return a
|
||||||
|
// fake preference response based on msg_type.
|
||||||
|
fn handle_missing_preference(
|
||||||
|
name: String,
|
||||||
|
msg_type: &str,
|
||||||
|
stream: &mut TcpStream,
|
||||||
|
) -> ActorMessageStatus {
|
||||||
|
match msg_type {
|
||||||
|
"getBoolPref" => {
|
||||||
|
let reply = BoolReply {
|
||||||
|
from: name,
|
||||||
value: false,
|
value: false,
|
||||||
};
|
};
|
||||||
let _ = stream.write_json_packet(&reply);
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
@ -43,7 +91,7 @@ impl Actor for PreferenceActor {
|
||||||
|
|
||||||
"getCharPref" => {
|
"getCharPref" => {
|
||||||
let reply = CharReply {
|
let reply = CharReply {
|
||||||
from: self.name(),
|
from: name,
|
||||||
value: "".to_owned(),
|
value: "".to_owned(),
|
||||||
};
|
};
|
||||||
let _ = stream.write_json_packet(&reply);
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
@ -52,7 +100,7 @@ impl Actor for PreferenceActor {
|
||||||
|
|
||||||
"getIntPref" => {
|
"getIntPref" => {
|
||||||
let reply = IntReply {
|
let reply = IntReply {
|
||||||
from: self.name(),
|
from: name,
|
||||||
value: 0,
|
value: 0,
|
||||||
};
|
};
|
||||||
let _ = stream.write_json_packet(&reply);
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
@ -60,7 +108,6 @@ impl Actor for PreferenceActor {
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => ActorMessageStatus::Ignored,
|
_ => ActorMessageStatus::Ignored,
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,5 +126,11 @@ struct CharReply {
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct IntReply {
|
struct IntReply {
|
||||||
from: String,
|
from: String,
|
||||||
value: i32,
|
value: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct FloatReply {
|
||||||
|
from: String,
|
||||||
|
value: f64,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue