// Copyright 2019-2023 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT /** * Open files and URLs using their default application. * * ## Security * * This API has a scope configuration that forces you to restrict the files and urls to be opened. * * ### Restricting access to the {@link open | `open`} API * * On the configuration object, `open: true` means that the {@link open} API can be used with any URL, * as the argument is validated with the `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+` regex. * You can change that regex by changing the boolean value to a string, e.g. `open: ^https://github.com/`. * * @module */ import { invoke } from '@tauri-apps/api/core' /** * Opens a path or URL with the system's default app, * or the one specified with `openWith`. * * The `openWith` value must be one of `firefox`, `google chrome`, `chromium` `safari`, * `open`, `start`, `xdg-open`, `gio`, `gnome-open`, `kde-open` or `wslview`. * * @example * ```typescript * import { open } from '@tauri-apps/plugin-opener'; * // opens the given URL on the default browser: * await open('https://github.com/tauri-apps/tauri'); * // opens the given URL using `firefox`: * await open('https://github.com/tauri-apps/tauri', 'firefox'); * // opens a file using the default program: * await open('/path/to/file'); * ``` * * @param path The path or URL to open. * This value is matched against the string regex defined on `tauri.conf.json > plugins > opener > open`, * which defaults to `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`. * @param openWith The app to open the file or URL with. * Defaults to the system default application for the specified path type. * * @since 2.0.0 */ export async function open(path: string, openWith?: string): Promise { await invoke('plugin:opener|open', { path, with: openWith }) } export async function revealInDir() { return invoke('plugin:opener|reveal_item_in_dir') }