ARK-Builders / ARK-Builders/Shelf-Desktop
Tauri State being used for filepath constant
- Dominant language
- Rust
- Stars
- 3
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
The outcome of parsing the CLI is sent to tauri and then called back from it in multiple places, even though it doesn't change.
Sent to tauri:
```rust
builder
.manage(cli)
```
Pulled back from tauri:
```rust
async fn read_link(name: String, state: tauri::State<'_, Cli>) -> Result {
let file_path = format!("{}/{name}", &state.path);
let link = Link::load(&state.path, &file_path).expect(&format!("Error loading {file_path}"));
```
Really these could just be the global statics rather than state. There's a lazy static macro in use but `OnceLock` is also in the standard library now, which could initialise the global.
Which instead would look like:
```rust
pub static ARK_SHELF_WORKING_DIR: OnceLock = OnceLock::new();
pub static SCORES_PATH: OnceLock = OnceLock::new();
fn main() {
let cli = Cli::parse();
let base_dir = match cli.path {
Ok(path) => PathBuf::from(path),
// This is using platform defaults but otherwise stick with home_dir() + ark-shelf
None => ProjectDirs::from("dev", "Ark Builders", "Shelf-Desktop")
.map_or(PathBuf::from(""), |proj| PathBuf::from(proj.data_dir()))
};
// Initialise global constants
ARK_SHELF_WORKING_DIR.set(base_dir.clone()).expect("Setting Working Dir");
SCORES_PATH.set(base_dir.join("scores")).expect("Setting Scores Path");
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in the CLI setup around `Cli::parse`, `builder.manage(cli)`, and the `read_link` function shown in the issue; search for other `tauri::State` uses and the existing lazy-static definitions. Review how the working directory and scores path are initialized, then verify that link loading and other callers still receive the same paths after the state usage is removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100