5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 02:01:01 +08:00

[linux] Hook up runtime Window methods

This commit is contained in:
Lea Anthony 2021-11-29 20:19:18 +11:00
parent 5dbfb447b1
commit 0a8f720586
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
2 changed files with 22 additions and 135 deletions

View File

@ -143,158 +143,73 @@ func (f *Frontend) Run(ctx context.Context) error {
} }
func (f *Frontend) WindowCenter() { func (f *Frontend) WindowCenter() {
////dCenter() f.mainWindow.Center()
} }
func (f *Frontend) WindowSetPos(x, y int) { func (f *Frontend) WindowSetPos(x, y int) {
////dSetPos(x, y) f.mainWindow.SetPos(x, y)
} }
func (f *Frontend) WindowGetPos() (int, int) { func (f *Frontend) WindowGetPos() (int, int) {
////return dPos() return f.mainWindow.Pos()
return 0, 0
} }
func (f *Frontend) WindowSetSize(width, height int) { func (f *Frontend) WindowSetSize(width, height int) {
////dSetSize(width, height) f.mainWindow.SetSize(width, height)
} }
func (f *Frontend) WindowGetSize() (int, int) { func (f *Frontend) WindowGetSize() (int, int) {
////return dSize() return f.mainWindow.Size()
return 0, 0
} }
func (f *Frontend) WindowSetTitle(title string) { func (f *Frontend) WindowSetTitle(title string) {
////dSetText(title) f.mainWindow.SetTitle(title)
} }
func (f *Frontend) WindowFullscreen() { func (f *Frontend) WindowFullscreen() {
////dSetMaxSize(0, 0) f.mainWindow.Fullscreen()
////dSetMinSize(0, 0)
////dFullscreen()
} }
func (f *Frontend) WindowUnFullscreen() { func (f *Frontend) WindowUnFullscreen() {
////dUnFullscreen() f.mainWindow.UnFullscreen()
////dSetMaxSize(f.maxWidth, f.maxHeight)
////dSetMinSize(f.minWidth, f.minHeight)
} }
func (f *Frontend) WindowShow() { func (f *Frontend) WindowShow() {
////dShow() f.mainWindow.Show()
} }
func (f *Frontend) WindowHide() { func (f *Frontend) WindowHide() {
////dHide() f.mainWindow.Hide()
} }
func (f *Frontend) WindowMaximise() { func (f *Frontend) WindowMaximise() {
////dMaximise() f.mainWindow.Maximise()
} }
func (f *Frontend) WindowUnmaximise() { func (f *Frontend) WindowUnmaximise() {
////dUnMaximise() f.mainWindow.UnMaximise()
} }
func (f *Frontend) WindowMinimise() { func (f *Frontend) WindowMinimise() {
//dMinimise() f.mainWindow.Minimise()
} }
func (f *Frontend) WindowUnminimise() { func (f *Frontend) WindowUnminimise() {
//dUnMinimise() f.mainWindow.UnMinimise()
} }
func (f *Frontend) WindowSetMinSize(width int, height int) { func (f *Frontend) WindowSetMinSize(width int, height int) {
//f.minWidth = width f.mainWindow.SetMinSize(width, height)
////f.minHeight = height
//dSetMinSize(width, height)
} }
func (f *Frontend) WindowSetMaxSize(width int, height int) { func (f *Frontend) WindowSetMaxSize(width int, height int) {
//f.maxWidth = width f.mainWindow.SetMaxSize(width, height)
////f.maxHeight = height
//dSetMaxSize(width, height)
} }
func (f *Frontend) WindowSetRGBA(col *options.RGBA) { func (f *Frontend) WindowSetRGBA(col *options.RGBA) {
if col == nil { if col == nil {
return return
} }
//
//f.gtkWindow.Dispatch(func() {
// controller := f.chromium.GetController()
// controller2 := controller.GetICoreWebView2Controller2()
//
// backgroundCol := edge.COREWEBVIEW2_COLOR{
// A: col.A,
// R: col.R,
// G: col.G,
// B: col.B,
// }
//
// // Webview2 only has 0 and 255 as valid values.
// if backgroundCol.A > 0 && backgroundCol.A < 255 {
// backgroundCol.A = 255
// }
//
// if f.frontendOptions.Windows != nil && f.frontendOptions.Windows.WebviewIsTransparent {
// backgroundCol.A = 0
// }
//
// err := controller2.PutDefaultBackgroundColor(backgroundCol)
// if err != nil {
// log.Fatal(err)
// }
//})
} }
func (f *Frontend) Quit() { func (f *Frontend) Quit() {
//winc.Exit() f.mainWindow.Quit()
} }
//func (f *Frontend) setupChromium() {
// chromium := edge.NewChromium()
// f.chromium = chromium
// chromium.MessageCallback = f.processMessage
// chromium.WebResourceRequestedCallback = f.processRequest
// chromium.NavigationCompletedCallback = f.navigationCompleted
// chromium.AcceleratorKeyCallback = func(vkey uint) bool {
// w32.PostMessage(f.gtkWindow.Handle(), w32.WM_KEYDOWN, uintptr(vkey), 0)
// return false
// }
// chromium.Embed(f.gtkWindow.Handle())
// chromium.Resize()
// settings, err := chromium.GetSettings()
// if err != nil {
// log.Fatal(err)
// }
// err = settings.PutAreDefaultContextMenusEnabled(f.debug)
// if err != nil {
// log.Fatal(err)
// }
// err = settings.PutAreDevToolsEnabled(f.debug)
// if err != nil {
// log.Fatal(err)
// }
// err = settings.PutIsZoomControlEnabled(false)
// if err != nil {
// log.Fatal(err)
// }
// err = settings.PutIsStatusBarEnabled(false)
// if err != nil {
// log.Fatal(err)
// }
// err = settings.PutAreBrowserAcceleratorKeysEnabled(false)
// if err != nil {
// log.Fatal(err)
// }
// err = settings.PutIsSwipeNavigationEnabled(false)
// if err != nil {
// log.Fatal(err)
// }
//
// // Set background colour
// f.WindowSetRGBA(f.frontendOptions.RGBA)
//
// chromium.SetGlobalPermission(edge.CoreWebView2PermissionStateAllow)
// chromium.AddWebResourceRequestedFilter("*", edge.COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL)
// chromium.Navigate(f.startURL)
//}
type EventNotify struct { type EventNotify struct {
Name string `json:"name"` Name string `json:"name"`
Data []interface{} `json:"data"` Data []interface{} `json:"data"`
@ -313,39 +228,6 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
f.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`) f.ExecJS(`window.wails.EventsNotify('` + template.JSEscapeString(string(payload)) + `');`)
} }
//func (f *Frontend) processRequest(req *edge.ICoreWebView2WebResourceRequest, args *edge.ICoreWebView2WebResourceRequestedEventArgs) {
// //Get the request
// uri, _ := req.GetUri()
//
// // Translate URI
// uri = strings.TrimPrefix(uri, "file://wails")
// if !strings.HasPrefix(uri, "/") {
// return
// }
//
// // Load file from asset store
// content, mimeType, err := f.assets.Load(uri)
// if err != nil {
// return
// }
//
// env := f.chromium.Environment()
// headers := "Content-Type: " + mimeType
// if f.servingFromDisk {
// headers += "\nPragma: no-cache"
// }
// response, err := env.CreateWebResourceResponse(content, 200, "OK", headers)
// if err != nil {
// return
// }
// // Send response back
// err = args.PutResponse(response)
// if err != nil {
// return
// }
// return
//}
func (f *Frontend) processMessage(message string) { func (f *Frontend) processMessage(message string) {
if message == "drag" { if message == "drag" {
//if !f.mainWindow.IsFullScreen() { //if !f.mainWindow.IsFullScreen() {

View File

@ -396,3 +396,8 @@ func (w *Window) ExecJS(js string) {
func (w *Window) StartDrag() { func (w *Window) StartDrag() {
C.startDrag(w.webview, w.asGTKWindow()) C.startDrag(w.webview, w.asGTKWindow())
} }
func (w *Window) Quit() {
w.Close()
w.Destroy()
}