mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
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.
This commit is contained in:
parent
a5a21a59ad
commit
c8d911817f
1 changed files with 33 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,35 +33,41 @@ 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 {
|
||||||
let reply = BoolReply {
|
PrefValue::Float(value) => {
|
||||||
|
let reply = FloatReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
value: false,
|
value: value,
|
||||||
};
|
};
|
||||||
let _ = stream.write_json_packet(&reply);
|
let _ = stream.write_json_packet(&reply);
|
||||||
ActorMessageStatus::Processed
|
ActorMessageStatus::Processed
|
||||||
},
|
},
|
||||||
|
PrefValue::Int(value) => {
|
||||||
"getCharPref" => {
|
|
||||||
let reply = CharReply {
|
|
||||||
from: self.name(),
|
|
||||||
value: "".to_owned(),
|
|
||||||
};
|
|
||||||
let _ = stream.write_json_packet(&reply);
|
|
||||||
ActorMessageStatus::Processed
|
|
||||||
},
|
|
||||||
|
|
||||||
"getIntPref" => {
|
|
||||||
let reply = IntReply {
|
let reply = IntReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
value: 0,
|
value: value,
|
||||||
};
|
};
|
||||||
let _ = stream.write_json_packet(&reply);
|
let _ = stream.write_json_packet(&reply);
|
||||||
ActorMessageStatus::Processed
|
ActorMessageStatus::Processed
|
||||||
},
|
},
|
||||||
|
PrefValue::Str(value) => {
|
||||||
_ => ActorMessageStatus::Ignored,
|
let reply = CharReply {
|
||||||
|
from: self.name(),
|
||||||
|
value: value,
|
||||||
|
};
|
||||||
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
PrefValue::Bool(value) => {
|
||||||
|
let reply = BoolReply {
|
||||||
|
from: self.name(),
|
||||||
|
value: value,
|
||||||
|
};
|
||||||
|
let _ = stream.write_json_packet(&reply);
|
||||||
|
ActorMessageStatus::Processed
|
||||||
|
},
|
||||||
|
PrefValue::Missing => ActorMessageStatus::Ignored,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,5 +87,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