GoMiniblink

package module
v0.0.0-...-f588240 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 18 Imported by: 0

README

介绍

Miniblink的免费版封装,官网:https://miniblink.net/

  1. 不使用CGO
  2. 面向对象
  3. 跨平台设计,但目前只有一个windows实现
  4. 组件和窗体两种模式
  5. JS互操作
  6. 监控与拦截请求
  7. 透明窗体
  8. 支持本地目录加载模式

Go封装的功能比较少,其实就是 https://gitee.com/aochulai/NetMiniblink 的简化版,因为我出Go封装的目标是VIP,所以免费版就懒得像NetMiniblink一样写得那么完善啦,不过VIP版会向NetMiniblink完整度看齐。

简单的例子
package main

import (
	gm "github.com/reghtml/mblink"
	cs "github.com/reghtml/mblink/forms/controls"
	ws "github.com/reghtml/mblink/forms/windows"
)

func main() {
    //windows版本初始化
    cs.App = new(ws.Provider).Init()
    
    //创建一个窗体并设置基本属性
    frm := new(cs.Form).Init()
    frm.SetTitle("普通窗口")
    frm.SetSize(800, 500)
	
    //创建浏览器控件并设置基本属性
    mb := new(gm.MiniblinkBrowser).Init()
    mb.SetSize(700, 400)
    
    //添加浏览器控件到窗体
    frm.AddChild(mb)
    //注册回调, EvLoad回调在窗体首次显示前触发
    frm.EvLoad["回调名称"] = func(s cs.GUI) {
        //加载网址
        mb.LoadUri("https://www.baidu.com")
    }
    //将frm作为主窗口打开
    cs.Run(frm)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindJsFunc

func BindJsFunc(fn JsFnBinding)

绑定 JavaScript 全局函数

Types

type ConsoleCallback

type ConsoleCallback func(args ConsoleEvArgs)

ConsoleCallback 控制台消息回调函数类型

type ConsoleEvArgs

type ConsoleEvArgs interface {
	Level() string
	Message() string
	SourceName() string
	SourceLine() int
	StackTrace() string
}

type DocumentReadyCallback

type DocumentReadyCallback func(args DocumentReadyEvArgs)

DocumentReadyCallback 文档就绪回调函数类型

type DocumentReadyEvArgs

type DocumentReadyEvArgs interface {
	FrameContext
}

type EventDispatcher

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

EventDispatcher 事件分发器,用于管理和触发事件

func (*EventDispatcher) Add

func (_this *EventDispatcher) Add(name string, fn interface{})

添加事件处理器

func (*EventDispatcher) AddEx

func (_this *EventDispatcher) AddEx(fn interface{}) string

添加事件处理器并返回自动生成的名称

func (*EventDispatcher) Clear

func (_this *EventDispatcher) Clear()

清空所有事件处理器

func (*EventDispatcher) Fire

func (_this *EventDispatcher) Fire(key string, sender interface{}, param ...interface{})

触发事件并调用所有注册的处理器

func (*EventDispatcher) Init

func (_this *EventDispatcher) Init(key string) *EventDispatcher

初始化事件分发器

func (*EventDispatcher) IsEmtpy

func (_this *EventDispatcher) IsEmtpy() bool

检查事件分发器是否为空

func (*EventDispatcher) Remove

func (_this *EventDispatcher) Remove(name string) interface{}

移除指定名称的事件处理器

type FileLoader

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

FileLoader 文件资源加载器实现

func (*FileLoader) ByUri

func (_this *FileLoader) ByUri(uri *url2.URL) []byte

根据 URI 加载文件内容

func (*FileLoader) Domain

func (_this *FileLoader) Domain() string

获取文件加载器的域名

func (*FileLoader) Init

func (_this *FileLoader) Init(dir, domain string) *FileLoader

初始化文件资源加载器

type FrameContext

type FrameContext interface {
	FrameId() uintptr
	IsMain() bool
	Url() string
	IsRemote() bool
	RunJs(script string) interface{}
}

type GoFn

type GoFn func(context GoFnContext) interface{}

type GoFnContext

type GoFnContext struct {
	Miniblink Miniblink
	Name      string
	State     interface{}
	Param     []interface{}
}

GoFnContext Go 函数调用上下文

type JsFnBinding

type JsFnBinding struct {
	Name  string
	Fn    GoFn
	State interface{}
	// contains filtered or unexported fields
}

JsFnBinding JavaScript 函数绑定信息

func (*JsFnBinding) Call

func (_this *JsFnBinding) Call(mb Miniblink, param []interface{}) interface{}

调用绑定的 JavaScript 函数

type JsFunc

type JsFunc func(param ...interface{}) interface{}

type JsReadyCallback

type JsReadyCallback func(args JsReadyEvArgs)

JsReadyCallback JavaScript 就绪回调函数类型

type JsReadyEvArgs

type JsReadyEvArgs interface {
	FrameContext
}

type LoadFailEvArgs

type LoadFailEvArgs interface {
	RequestBefore() RequestBeforeEvArgs
}

type LoadResource

type LoadResource interface {
	Domain() string
	ByUri(uri *url2.URL) []byte
}
type Miniblink interface {
	SetBmpPaintMode(b bool)
	SetProxy(info ProxyInfo)
	MouseIsEnable() bool
	MouseEnable(b bool)
	ToBitmap() *image.RGBA
	CallJsFunc(name string, param []interface{}) interface{}
	JsFunc(name string, fn GoFn, state interface{})
	RunJs(script string) interface{}
	SetOnConsole(callback ConsoleCallback)
	SetOnJsReady(callback JsReadyCallback)
	SetOnRequestBefore(callback RequestBeforeCallback)
	SetOnDocumentReady(callback DocumentReadyCallback)
	SetOnPaintUpdated(callback PaintUpdatedCallback)
	LoadUri(uri string)
	LoadHtmlWithBaseUrl(html, baseUrl string)
	GetHandle() wkeHandle
	ShowDevTools(path string)
	SetLocalStorageFullPath(path string)
	SetUserAgent(userAgent string)
}

Miniblink Miniblink 浏览器接口

type MiniblinkBrowser

type MiniblinkBrowser struct {
	cs.Control

	EvRequestBefore map[string]func(sender *MiniblinkBrowser, e RequestBeforeEvArgs)
	OnRequestBefore func(e RequestBeforeEvArgs)

	EvJsReady map[string]func(sender *MiniblinkBrowser, e JsReadyEvArgs)
	OnJsReady func(e JsReadyEvArgs)

	EvConsole map[string]func(sender *MiniblinkBrowser, e ConsoleEvArgs)
	OnConsole func(e ConsoleEvArgs)

	EvDocumentReady map[string]func(sender *MiniblinkBrowser, e DocumentReadyEvArgs)
	OnDocumentReady func(e DocumentReadyEvArgs)

	EvPaintUpdated map[string]func(sender *MiniblinkBrowser, e PaintUpdatedEvArgs)
	OnPaintUpdated func(e PaintUpdatedEvArgs)

	ResourceLoader []LoadResource
	// contains filtered or unexported fields
}

MiniblinkBrowser 浏览器控件,封装了 Miniblink 核心功能

func (*MiniblinkBrowser) CallJsFunc

func (_this *MiniblinkBrowser) CallJsFunc(name string, param ...interface{}) interface{}

调用 JavaScript 函数并返回结果

func (*MiniblinkBrowser) GetMiniblinkHandle

func (_this *MiniblinkBrowser) GetMiniblinkHandle() uintptr

获取底层的 miniblink 句柄

func (*MiniblinkBrowser) Init

func (_this *MiniblinkBrowser) Init() *MiniblinkBrowser

初始化浏览器控件

func (*MiniblinkBrowser) JsFunc

func (_this *MiniblinkBrowser) JsFunc(name string, fn GoFn, state interface{})

绑定 Go 函数为 JavaScript 全局函数

func (*MiniblinkBrowser) JsFuncEx

func (_this *MiniblinkBrowser) JsFuncEx(name string, fn interface{})

使用反射绑定任意 Go 函数为 JavaScript 全局函数

func (*MiniblinkBrowser) LoadHtmlWithBaseUrl

func (_this *MiniblinkBrowser) LoadHtmlWithBaseUrl(html, baseUrl string)

加载 HTML 内容并指定基础 URL

func (*MiniblinkBrowser) LoadUri

func (_this *MiniblinkBrowser) LoadUri(uri string)

加载指定的 URL

func (*MiniblinkBrowser) MouseEnable

func (_this *MiniblinkBrowser) MouseEnable(b bool)

启用或禁用鼠标事件

func (*MiniblinkBrowser) MouseIsEnable

func (_this *MiniblinkBrowser) MouseIsEnable() bool

检查鼠标事件是否启用

func (*MiniblinkBrowser) SetBmpPaintMode

func (_this *MiniblinkBrowser) SetBmpPaintMode(b bool)

设置是否使用位图绘制模式

func (*MiniblinkBrowser) SetLocalStorageFullPath

func (_this *MiniblinkBrowser) SetLocalStorageFullPath(path string)

设置本地存储的完整路径

func (*MiniblinkBrowser) SetProxy

func (_this *MiniblinkBrowser) SetProxy(info ProxyInfo)

设置代理服务器

func (*MiniblinkBrowser) SetUserAgent

func (_this *MiniblinkBrowser) SetUserAgent(userAgent string)

设置 HTTP 请求的 User-Agent 字符串

func (*MiniblinkBrowser) ShowDevTools

func (_this *MiniblinkBrowser) ShowDevTools(path string)

显示开发者工具

func (*MiniblinkBrowser) ToBitmap

func (_this *MiniblinkBrowser) ToBitmap() *image.RGBA

将 webview 内容转换为位图

type MiniblinkForm

type MiniblinkForm struct {
	cs.Form
	View *MiniblinkBrowser
	// contains filtered or unexported fields
}

MiniblinkForm 包含 Miniblink 浏览器的窗体

func (*MiniblinkForm) Init

func (_this *MiniblinkForm) Init() *MiniblinkForm

初始化窗体(使用默认参数)

func (*MiniblinkForm) InitEx

func (_this *MiniblinkForm) InitEx(param br.FormParam) *MiniblinkForm

使用指定参数初始化窗体

func (*MiniblinkForm) SetSizeAndPosition

func (_this *MiniblinkForm) SetSizeAndPosition(width, height, position int)

SetSizeAndPosition 根据数字小键盘布局设置窗口大小和位置 position: 1-9 对应数字小键盘布局 7 8 9 左上 上中 右上 4 5 6 左中 中间 右中 1 2 3 左下 下中 右下 设置窗体大小和位置

func (*MiniblinkForm) TransparentMode

func (_this *MiniblinkForm) TransparentMode()

启用透明模式

type PaintUpdatedCallback

type PaintUpdatedCallback func(args PaintUpdatedEvArgs)

PaintUpdatedCallback 绘制更新回调函数类型

type PaintUpdatedEvArgs

type PaintUpdatedEvArgs interface {
	Bitmap() *image.RGBA
	Bound() forms.Bound
	Cancel()
	IsCancel() bool
}

type ProxyInfo

type ProxyInfo struct {
	Type     ProxyType
	HostName string
	Port     int
	UserName string
	Password string
}

ProxyInfo 代理服务器配置信息

type ProxyType

type ProxyType int

ProxyType 代理服务器类型

const (
	ProxyType_NONE ProxyType = iota
	ProxyType_HTTP
	ProxyType_SOCKS4
	ProxyType_SOCKS4A
	ProxyType_SOCKS5
	ProxyType_SOCKS5HOSTNAME
)

type RequestBeforeCallback

type RequestBeforeCallback func(args RequestBeforeEvArgs)

RequestBeforeCallback 请求前回调函数类型

type RequestBeforeEvArgs

type RequestBeforeEvArgs interface {
	Url() string
	Method() string
	SetData([]byte)
	Data() []byte
	SetCancel(b bool)
	ResetUrl(url string)
	SetHeader(name, value string)
	/**
	内容最终呈现时触发
	args:intf, ResponseEvArgs
	*/
	EvResponse() *EventDispatcher
	/**
	加载失败时触发
	args:intf, LoadFailEvArgs
	*/
	EvLoadFail() *EventDispatcher
	/**
	请求流程全部完成时触发
	args:intf, RequestBeforeEvArgs
	*/
	EvFinish() *EventDispatcher
}

type ResponseCallback

type ResponseCallback func(args ResponseEvArgs)

ResponseCallback 响应回调函数类型

type ResponseEvArgs

type ResponseEvArgs interface {
	RequestBefore() RequestBeforeEvArgs
	ContentType() string
	SetContentType(contentType string)
	Data() []byte
	SetData(data []byte)
	Headers() map[string]string
}

Directories

Path Synopsis
Res

Jump to

Keyboard shortcuts

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