Skip to content

openPath opens Explorer twice #3102

@Silbad

Description

@Silbad

Hi,

Windows + Tauri (latest) + Svelte 5

My code :

<script lang="ts">
  import { FolderCog } from "@lucide/svelte";
  import { appDataDir } from "@tauri-apps/api/path";
  import { openPath } from "@tauri-apps/plugin-opener";
  import { Button } from "$lib/components/ui/button/index.js";

  const openUserFolder = async () => {
    const appDataPath = await appDataDir();
    try {
      await openPath(
        `${appDataPath}/myapp${import.meta.env.DEV ? ".dev" : ""}`
      );
    } catch (error) {
      console.error("Error opening user folder:", error);
    }
  };
</script>

<Button
  variant="outline"
  size="icon"
  class="cursor-pointer size-10"
  onclick={openUserFolder}
  title="Open User Folder"
>
  <FolderCog />
</Button>

The behavior is strange. At first, a window opens instantly to “Documents,” then 5 seconds later, the window to the user's folder opens correctly. How can this be fixed? Is it due to Svelte (reactivity)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions