Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Local dapps embeddable on signer port #2815

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions dapps/src/apps/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct ContentFetcher<R: URLHint = URLHintContract> {
resolver: R,
cache: Arc<Mutex<ContentCache>>,
sync: Arc<SyncStatus>,
embeddable_at: Option<u16>,
}

impl<R: URLHint> Drop for ContentFetcher<R> {
Expand All @@ -57,7 +58,7 @@ impl<R: URLHint> Drop for ContentFetcher<R> {

impl<R: URLHint> ContentFetcher<R> {

pub fn new(resolver: R, sync_status: Arc<SyncStatus>) -> Self {
pub fn new(resolver: R, sync_status: Arc<SyncStatus>, embeddable_at: Option<u16>) -> Self {
let mut dapps_path = env::temp_dir();
dapps_path.push(random_filename());

Expand All @@ -66,6 +67,7 @@ impl<R: URLHint> ContentFetcher<R> {
resolver: resolver,
sync: sync_status,
cache: Arc::new(Mutex::new(ContentCache::default())),
embeddable_at: embeddable_at,
}
}

Expand Down Expand Up @@ -150,6 +152,7 @@ impl<R: URLHint> ContentFetcher<R> {
id: content_id.clone(),
dapps_path: self.dapps_path.clone(),
on_done: Box::new(on_done),
embeddable_at: self.embeddable_at,
}
);

Expand Down Expand Up @@ -271,6 +274,7 @@ struct DappInstaller {
id: String,
dapps_path: PathBuf,
on_done: Box<Fn(String, Option<LocalPageEndpoint>) + Send>,
embeddable_at: Option<u16>,
}

impl DappInstaller {
Expand Down Expand Up @@ -363,7 +367,7 @@ impl ContentValidator for DappInstaller {
try!(manifest_file.write_all(manifest_str.as_bytes()));

// Create endpoint
let app = LocalPageEndpoint::new(target, manifest.clone().into());
let app = LocalPageEndpoint::new(target, manifest.clone().into(), self.embeddable_at);

// Return modified app manifest
Ok((manifest.id.clone(), app))
Expand Down Expand Up @@ -396,14 +400,14 @@ mod tests {
fn should_true_if_contains_the_app() {
// given
let path = env::temp_dir();
let fetcher = ContentFetcher::new(FakeResolver, Arc::new(|| false));
let fetcher = ContentFetcher::new(FakeResolver, Arc::new(|| false), None);
let handler = LocalPageEndpoint::new(path, EndpointInfo {
name: "fake".into(),
description: "".into(),
version: "".into(),
author: "".into(),
icon_url: "".into(),
});
}, None);

// when
fetcher.set_status("test", ContentStatus::Ready(handler));
Expand Down
4 changes: 2 additions & 2 deletions dapps/src/apps/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ fn read_manifest(name: &str, mut path: PathBuf) -> EndpointInfo {
})
}

pub fn local_endpoints(dapps_path: String) -> Endpoints {
pub fn local_endpoints(dapps_path: String, signer_port: Option<u16>) -> Endpoints {
let mut pages = Endpoints::new();
for dapp in local_dapps(dapps_path) {
pages.insert(
dapp.id,
Box::new(LocalPageEndpoint::new(dapp.path, dapp.info))
Box::new(LocalPageEndpoint::new(dapp.path, dapp.info, signer_port))
);
}
pages
Expand Down
2 changes: 1 addition & 1 deletion dapps/src/apps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn utils() -> Box<Endpoint> {

pub fn all_endpoints(dapps_path: String, signer_port: Option<u16>) -> Endpoints {
// fetch fs dapps at first to avoid overwriting builtins
let mut pages = fs::local_endpoints(dapps_path);
let mut pages = fs::local_endpoints(dapps_path, signer_port);

// NOTE [ToDr] Dapps will be currently embeded on 8180
insert::<parity_ui::App>(&mut pages, "ui", Embeddable::Yes(signer_port));
Expand Down
2 changes: 1 addition & 1 deletion dapps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Server {
) -> Result<Server, ServerError> {
let panic_handler = Arc::new(Mutex::new(None));
let authorization = Arc::new(authorization);
let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new(apps::urlhint::URLHintContract::new(registrar), sync_status));
let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new(apps::urlhint::URLHintContract::new(registrar), sync_status, signer_port));
let endpoints = Arc::new(apps::all_endpoints(dapps_path, signer_port.clone()));
let cors_domains = Self::cors_domains(signer_port);

Expand Down
9 changes: 6 additions & 3 deletions dapps/src/page/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ pub struct LocalPageEndpoint {
path: PathBuf,
mime: Option<String>,
info: Option<EndpointInfo>,
embeddable_at: Option<u16>,
}

impl LocalPageEndpoint {
pub fn new(path: PathBuf, info: EndpointInfo) -> Self {
pub fn new(path: PathBuf, info: EndpointInfo, embeddable_at: Option<u16>) -> Self {
LocalPageEndpoint {
path: path,
mime: None,
info: Some(info),
embeddable_at: embeddable_at,
}
}

Expand All @@ -42,6 +44,7 @@ impl LocalPageEndpoint {
path: path,
mime: Some(mime),
info: None,
embeddable_at: None,
}
}

Expand All @@ -62,15 +65,15 @@ impl Endpoint for LocalPageEndpoint {
prefix: None,
path: path,
file: handler::ServedFile::new(None),
safe_to_embed_at_port: None,
safe_to_embed_at_port: self.embeddable_at,
})
} else {
Box::new(handler::PageHandler {
app: LocalDapp { path: self.path.clone() },
prefix: None,
path: path,
file: handler::ServedFile::new(None),
safe_to_embed_at_port: None,
safe_to_embed_at_port: self.embeddable_at,
})
}
}
Expand Down