v2.1 Fixed Chinese input and gtk3 issues for linux packaging

This commit is contained in:
杨红岩 2023-01-05 22:15:35 +08:00
parent d512e42d6a
commit 5f7c0fc9f0
5 changed files with 52 additions and 62 deletions

2
.gitignore vendored
View File

@ -115,4 +115,4 @@ test
1048576000
/exe/app.ico
/resources/manifest.xml
/app_windows_amd64.syso
/app_windows_amd64.syso

View File

@ -57,7 +57,7 @@ type browser struct {
windowSerial int32 //窗口序号
}
// 浏览器全局事件监听
// 浏览器全局事件监听-扩展
//
// 在主浏览器进程调用
type BrowserEvent struct {
@ -70,11 +70,10 @@ type BrowserEvent struct {
onFrameCreated ChromiumEventOnFrameCreated //default
onFrameDetached ChromiumEventOnFrameDetached //default
onMainFrameChanged ChromiumEventOnMainFrameChanged //default
onBeforeDownload ChromiumEventOnBeforeDownload //default
onKeyEvent ChromiumEventOnKeyEvent //default
onBeforeDownload ChromiumEventOnBeforeDownload //default can cover
onKeyEvent ChromiumEventOnKeyEvent //default can cover
onProcessMessageReceived BrowseProcessMessageReceived //default
onTitleChange ChromiumEventOnTitleChange //default
onLoadingStateChange ChromiumEventOnLoadingStateChange //default
onContextMenuCommand ChromiumEventOnContextMenuCommand //default
onBeforeContextMenu ChromiumEventOnBeforeContextMenu //default
onBeforeResourceLoad ChromiumEventOnBeforeResourceLoad //default
@ -104,7 +103,7 @@ func Run(cefApp *TCEFApplication) {
//externalMessagePump 和 multiThreadedMessageLoop 为 false 时启用CEF views framework (ViewsFrameworkBrowserWindow) 窗口
IsMessageLoop = !api.GoBool(cefApp.cfg.externalMessagePump) && !api.GoBool(cefApp.cfg.multiThreadedMessageLoop)
if IsMessageLoop {
BrowserWindow.mainBrowserWindow.appContextInitialized(cefApp)
BrowserWindow.appContextInitialized(cefApp)
}
success := cefApp.StartMainProcess()
if browserProcessStartAfterCallback != nil {
@ -382,7 +381,7 @@ func (m *BrowserEvent) SetOnLoadStart(event ChromiumEventOnLoadStart) {
// BrowserEvent.SetOnLoadingStateChange
func (m *BrowserEvent) SetOnLoadingStateChange(event ChromiumEventOnLoadingStateChange) {
if Args.IsMain() {
m.onLoadingStateChange = event
m.chromium.SetOnLoadingStateChange(event)
}
}

View File

@ -525,30 +525,29 @@ func (m *LCLBrowserWindow) activate(sender lcl.IObject) {
func (m *LCLBrowserWindow) registerPopupEvent() {
var bwEvent = BrowserWindow.browserEvent
m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, beforePopupInfo *BeforePopupInfo, client *ICefClient, noJavascriptAccess *bool) bool {
if !api.GoBool(BrowserWindow.Config.chromiumConfig.enableWindowPopup) {
if !api.GoBool(BrowserWindow.Config.ChromiumConfig().enableWindowPopup) {
return true
}
BrowserWindow.popupWindow.SetWindowType(consts.WT_POPUP_SUB_BROWSER)
BrowserWindow.popupWindow.ChromiumCreate(BrowserWindow.Config.chromiumConfig, beforePopupInfo.TargetUrl)
BrowserWindow.popupWindow.ChromiumCreate(BrowserWindow.Config.ChromiumConfig(), beforePopupInfo.TargetUrl)
BrowserWindow.popupWindow.putChromiumWindowInfo()
BrowserWindow.popupWindow.defaultChromiumEvent()
var result = false
defer func() {
if result {
QueueAsyncCall(func(id int) {
winProperty := BrowserWindow.popupWindow.windowProperty
if winProperty != nil {
if winProperty.IsShowModel {
BrowserWindow.popupWindow.ShowModal()
return
}
}
BrowserWindow.popupWindow.Show()
})
}
}()
if bwEvent.onBeforePopup != nil {
result = !bwEvent.onBeforePopup(sender, browser, frame, beforePopupInfo, BrowserWindow.popupWindow, noJavascriptAccess)
result = bwEvent.onBeforePopup(sender, browser, frame, beforePopupInfo, BrowserWindow.popupWindow, noJavascriptAccess)
}
if !result {
QueueAsyncCall(func(id int) {
winProperty := BrowserWindow.popupWindow.windowProperty
if winProperty != nil {
if winProperty.IsShowModel {
BrowserWindow.popupWindow.ShowModal()
return
}
}
BrowserWindow.popupWindow.Show()
})
result = true
}
return result
})
@ -593,11 +592,6 @@ func (m *LCLBrowserWindow) registerDefaultEvent() {
bwEvent.onContextMenuCommand(sender, browser, frame, params, commandId, eventFlags, result)
}
})
m.chromium.SetOnLoadingStateChange(func(sender lcl.IObject, browser *ICefBrowser, isLoading, canGoBack, canGoForward bool) {
if bwEvent.onLoadingStateChange != nil {
bwEvent.onLoadingStateChange(sender, browser, isLoading, canGoBack, canGoForward)
}
})
m.chromium.SetOnFrameCreated(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) {
QueueAsyncCall(func(id int) {
BrowserWindow.putBrowserFrame(browser, frame)

View File

@ -99,22 +99,22 @@ func (m *ViewsFrameworkBrowserWindow) BrowserViewComponent() *TCEFBrowserViewCom
}
//ViewsFrameworkBrowserWindow 主窗口初始化
func (m *browserWindow) appContextInitialized(app *TCEFApplication) {
func (m *browser) appContextInitialized(app *TCEFApplication) {
if !common.Args.IsMain() {
return
}
app.SetOnContextInitialized(func() {
vFrameBrowserWindow := NewViewsFrameworkBrowserWindow(BrowserWindow.Config.ChromiumConfig(), &BrowserWindow.Config.WindowProperty)
m.chromium = vFrameBrowserWindow.chromium
m.putChromiumWindowInfo()
vFrameBrowserWindow := NewViewsFrameworkBrowserWindow(m.Config.ChromiumConfig(), &m.Config.WindowProperty)
//BrowserWindow.mainBrowserWindow.windowId = BrowserWindow.GetNextWindowNum()
//BrowserWindow.mainBrowserWindow.putChromiumWindowInfo()
vFrameBrowserWindow.registerPopupEvent()
vFrameBrowserWindow.registerDefaultEvent()
vFrameBrowserWindow.windowComponent.SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = true
app.QuitMessageLoop()
})
if BrowserWindow.Config.viewsFrameBrowserWindowOnEventCallback != nil {
BrowserWindow.Config.viewsFrameBrowserWindowOnEventCallback(BrowserWindow.browserEvent, vFrameBrowserWindow)
if m.Config.viewsFrameBrowserWindowOnEventCallback != nil {
m.Config.viewsFrameBrowserWindowOnEventCallback(m.browserEvent, vFrameBrowserWindow)
}
vFrameBrowserWindow.windowComponent.CreateTopLevelWindow()
})
@ -129,10 +129,9 @@ func (m *ViewsFrameworkBrowserWindow) registerPopupEvent() {
fmt.Println("BrowserWindow-TargetUrl:", beforePopupInfo.TargetUrl, "IsMessageLoop:", consts.IsMessageLoop)
var result = false
if bwEvent.onBeforePopup != nil {
result = !bwEvent.onBeforePopup(sender, browser, frame, beforePopupInfo, BrowserWindow.popupWindow, noJavascriptAccess)
result = bwEvent.onBeforePopup(sender, browser, frame, beforePopupInfo, BrowserWindow.popupWindow, noJavascriptAccess)
}
if !result {
result = true
wp := &WindowProperty{
Title: BrowserWindow.Config.WindowProperty.Title,
Url: beforePopupInfo.TargetUrl,
@ -151,10 +150,12 @@ func (m *ViewsFrameworkBrowserWindow) registerPopupEvent() {
Height: BrowserWindow.Config.WindowProperty.Height,
}
vFrameBrowserWindow := NewViewsFrameworkBrowserWindow(BrowserWindow.Config.ChromiumConfig(), wp)
//BrowserWindow.mainBrowserWindow.windowId = BrowserWindow.GetNextWindowNum()
//BrowserWindow.mainBrowserWindow.putChromiumWindowInfo()
vFrameBrowserWindow.registerPopupEvent()
vFrameBrowserWindow.registerDefaultEvent()
vFrameBrowserWindow.windowComponent.CreateTopLevelWindow()
result = true
}
return result
})
@ -178,7 +179,7 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
bwEvent.onBeforeResourceLoad(sender, browser, frame, request, callback, result)
}
})
//事件可以覆盖
//事件可以覆盖
m.chromium.SetOnBeforeDownload(func(sender lcl.IObject, browser *ICefBrowser, beforeDownloadItem *DownloadItem, suggestedName string, callback *ICefBeforeDownloadCallback) {
if bwEvent.onBeforeDownload != nil {
bwEvent.onBeforeDownload(sender, browser, beforeDownloadItem, suggestedName, callback)
@ -198,11 +199,6 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
bwEvent.onContextMenuCommand(sender, browser, frame, params, commandId, eventFlags, result)
}
})
m.chromium.SetOnLoadingStateChange(func(sender lcl.IObject, browser *ICefBrowser, isLoading, canGoBack, canGoForward bool) {
if bwEvent.onLoadingStateChange != nil {
bwEvent.onLoadingStateChange(sender, browser, isLoading, canGoBack, canGoForward)
}
})
m.chromium.SetOnFrameCreated(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) {
QueueAsyncCall(func(id int) {
BrowserWindow.putBrowserFrame(browser, frame)
@ -217,7 +213,6 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
bwEvent.onFrameDetached(sender, browser, frame)
}
})
m.chromium.SetOnAfterCreated(func(sender lcl.IObject, browser *ICefBrowser) {
if chromiumOnAfterCreate(browser) {
return
@ -228,24 +223,25 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
})
//事件可以被覆盖
m.chromium.SetOnKeyEvent(func(sender lcl.IObject, browser *ICefBrowser, event *TCefKeyEvent, result *bool) {
if api.GoBool(BrowserWindow.Config.chromiumConfig.enableDevTools) {
if winInfo := BrowserWindow.GetWindowInfo(browser.Identifier()); winInfo != nil {
if winInfo.WindowType() == consts.WT_DEV_TOOLS || winInfo.WindowType() == consts.WT_VIEW_SOURCE {
return
}
}
if event.WindowsKeyCode == VkF12 && event.Kind == consts.KEYEVENT_RAW_KEYDOWN {
browser.ShowDevTools()
*result = true
} else if event.WindowsKeyCode == VkF12 && event.Kind == consts.KEYEVENT_KEYUP {
*result = true
}
}
if KeyAccelerator.accelerator(browser, event, result) {
return
}
if bwEvent.onKeyEvent != nil {
bwEvent.onKeyEvent(sender, browser, event, result)
} else {
if api.GoBool(BrowserWindow.Config.chromiumConfig.enableDevTools) {
if winInfo := BrowserWindow.GetWindowInfo(browser.Identifier()); winInfo != nil {
if winInfo.WindowType() == consts.WT_DEV_TOOLS || winInfo.WindowType() == consts.WT_VIEW_SOURCE {
return
}
}
if event.WindowsKeyCode == VkF12 && event.Kind == consts.KEYEVENT_RAW_KEYDOWN {
browser.ShowDevTools()
*result = true
} else if event.WindowsKeyCode == VkF12 && event.Kind == consts.KEYEVENT_KEYUP {
*result = true
}
}
if KeyAccelerator.accelerator(browser, event, result) {
return
}
}
})
m.chromium.SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) bool {

View File

@ -187,6 +187,7 @@ func AppBrowserInit() {
fmt.Println("主窗口初始化回调函数")
lcl.Application.Icon().LoadFromFSFile("resources/icon.ico") //设置应用图标
browserWindow.SetCaption("这里设置应用标题")
//browserWindow.EnableTransparent(100) //窗口透明
//设置窗口样式,无标题 ,最大化按钮等
//browserWindow.SetBorderStyle(types.BsSingle)
//browserWindow.SetFormStyle(types.FsNormal)
@ -194,7 +195,7 @@ func AppBrowserInit() {
//设置窗口大小
//browserWindow.SetWidth(1600)
//browserWindow.SetHeight(900)
//限制窗口大小 linux 下不是很友好
//限制窗口大小
//browserWindow.Window.Constraints().SetMinHeight(300)
//browserWindow.Window.Constraints().SetMinWidth(300)
//browserWindow.Window.Constraints().SetMaxWidth(1600)