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

Commit

Permalink
Get rid of 'Dapp is being downloaded' page
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Drwięga committed Sep 6, 2016
1 parent 9655920 commit 6f88b7f
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 76 deletions.
8 changes: 4 additions & 4 deletions dapps/src/apps/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
use std::fs;
use std::sync::{Arc};
use std::sync::atomic::{AtomicBool, Ordering};

use linked_hash_map::LinkedHashMap;
use page::LocalPageEndpoint;
use handlers::FetchControl;

pub enum ContentStatus {
Fetching(Arc<AtomicBool>),
Fetching(Arc<FetchControl>),
Ready(LocalPageEndpoint),
}

Expand Down Expand Up @@ -57,10 +57,10 @@ impl ContentCache {
while len > expected_size {
let entry = self.cache.pop_front().unwrap();
match entry.1 {
ContentStatus::Fetching(ref abort) => {
ContentStatus::Fetching(ref fetch) => {
trace!(target: "dapps", "Aborting {} because of limit.", entry.0);
// Mark as aborted
abort.store(true, Ordering::SeqCst);
fetch.abort()
},
ContentStatus::Ready(ref endpoint) => {
trace!(target: "dapps", "Removing {} because of limit.", entry.0);
Expand Down
31 changes: 14 additions & 17 deletions dapps/src/apps/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::{fs, env, fmt};
use std::io::{self, Read, Write};
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool};
use rustc_serialize::hex::FromHex;

use hyper;
Expand Down Expand Up @@ -76,10 +75,12 @@ impl<R: URLHint> AppFetcher<R> {
}

pub fn contains(&self, app_id: &str) -> bool {
let mut dapps = self.dapps.lock();
// Check if we already have the app
if dapps.get(app_id).is_some() {
return true;
{
let mut dapps = self.dapps.lock();
// Check if we already have the app
if dapps.get(app_id).is_some() {
return true;
}
}
// fallback to resolver
if let Ok(app_id) = app_id.from_hex() {
Expand Down Expand Up @@ -115,33 +116,29 @@ impl<R: URLHint> AppFetcher<R> {
(None, endpoint.to_async_handler(path, control))
},
// App is already being fetched
Some(&mut ContentStatus::Fetching(_)) => {
(None, Box::new(ContentHandler::error_with_refresh(
StatusCode::ServiceUnavailable,
"Download In Progress",
"This dapp is already being downloaded. Please wait...",
None,
)) as Box<Handler>)
Some(&mut ContentStatus::Fetching(ref fetch_control)) => {
trace!(target: "dapps", "Content fetching in progress. Waiting...");
(None, fetch_control.to_handler(control))
},
// We need to start fetching app
None => {
trace!(target: "dapps", "Content fetching unavailable. Fetching...");
let app_hex = app_id.from_hex().expect("to_handler is called only when `contains` returns true.");
let app = self.resolver.resolve(app_hex);

if let Some(app) = app {
let abort = Arc::new(AtomicBool::new(false));

(Some(ContentStatus::Fetching(abort.clone())), Box::new(ContentFetcherHandler::new(
let (handler, fetch_control) = ContentFetcherHandler::new(
app,
abort,
control,
path.using_dapps_domains,
DappInstaller {
dapp_id: app_id.clone(),
dapps_path: self.dapps_path.clone(),
dapps: self.dapps.clone(),
}
)) as Box<Handler>)
);

(Some(ContentStatus::Fetching(fetch_control)), Box::new(handler) as Box<Handler>)
} else {
// This may happen when sync status changes in between
// `contains` and `to_handler`
Expand Down
1 change: 0 additions & 1 deletion dapps/src/error_tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
{meta}
<title>{title}</title>
<link rel="stylesheet" href="/parity-utils/styles.css">
</head>
Expand Down
13 changes: 1 addition & 12 deletions dapps/src/handlers/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use hyper::status::StatusCode;

use util::version;

#[derive(Clone)]
pub struct ContentHandler {
code: StatusCode,
content: String,
Expand Down Expand Up @@ -57,18 +58,6 @@ impl ContentHandler {
Self::html(code, format!(
include_str!("../error_tpl.html"),
title=title,
meta="",
message=message,
details=details.unwrap_or_else(|| ""),
version=version(),
))
}

pub fn error_with_refresh(code: StatusCode, title: &str, message: &str, details: Option<&str>) -> Self {
Self::html(code, format!(
include_str!("../error_tpl.html"),
title=title,
meta="<meta http-equiv=\"refresh\" content=\"1\">",
message=message,
details=details.unwrap_or_else(|| ""),
version=version(),
Expand Down
Loading

0 comments on commit 6f88b7f

Please sign in to comment.