#How do I authorize permission and execute user-selected executables

4 messages · Page 1 of 1 (latest)

timber flare
#

I'm building a tool where there is a function that user can select their own python interpreter, like that of VS Code.

Is there a way to have user authorize the permission to execute a certain executable? Or for my use case, is there a better solution?

valid creek
#

I suggest add some kind of filter in rust to avoid misuse

timber flare
#

I have resorted to this.
Will figure out how to handle multiple envs later

#[tauri::command]
fn grant_python_permission(
    path: &str,
    app_handle: tauri::AppHandle,
) -> std::result::Result<(), tauri::Error> {
    log::info!("Granting python permission for {}", path);
    app_handle.add_capability(
        CapabilityBuilder::new(format!("python-interpreter-{}", path))
            .webview("main")
            .window("main")
            .permission_scoped(
                "shell:allow-execute",
                vec![json!(
                    {
                        "name": "python",
                        "cmd": path,
                        "sidecar": false,
                        "args": [
                            "-c",
                            {
                                "validator": ".+",
                            }
                        ]
                    }
                )],
                vec![],
            ),
    )
}