parent
b247c8640d
commit
f840865597
24 changed files with 198 additions and 87 deletions
@ -0,0 +1,10 @@ |
|||||||
|
[package] |
||||||
|
name = "be" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2018" |
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
actix-web = "3.3.2" |
||||||
|
u_lib = { version = "*", path = "../../../lib/u_lib" } |
@ -0,0 +1,12 @@ |
|||||||
|
[package] |
||||||
|
name = "fe" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2018" |
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
u_lib = { version = "*", path = "../../../lib/u_lib" } |
||||||
|
wasm-bindgen = "0.2.78" |
||||||
|
yew = "0.18.0" |
||||||
|
yew-router = "0.15.0" |
@ -0,0 +1,9 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html> |
||||||
|
|
||||||
|
<head> |
||||||
|
<meta charset="utf-8" /> |
||||||
|
<title>Yew App</title> |
||||||
|
</head> |
||||||
|
|
||||||
|
</html> |
@ -0,0 +1,51 @@ |
|||||||
|
use wasm_bindgen::prelude::*; |
||||||
|
use yew::prelude::*; |
||||||
|
enum Msg { |
||||||
|
AddOne, |
||||||
|
} |
||||||
|
struct Model { |
||||||
|
// `ComponentLink` is like a reference to a component.
|
||||||
|
// It can be used to send messages to the component
|
||||||
|
link: ComponentLink<Self>, |
||||||
|
value: i64, |
||||||
|
} |
||||||
|
|
||||||
|
impl Component for Model { |
||||||
|
type Message = Msg; |
||||||
|
type Properties = (); |
||||||
|
|
||||||
|
fn create(_props: Self::Properties, link: ComponentLink<Self>) -> Self { |
||||||
|
Self { link, value: 0 } |
||||||
|
} |
||||||
|
|
||||||
|
fn update(&mut self, msg: Self::Message) -> ShouldRender { |
||||||
|
match msg { |
||||||
|
Msg::AddOne => { |
||||||
|
self.value += 1; |
||||||
|
// the value has changed so we need to
|
||||||
|
// re-render for it to appear on the page
|
||||||
|
true |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fn change(&mut self, _props: Self::Properties) -> ShouldRender { |
||||||
|
// Should only return "true" if new properties are different to
|
||||||
|
// previously received properties.
|
||||||
|
// This component has no properties so we will always return "false".
|
||||||
|
false |
||||||
|
} |
||||||
|
|
||||||
|
fn view(&self) -> Html { |
||||||
|
html! { |
||||||
|
<div> |
||||||
|
<button onclick=self.link.callback(|_| Msg::AddOne)>{ "+1" }</button> |
||||||
|
<p>{ self.value }</p> |
||||||
|
</div> |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
pub fn main() { |
||||||
|
yew::start_app::<Model>(); |
||||||
|
} |
@ -1,3 +0,0 @@ |
|||||||
mod app; |
|
||||||
|
|
||||||
pub use app::serve; |
|
@ -0,0 +1,37 @@ |
|||||||
|
use nix::{ |
||||||
|
sys::signal::{signal, SigHandler, Signal}, |
||||||
|
unistd::{chdir, close as fdclose, fork, getppid, setsid, ForkResult}, |
||||||
|
}; |
||||||
|
use std::process::exit; |
||||||
|
|
||||||
|
pub fn daemonize() { |
||||||
|
if getppid().as_raw() != 1 { |
||||||
|
setsig(Signal::SIGTTOU, SigHandler::SigIgn); |
||||||
|
setsig(Signal::SIGTTIN, SigHandler::SigIgn); |
||||||
|
setsig(Signal::SIGTSTP, SigHandler::SigIgn); |
||||||
|
} |
||||||
|
for fd in 0..=2 { |
||||||
|
match fdclose(fd) { |
||||||
|
_ => (), |
||||||
|
} |
||||||
|
} |
||||||
|
match chdir("/") { |
||||||
|
_ => (), |
||||||
|
}; |
||||||
|
|
||||||
|
match fork() { |
||||||
|
Ok(ForkResult::Parent { .. }) => { |
||||||
|
exit(0); |
||||||
|
} |
||||||
|
Ok(ForkResult::Child) => match setsid() { |
||||||
|
_ => (), |
||||||
|
}, |
||||||
|
Err(_) => exit(255), |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
pub fn setsig(sig: Signal, hnd: SigHandler) { |
||||||
|
unsafe { |
||||||
|
signal(sig, hnd).unwrap(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue