windows

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package windows 为桌面端提供「多窗口」能力。

设计要点:

  • 前端统一调用 DesktopService.OpenWindow(rawURL),由本包决定「开新窗口 / 复用窗口 / 交给系统浏览器」;
  • 窗口按 **规范化后的绝对 URL** 去重:同一条 URL 再次打开只做 Show + Focus, 不会重复创建(例如反复点同一个应用的 Open);
  • 窗口关闭(WindowClosing)时从表中移除,避免拿到已销毁的窗口句柄;
  • 非本应用同源(外部 http/https)的 URL 交给系统默认浏览器,避免把第三方页面塞进 WebView。

之所以要「规范化」而不是直接用原始字符串:前端可能传相对路径(/c/analysis/apps/123/), 也可能是绝对地址;两者指向同一个页面时必须命中同一个窗口。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 管理桌面端创建的所有原生窗口。

所有导出方法都可被前端(Wails binding)并发调用,内部用互斥锁串行化。

func NewManager

func NewManager(opts Options) *Manager

NewManager 创建窗口管理器。

func (*Manager) Close

func (m *Manager) Close(rawURL string) error

Close 关闭指定 URL 对应的窗口(不存在时忽略)。

func (*Manager) Focus

func (m *Manager) Focus(rawURL string) (bool, error)

Focus 激活指定 URL 对应的窗口(不存在时返回 found=false)。

func (*Manager) List

func (m *Manager) List() []string

List 返回当前打开的应用窗口(规范化 URL)列表,便于前端做调试视图。

func (*Manager) Open

func (m *Manager) Open(rawURL string) (OpenResult, error)

Open 打开 rawURL:本应用页面开原生窗口,外部地址交给系统浏览器。

返回的 error 仅表示「参数非法」或「Wails 创建窗口失败」; 复用已有窗口属于正常路径。

func (*Manager) OpenExternal

func (m *Manager) OpenExternal(rawURL string) error

OpenExternal 强制用系统默认浏览器打开(即使同源)。

type OpenResult

type OpenResult struct {
	// URL 是最终使用的绝对地址。
	URL string `json:"url"`
	// Action 取值:created / focused / external。
	Action string `json:"action"`
	// Name 是窗口名称(external 时为空)。
	Name string `json:"name"`
}

OpenResult 是 Open 的返回值,便于前端判断实际发生了什么(便于调试 / 埋点)。

type Options

type Options struct {
	// App 是 Wails 应用实例,用于创建 WebviewWindow / 打开系统浏览器。
	App *application.App
	// ShellURL 是主窗口加载的地址(pageURL),用于解析相对路径与判定同源。
	ShellURL string
	// TitlePrefix 是新窗口标题前缀,例如 "Brave"。
	TitlePrefix string
	// MarkerJS 是页面加载后注入的脚本,用于让前端识别「运行在桌面壳里」。
	// 必须与主窗口使用同一段脚本(见 main.go 的 desktopMarkerJS)。
	MarkerJS string
	// DefaultWidth / DefaultHeight 是未命中规则时的窗口尺寸。
	DefaultWidth  int
	DefaultHeight int
}

Options 描述窗口管理器依赖的外部参数。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL