Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tauri-plugin-fs-pro #404

Merged
merged 1 commit into from
Nov 25, 2024
Merged

add tauri-plugin-fs-pro #404

merged 1 commit into from
Nov 25, 2024

Conversation

ayangweb
Copy link
Contributor

@ayangweb ayangweb commented Nov 23, 2024

This is the link to the project: tauri-plugin-fs-pro

  • I have read the contributing guidelines.
  • Use the following format: [Title](link) - Description.
  • If the project is closed source add the ![closed source] badge after the (link) but before the -.
  • If the project/article is non-free or paywalled add the ![paid] badge after the (link) but before the -.
  • Add entries alphabetically to the most appropriate category.
  • No unnecessary words like for Tauri, a Tauri plugin and Super-Fast.
  • Description does not start with A or An.
  • Description is under 24 words.
  • Description has no links or parenthesis.
  • Use backticks when mentioning package names.
  • Double-check spelling and grammar.
  • No trailing whitespace is added to the end of any file.
  • One suggestion per pull request.
  • I understand that my entry will be removed if it violates the guidelines.
  • I have signed my commits.

Plugins/Integrations

  • Works with Tauri 1.x and onward.
  • The project is open source and accepts contributions.
  • The repo is at least 30 days old.
  • Documentation is in English.
  • The project is active and maintained.

Templates

  • Works with Tauri 1.x and onward.
  • The repo is at least 30 days old.
  • Documentation is in English.
  • The template provides enough information about how to get started and what's included.
  • The template is pretty different from the existing templates.

Apps

  • The app is original and not too simple.
  • The README is in English.
  • The app makes a reasonable effort to be fast, lightweight and secure.
  • If the app closed source, evidence of it being built with Tauri is included.

Additional Context

@FabianLars
Copy link
Member

I'm a bit confused why this plugin exists as-is tbh. fs-extra only existed in v1 because the core fs api was missing things. Your plugin however only supports v2 but all of the listed methods also exist in the official fs plugin (and shell/opener for open).

i really don't want to talk bad about your work here of course, i just think that listed community plugins should have value over the official ones.

@ayangweb
Copy link
Contributor Author

ayangweb commented Nov 24, 2024

  1. The stat method of @tauri-apps/plugin-fs cannot directly retrieve the size of a directory. See: issue comment.
  2. The metadata method provided by tauri-plugin-fs-pro calculates the size of a directory, and in view of the time-consuming issues, additional methods such as isDir are provided separately.
  3. While @tauri-apps/plugin-shell allows paths to be opened in the default application, tauri-plugin-fs-pro adds support for opening paths directly in the file explorer.
  4. Due to time constraints, priority is being given to developing the plugin's v2 version. Support for v1 may be added later if needed.

@FabianLars
Copy link
Member

  1. ah my bad, didn't see the use of fs-extra
  2. 👍
  3. plugin-opener, which pulled out the opening feature out of plugin-shell into a seperate plugin supports that too (will be released soon Publish New Versions (v2) plugins-workspace#2011)
  4. 👍

I think for the dirSize thing we also would have accepted a PR, just as a seperate function instead of adding it to the metadata (so basically your point 2 but the other way around)

I will leave this PR unmerged for a few more days to see if the rest of the team has any opinions

@ayangweb
Copy link
Contributor Author

ayangweb commented Nov 25, 2024

Regarding the release of the opener plugin, it was really helpful to me! Also, I added compress, decompress and transfer methods to fs-pro.

As for the size method, I can try to provide a PR if needed, but since I'm not proficient enough with Rust, I probably can't guarantee that I'll be able to do it.

@FabianLars
Copy link
Member

As for the size method, I can try to provide a PR if needed, but since I'm not proficient enough with Rust, I probably can't guarantee that I'll be able to do it.

no worries :)

Also, I added compress, decompress and transfer methods to fs-pro.

that's reason enough to merge this pr then :D

@FabianLars FabianLars changed the title feat: add tauri-plugin-fs-pro to the plugins add tauri-plugin-fs-pro Nov 25, 2024
@FabianLars FabianLars merged commit cf24d4c into tauri-apps:dev Nov 25, 2024
3 checks passed
@ayangweb
Copy link
Contributor Author

🌹

@ayangweb
Copy link
Contributor Author

ayangweb commented Nov 25, 2024

I've roughly written it down for you to read first!

#[tauri::command]
pub async fn size<R: Runtime>(
    webview: Webview<R>,
    global_scope: GlobalScope<Entry>,
    command_scope: CommandScope<Entry>,
    path: SafeFilePath,
    options: Option<BaseOptions>,
) -> CommandResult<u64> {
    let resolved_path = resolve_path(
        &webview,
        &global_scope,
        &command_scope,
        path,
        options.as_ref().and_then(|o| o.base_dir),
    )?;

    let metadata = resolved_path.metadata()?;

    if metadata.is_file() {
        Ok(metadata.len())
    } else {
        let size = get_dir_size(resolved_path).map_err(|e| {
            format!(
                "failed to get size at path: {} with error: {e}",
                path.display()
            )
        })?;

        Ok(size)
    }
}

fn get_dir_size(path: PathBuf) -> CommandResult<u64> {
    let mut size = 0;

    for entry in std::fs::read_dir(path)? {
        let entry = entry?;
        let metadata = entry.metadata()?;

        if metadata.is_file() {
            size += metadata.len();
        } else if metadata.is_dir() {
            size += get_dir_size(entry.path())?;
        }
    }

    Ok(size)
}

@FabianLars
Copy link
Member

that looks fine at first glance

@ayangweb
Copy link
Contributor Author

I pr a prototype, you help me to optimize it again, thanks!

@ayangweb
Copy link
Contributor Author

tauri-apps/plugins-workspace#2095 thank you for your time.🌹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants