Skip to content

Commit 790daf6

Browse files
committed
chore: yet more rust code cleanups
- move the run module under interpreter::run - improved handling of optional paths to gui open window - rename gui::setup to gui::new_window Signed-off-by: Nick Mitchell <[email protected]>
1 parent 9a9ea62 commit 790daf6

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

pdl-live-react/src-tauri/src/cli/setup.rs renamed to pdl-live-react/src-tauri/src/cli.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use ::std::path::Path;
33
use tauri_plugin_cli::CliExt;
44
use urlencoding::encode;
55

6-
use crate::cli::run;
76
use crate::compile;
8-
use crate::gui::setup as gui_setup;
7+
use crate::gui::new_window;
8+
use crate::interpreter::run::run_pdl_program;
99

1010
#[cfg(desktop)]
11-
pub fn cli(app: &mut tauri::App) -> Result<bool, Box<dyn ::std::error::Error>> {
11+
pub fn setup(app: &mut tauri::App) -> Result<bool, Box<dyn ::std::error::Error>> {
1212
app.handle().plugin(tauri_plugin_cli::init())?;
1313

1414
// `matches` here is a Struct with { args, subcommand }.
@@ -49,7 +49,7 @@ pub fn cli(app: &mut tauri::App) -> Result<bool, Box<dyn ::std::error::Error>> {
4949
_ => Err(Box::from("Unsupported compile command")),
5050
}
5151
}
52-
"run" => run::run_pdl_program(
52+
"run" => run_pdl_program(
5353
subcommand_args
5454
.get("source")
5555
.and_then(|a| a.value.as_str())
@@ -59,19 +59,14 @@ pub fn cli(app: &mut tauri::App) -> Result<bool, Box<dyn ::std::error::Error>> {
5959
subcommand_args.get("stream").and_then(|a| a.value.as_str()),
6060
)
6161
.and_then(|()| Ok(true)),
62-
"view" => gui_setup(
62+
"view" => new_window(
6363
app.handle().clone(),
64-
subcommand_args
65-
.get("trace")
66-
.and_then(|a| {
67-
Some(
68-
Path::new("#/local")
69-
.join(encode(&a.value.as_str().expect("trace arg is string")).as_ref())
70-
.display()
71-
.to_string(),
72-
)
73-
})
74-
.expect("valid positional trace arg"),
64+
subcommand_args.get("trace").and_then(|a| {
65+
Some(
66+
Path::new("#/local")
67+
.join(encode(&a.value.as_str().expect("trace arg is string")).as_ref()),
68+
)
69+
}),
7570
)
7671
.and_then(|()| Ok(false)),
7772
_ => Err(Box::from("Unsupported command")),

pdl-live-react/src-tauri/src/cli/mod.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
use ::std::path::PathBuf;
12
use tauri::WebviewWindowBuilder;
23

3-
pub fn setup(app: tauri::AppHandle, path: String) -> Result<(), Box<dyn ::std::error::Error>> {
4-
WebviewWindowBuilder::new(&app, "main", tauri::WebviewUrl::App(path.into()))
5-
.title("Prompt Declaration Language")
6-
.zoom_hotkeys_enabled(true)
7-
.inner_size(1400.0, 1050.0)
8-
.build()?;
4+
pub fn new_window(
5+
app: tauri::AppHandle,
6+
path: Option<PathBuf>,
7+
) -> Result<(), Box<dyn ::std::error::Error>> {
8+
WebviewWindowBuilder::new(
9+
&app,
10+
"main",
11+
tauri::WebviewUrl::App(path.unwrap_or("".into())),
12+
)
13+
.title("Prompt Declaration Language")
14+
.zoom_hotkeys_enabled(true)
15+
.inner_size(1400.0, 1050.0)
16+
.build()?;
917
Ok(())
1018
}

pdl-live-react/src-tauri/src/interpreter/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pub mod extract;
33
pub mod pip;
44
pub mod pull;
55
pub mod requirements;
6+
pub mod run;
67
pub mod shasum;

pdl-live-react/src-tauri/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ pub fn run() {
1313
.setup(|app| {
1414
// Default to GUI if the app was opened with no CLI args.
1515
if args_os().count() <= 1 {
16-
gui::setup(app.handle().clone(), "".to_owned())
16+
gui::new_window(app.handle().clone(), None)
1717
} else {
18-
match cli::setup::cli(app) {
18+
match cli::setup(app) {
1919
Ok(true) => ::std::process::exit(0), // success with CLI
2020
Ok(false) => Ok(()), // instead, open GUI (fallthrough to the logic below)
2121
Err(s) => {

0 commit comments

Comments
 (0)