summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-05-18 21:27:30 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-05-18 21:27:30 +0200
commitc44d69dcde20d6b200f7c2782a4ebbb848e2ed1f (patch)
tree92f07a1beeddd2b82972616a11670984376a168b
parent75dadb51fee37579d5b02005096e0d9e7f26f87c (diff)
downloaddistrox-c44d69dcde20d6b200f7c2782a4ebbb848e2ed1f.tar.gz
distrox-c44d69dcde20d6b200f7c2782a4ebbb848e2ed1f.tar.xz
Move app startup code to server part
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/gui.rs24
-rw-r--r--src/main.rs6
-rw-r--r--src/server.rs23
3 files changed, 26 insertions, 27 deletions
diff --git a/src/gui.rs b/src/gui.rs
index 574d6de..1d5281e 100644
--- a/src/gui.rs
+++ b/src/gui.rs
@@ -5,32 +5,10 @@ use anyhow::Result;
use web_view::WVResult;
use web_view::WebView;
-use crate::app::App;
use crate::cli::*;
-use crate::configuration::Configuration;
use crate::types::util::*;
-pub fn run_gui(config: Configuration, adr: String) -> Result<()> {
- // GUI
- let app = {
- let device_name = config.get_device_name();
- let device_key = config.get_device_key();
-
- if let (Some(name), Some(key)) = (device_name, device_key) {
- let name = IPNSHash::from(name.clone());
- let key = key.clone();
- let api_url = config.get_api_url().clone();
- let api_port = config.get_api_port().clone();
-
- App::load(name, key, &api_url, api_port)
- } else {
- // ask user for name(s)
- // boot repository
- // load App object
- unimplemented!()
- }
- };
-
+pub fn run_gui(adr: String) -> Result<()> {
let webview_content = web_view::Content::Url(format!("http://{}", adr));
web_view::builder()
diff --git a/src/main.rs b/src/main.rs
index 6575203..b624bd8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -93,18 +93,18 @@ async fn main() -> Result<()> {
let start_server = crate::server::do_start(&cli);
match (server_running, start_server) {
- (true, false) => crate::gui::run_gui(config, adr),
+ (true, false) => crate::gui::run_gui(adr),
(false, false) => {
// fork()
info!("Spawning server thread...");
let path = std::env::current_exe()?;
let mut child = std::process::Command::new(path).arg("server").spawn()?;
- let r = crate::gui::run_gui(config, adr);
+ let r = crate::gui::run_gui(adr);
child.kill()?;
r
},
- (false, true) => crate::server::run_server(server_lock, adr).await,
+ (false, true) => crate::server::run_server(config, server_lock, adr).await,
(true, true) => {
info!("Server is already running. Doing nothing.");
diff --git a/src/server.rs b/src/server.rs
index f2df45c..0fc8e9b 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -8,7 +8,9 @@ use actix_web::Responder;
use actix_web::http::StatusCode;
use actix_web::body::Body;
+use crate::app::App;
use crate::cli::*;
+use crate::configuration::Configuration;
use crate::types::util::*;
pub fn mk_lock() -> Pidlock {
@@ -24,7 +26,26 @@ pub fn is_running(server_lock: &Pidlock) -> bool {
}
-pub async fn run_server(mut server_lock: Pidlock, adr: String) -> Result<()> {
+pub async fn run_server(config: Configuration, mut server_lock: Pidlock, adr: String) -> Result<()> {
+ let app = {
+ let device_name = config.get_device_name();
+ let device_key = config.get_device_key();
+
+ if let (Some(name), Some(key)) = (device_name, device_key) {
+ let name = IPNSHash::from(name.clone());
+ let key = key.clone();
+ let api_url = config.get_api_url().clone();
+ let api_port = config.get_api_port().clone();
+
+ App::load(name, key, &api_url, api_port)
+ } else {
+ // ask user for name(s)
+ // boot repository
+ // load App object
+ unimplemented!()
+ }
+ }?;
+
info!("Starting server");
let _ = server_lock.acquire().map_err(|_| anyhow!("Error while getting the PID lock"))?;