Skip to content

Commit

Permalink
feat: option to disable shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Aug 7, 2024
1 parent 7b39dfe commit 3e16bf8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ struct Args {
base_path: Option<String>,

/// Don't open URL in the system browser.
#[clap(short, long)]
#[clap(long)]
no_browser: bool,

/// Don't show the shutdown button in the UI.
#[clap(long)]
no_shutdown: bool,
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -139,7 +143,7 @@ async fn main() -> color_eyre::Result<()> {

let (shutdown_tx, mut shutdown_rx) = mpsc::channel(1);

let api = warp::path("api").and(handlers::routes(db, shutdown_tx));
let api = warp::path("api").and(handlers::routes(db, args.no_shutdown, shutdown_tx));
let homepage = statics::homepage(index_html.clone());
let statics = statics::routes();

Expand Down Expand Up @@ -2953,6 +2957,7 @@ mod handlers {

pub fn routes(
db: impl Database,
no_shutdown: bool,
shutdown_signal: mpsc::Sender<()>,
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
let overview = warp::path::end()
Expand Down Expand Up @@ -2981,6 +2986,7 @@ mod handlers {
let shutdown = warp::post()
.and(warp::path!("shutdown"))
.and(with_state(&shutdown_signal))
.and(warp::any().map(move || no_shutdown))
.and_then(shutdown);

overview
Expand Down Expand Up @@ -3062,9 +3068,12 @@ mod handlers {

async fn shutdown(
shutdown_signal: mpsc::Sender<()>,
no_shutdown: bool,
) -> Result<impl warp::Reply, warp::Rejection> {
let res = shutdown_signal.send(()).await;
tracing::info!("sent shutdown signal: {res:?}");
if !no_shutdown {
let res = shutdown_signal.send(()).await;
tracing::info!("sent shutdown signal: {res:?}");
}
Ok("")
}
}
Expand Down

0 comments on commit 3e16bf8

Please sign in to comment.