energy/cef/chromium-config.go

104 lines
2.6 KiB
Go
Raw Normal View History

2022-10-04 13:21:05 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
2022-10-04 13:21:05 +08:00
//
//----------------------------------------
2023-05-31 17:41:14 +08:00
// Chromium 配置
2022-10-04 13:21:05 +08:00
package cef
2023-06-19 12:41:52 +08:00
// TCefChromiumConfig Chromium的基础配置
type TCefChromiumConfig struct {
enableMenu bool //启用右键菜单
enableViewSource bool //启用查看源代码
enableDevTools bool //启用开发者工具
enableWindowPopup bool //启用弹出新窗口
enableOpenUrlTab bool //启用tab签打开新窗口(需自定义实现)
enabledJavascript bool //启用Javascript
2022-10-04 13:21:05 +08:00
}
2023-06-19 12:41:52 +08:00
// NewChromiumConfig 创建默认启用相关功能
func NewChromiumConfig() *TCefChromiumConfig {
return &TCefChromiumConfig{
enableMenu: true,
enableViewSource: true,
enableDevTools: true,
enableWindowPopup: true,
enableOpenUrlTab: false,
enabledJavascript: false,
2022-10-04 13:21:05 +08:00
}
}
2023-02-20 00:20:01 +08:00
// SetEnableMenu 设置启用右键菜单
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) SetEnableMenu(value bool) *TCefChromiumConfig {
m.enableMenu = value
2022-10-04 13:21:05 +08:00
return m
}
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) EnableMenu() bool {
return m.enableMenu
2023-05-31 17:41:14 +08:00
}
// SetEnableViewSource 设置启用查看源文件
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) SetEnableViewSource(value bool) *TCefChromiumConfig {
m.enableViewSource = value
2022-10-04 13:21:05 +08:00
return m
}
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) EnableViewSource() bool {
return m.enableViewSource
2023-05-31 17:41:14 +08:00
}
2023-02-20 00:20:01 +08:00
// SetEnableDevTools 设置启用开发者工具
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) SetEnableDevTools(value bool) *TCefChromiumConfig {
m.enableDevTools = value
2022-10-04 13:21:05 +08:00
return m
}
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) EnableDevTools() bool {
return m.enableDevTools
2023-05-31 17:41:14 +08:00
}
// SetEnableWindowPopup 设置启用弹出新窗口
// 与tab互斥
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) SetEnableWindowPopup(value bool) *TCefChromiumConfig {
m.enableWindowPopup = value
2023-05-31 17:41:14 +08:00
if value {
m.SetEnableOpenUrlTab(false)
}
2022-10-04 13:21:05 +08:00
return m
}
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) EnableWindowPopup() bool {
return m.enableWindowPopup
2023-05-31 17:41:14 +08:00
}
// SetEnableOpenUrlTab 设置启用打开新tab
// 与popup互斥
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) SetEnableOpenUrlTab(value bool) *TCefChromiumConfig {
m.enableOpenUrlTab = value
2023-05-31 17:41:14 +08:00
if value {
m.SetEnableWindowPopup(false)
}
2022-10-04 13:21:05 +08:00
return m
}
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) EnableOpenUrlTab() bool {
return m.enableOpenUrlTab
2023-05-31 17:41:14 +08:00
}
2023-02-20 00:20:01 +08:00
// SetEnabledJavascript 设置启用Javascript
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) SetEnabledJavascript(value bool) *TCefChromiumConfig {
m.enabledJavascript = value
2022-10-04 13:21:05 +08:00
return m
}
2023-05-31 17:41:14 +08:00
2023-06-19 12:41:52 +08:00
func (m *TCefChromiumConfig) EnabledJavascript() bool {
return m.enabledJavascript
2023-05-31 17:41:14 +08:00
}