shell
import "github.com/tangoui/tango/sys/shell"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package shell hands URLs and files to the operating system: open a link in the default browser, a file with its default app, or show a file in Finder / Explorer / the file manager.
OpenURL only accepts URLs whose scheme is allowed (http, https and mailto by default; see AllowSchemes). Pages usually reach these functions through bound methods, and a page must not be able to make the app launch arbitrary protocol handlers or local programs (file:, custom schemes) just by passing a string. Paths are checked to exist.
On iOS OpenURL goes through UIApplication openURL (Safari, Mail, …), OpenPath shows a QuickLook preview (or the "Open in…" menu) and RevealPath is ErrUnsupported, as is OpenPath for folders. On Android OpenURL starts Intent.ACTION_VIEW, OpenPath does the same with a content:// URI of the host's file provider, and RevealPath and folders are ErrUnsupported.
Functions are safe from any goroutine once the app runs. They return ErrUnsupported when the backend has no shell integration and tango.ErrNotRunning after the app quit.
变量
var DefaultSchemes = []string{"http", "https", "mailto"}DefaultSchemes are the schemes OpenURL allows unless changed.
var ErrSchemeNotAllowed = errors.New("tango/shell: URL scheme not allowed")ErrSchemeNotAllowed is returned by OpenURL for URLs whose scheme is not allowed.
var ErrUnsupported = platform.ErrUnsupportedErrUnsupported is platform.ErrUnsupported, re-exported for callers outside the module.
函数
func AllowSchemes
func AllowSchemes(s ...string)AllowSchemes replaces the set of schemes OpenURL accepts, for the whole process. Schemes are case-insensitive, without the colon ("tel", "zoommtg"). With no arguments it restores DefaultSchemes. "file" is never allowed: use OpenPath.
func Allowed
func Allowed(rawURL string) boolAllowed reports whether OpenURL would accept rawURL.
func OpenPath
func OpenPath(a *tango.App, path string) errorOpenPath opens a file with its default application, or a directory in the file manager.
func OpenURL
func OpenURL(a *tango.App, rawURL string) errorOpenURL opens rawURL with the system's handler for its scheme (the default browser for http and https, the mail app for mailto).
func RevealPath
func RevealPath(a *tango.App, path string) errorRevealPath shows path selected in its folder (Finder, Explorer, the file manager). Where the file manager cannot select items, its parent folder is opened.